diff options
| author | tn143363 <none@none> | 2006-08-08 15:01:08 -0700 |
|---|---|---|
| committer | tn143363 <none@none> | 2006-08-08 15:01:08 -0700 |
| commit | f1710550bd8341486e7494e781335ba875c9b12c (patch) | |
| tree | 628eab88bf3c0afcada65e37e75f0ec899638604 /usr/src/cmd/rcap | |
| parent | 18b3347eef26eadfbb51b100a0b56dbd45fd68c7 (diff) | |
| download | illumos-joyent-f1710550bd8341486e7494e781335ba875c9b12c.tar.gz | |
6195745 need an upgrade script for rcapd
6424650 SMF service /system/rcap go to maintance mode after manual restarting coupe times
6447393 rcap service fails to start if /etc/rcap.conf doesn't exist
Diffstat (limited to 'usr/src/cmd/rcap')
| -rw-r--r-- | usr/src/cmd/rcap/common/rcapd_conf.h | 10 | ||||
| -rw-r--r-- | usr/src/cmd/rcap/common/rcapd_conf.l | 95 | ||||
| -rw-r--r-- | usr/src/cmd/rcap/rcapadm/rcapadm.c | 71 | ||||
| -rw-r--r-- | usr/src/cmd/rcap/rcapd/rcap.xml | 17 | ||||
| -rw-r--r-- | usr/src/cmd/rcap/rcapd/rcapd_main.c | 20 |
5 files changed, 127 insertions, 86 deletions
diff --git a/usr/src/cmd/rcap/common/rcapd_conf.h b/usr/src/cmd/rcap/common/rcapd_conf.h index 433eddc07c..3b12d8cab9 100644 --- a/usr/src/cmd/rcap/common/rcapd_conf.h +++ b/usr/src/cmd/rcap/common/rcapd_conf.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,6 +35,8 @@ extern "C" { #endif +#define CFG_TEMPLATE_SUFFIX ".XXXXXX" /* suffix of mkstemp() arg */ + /* * Operating modes */ @@ -86,6 +87,7 @@ typedef enum { extern int rcfg_read(char *, int, rcfg_t *, int(*)(void)); extern void rcfg_init(rcfg_t *); +extern void create_config_file(rcfg_t *); #ifdef __cplusplus } diff --git a/usr/src/cmd/rcap/common/rcapd_conf.l b/usr/src/cmd/rcap/common/rcapd_conf.l index 0d7a86f5e8..e990a58e19 100644 --- a/usr/src/cmd/rcap/common/rcapd_conf.l +++ b/usr/src/cmd/rcap/common/rcapd_conf.l @@ -3,9 +3,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,11 +19,11 @@ * * CDDL HEADER END * - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" +#pragma ident "%Z%%M% %I% %E% SMI" #include <sys/types.h> #include <sys/stat.h> @@ -260,3 +259,89 @@ rcfg_init(rcfg_t *rcfg) rcfg->rcfg_memory_cap_enforcement_pressure = 0; (void) strcpy(rcfg->rcfg_stat_file, STAT_FILE_DEFAULT); } + +/* + * Create the configuration file given the rcfg_t structure. If a rcfg_t + * structure is NULL, create the configuration file with default parameters. + */ +void +create_config_file(rcfg_t *conf) +{ + char *fname = RCAPD_DEFAULT_CONF_FILE; + char *template; + FILE *fp; + mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH; + int fd, olderrno, create_default = 0; + + if (conf == NULL) { + create_default = 1; + if ((conf = malloc(sizeof (*conf))) == NULL) + die(gettext("memory allocation failure")); + + /* Initialize config file with default parameters */ + rcfg_init(conf); + conf->rcfg_mode_name = "project"; + } + + if ((template = malloc(strlen(fname) + + strlen(CFG_TEMPLATE_SUFFIX) + 1)) == NULL) + die(gettext("memory allocation failure")); + + (void) strcpy(template, fname); + (void) strcat(template, CFG_TEMPLATE_SUFFIX); + + if ((fd = mkstemp(template)) < 0) + die(gettext("failed to create a temporary file %s"), + template); + + if ((fp = fdopen(fd, "w")) == NULL) { + olderrno = errno; + (void) close(fd); + if (unlink(template) < 0) + warn(gettext("could not unlink temp file %s"), + template); + errno = olderrno; + die(gettext("Failed to open output file %s"), template); + } + + (void) fputs("#\n# rcap.conf\n#\n" + "# Configuration parameters for resource capping daemon.\n" + "# Do NOT edit by hand -- use rcapadm(1m) instead.\n" + "#\n", fp); + (void) fprintf(fp, "RCAPD_MEMORY_CAP_ENFORCEMENT_PRESSURE " + "= %d\n", conf->rcfg_memory_cap_enforcement_pressure); + (void) fprintf(fp, "RCAPD_RECONFIGURATION_INTERVAL " + "= %d\n", conf->rcfg_reconfiguration_interval); + (void) fprintf(fp, "RCAPD_PROC_WALK_INTERVAL " + "= %d\n", conf->rcfg_proc_walk_interval); + (void) fprintf(fp, "RCAPD_REPORT_INTERVAL " + "= %d\n", conf->rcfg_report_interval); + (void) fprintf(fp, "RCAPD_RSS_SAMPLE_INTERVAL " + "= %d\n", conf->rcfg_rss_sample_interval); + + if (fchmod(fd, mode) != 0) { + olderrno = errno; + (void) fclose(fp); + if (unlink(template) < 0) + warn(gettext("could not unlink temp file %s"), + template); + errno = olderrno; + die(gettext("failed to fchmod %s to %o"), template, mode); + } + + if (rename(template, fname) != 0) { + olderrno = errno; + (void) fclose(fp); + if (unlink(template) < 0) + warn(gettext("could not unlink temp file %s"), + template); + errno = olderrno; + die(gettext("could not rename temporary file to %s"), fname); + } + + (void) fclose(fp); + free(template); + + if (create_default == 1) + free(conf); +} diff --git a/usr/src/cmd/rcap/rcapadm/rcapadm.c b/usr/src/cmd/rcap/rcapadm/rcapadm.c index 6fc90c76e8..cc9fd290a1 100644 --- a/usr/src/cmd/rcap/rcapadm/rcapadm.c +++ b/usr/src/cmd/rcap/rcapadm/rcapadm.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -46,7 +45,6 @@ #include "rcapd_conf.h" #include "rcapd_stat.h" -#define CFG_TEMPLATE_SUFFIX ".XXXXXX" /* suffix of mkstemp() arg */ #define RCAP_FMRI "system/rcap:default" static void @@ -140,10 +138,9 @@ out: int main(int argc, char *argv[]) { - char *subopts, *optval, *template; + char *subopts, *optval; int modified = 0; - FILE *fp; - int fd, olderrno, opt; + int opt; (void) setprogname("rcapadm"); (void) setlocale(LC_ALL, ""); @@ -221,10 +218,6 @@ main(int argc, char *argv[]) } rcfg_init(&conf); conf.rcfg_mode_name = "project"; - conf.rcfg_reconfiguration_interval = 60; - conf.rcfg_proc_walk_interval = 15; - conf.rcfg_report_interval = 5; - conf.rcfg_rss_sample_interval = 5; } else { /* * The configuration file has been read. Warn that any lnode @@ -251,55 +244,11 @@ main(int argc, char *argv[]) if (sample_interval >= 0) conf.rcfg_rss_sample_interval = sample_interval; - if ((template = malloc(strlen(fname) + - strlen(CFG_TEMPLATE_SUFFIX) + 1)) == NULL) - die(gettext("memory allocation failure")); - (void) strcpy(template, fname); - (void) strcpy(template + strlen(template), CFG_TEMPLATE_SUFFIX); - if ((fd = mkstemp(template)) < 0) - die("%s", template); - if ((fp = fdopen(fd, "w")) == NULL) { - olderrno = errno; - (void) close(fd); - (void) unlink(template); - errno = olderrno; - die("%s", template); - return (E_ERROR); - } - (void) fputs("#\n# rcap.conf\n#\n" - "# Configuration parameters for resource capping daemon.\n" - "# Do NOT edit by hand -- use rcapadm(1m) instead.\n" - "#\n", fp); - (void) fprintf(fp, "RCAPD_MEMORY_CAP_ENFORCEMENT_PRESSURE " - "= %d\n", conf.rcfg_memory_cap_enforcement_pressure); - (void) fprintf(fp, "RCAPD_RECONFIGURATION_INTERVAL " - "= %d\n", conf.rcfg_reconfiguration_interval); - (void) fprintf(fp, "RCAPD_PROC_WALK_INTERVAL " - "= %d\n", conf.rcfg_proc_walk_interval); - (void) fprintf(fp, "RCAPD_REPORT_INTERVAL " - "= %d\n", conf.rcfg_report_interval); - (void) fprintf(fp, "RCAPD_RSS_SAMPLE_INTERVAL " - "= %d\n", conf.rcfg_rss_sample_interval); - if (fchmod(fd, 0644) != 0) { - olderrno = errno; - (void) close(fd); - (void) fclose(fp); - (void) unlink(template); - errno = olderrno; - die("%s", template); - } - if (rename(template, fname) != 0) { - olderrno = errno; - (void) close(fd); - (void) fclose(fp); - (void) unlink(template); - errno = olderrno; - die(gettext("cannot rename temporary file to %s"), - fname); - } - (void) fclose(fp); - (void) close(fd); - free(template); + /* + * Create config file with the new parameter(s). The + * create_config_file will exit if it fails. + */ + create_config_file(&conf); if (enable > 0 && smf_enable_instance(RCAP_FMRI, no_starting_stopping > 0 ? SMF_AT_NEXT_BOOT : 0) != 0) diff --git a/usr/src/cmd/rcap/rcapd/rcap.xml b/usr/src/cmd/rcap/rcapd/rcap.xml index 1c1696e007..957643a361 100644 --- a/usr/src/cmd/rcap/rcapd/rcap.xml +++ b/usr/src/cmd/rcap/rcapd/rcap.xml @@ -1,15 +1,14 @@ <?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- - Copyright 2005 Sun Microsystems, Inc. All rights reserved. + Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. CDDL HEADER START The contents of this file are subject to the terms of the - Common Development and Distribution License, Version 1.0 only - (the "License"). You may not use this file except in compliance - with the License. + Common Development and Distribution License (the "License"). + You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. @@ -51,14 +50,6 @@ <service_fmri value='svc:/system/filesystem/minimal' /> </dependency> - <dependency - name='configuration' - type='path' - grouping='require_all' - restart_on='refresh'> - <service_fmri value='file://localhost/etc/rcap.conf' /> - </dependency> - <dependent name='rcap_multi-user' grouping='optional_all' @@ -79,7 +70,7 @@ <exec_method type='method' name='refresh' - exec=':kill -SIGHUP' + exec=':kill -HUP' timeout_seconds='60' /> <exec_method diff --git a/usr/src/cmd/rcap/rcapd/rcapd_main.c b/usr/src/cmd/rcap/rcapd/rcapd_main.c index ce6ac7381c..9c2e8b3c48 100644 --- a/usr/src/cmd/rcap/rcapd/rcapd_main.c +++ b/usr/src/cmd/rcap/rcapd/rcapd_main.c @@ -1096,9 +1096,23 @@ main(int argc, char *argv[]) * Read the configuration file. */ if (rcfg_read(RCAPD_DEFAULT_CONF_FILE, -1, &rcfg, verify_statistics) - != 0) - die(gettext("invalid configuration: %s"), - RCAPD_DEFAULT_CONF_FILE); + != 0) { + /* + * A configuration file may not exist if rcapd is started + * by enabling the smf rcap service, so attempt to create + * a default file. + */ + create_config_file(NULL); + + /* + * A real failure if still can't read the + * configuration file + */ + if (rcfg_read(RCAPD_DEFAULT_CONF_FILE, -1, &rcfg, + verify_statistics) != 0) + die(gettext("resource caps not configured %s"), + RCAPD_DEFAULT_CONF_FILE); + } finish_configuration(); should_reconfigure = 0; |
