xref: /titanic_53/usr/src/cmd/rcap/rcapadm/rcapadm.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
32*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
33*7c478bd9Sstevel@tonic-gate #include <errno.h>
34*7c478bd9Sstevel@tonic-gate #include <signal.h>
35*7c478bd9Sstevel@tonic-gate #include <stdio.h>
36*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
37*7c478bd9Sstevel@tonic-gate #include <strings.h>
38*7c478bd9Sstevel@tonic-gate #include <unistd.h>
39*7c478bd9Sstevel@tonic-gate #include <libscf.h>
40*7c478bd9Sstevel@tonic-gate #include <libscf_priv.h>
41*7c478bd9Sstevel@tonic-gate #include <libintl.h>
42*7c478bd9Sstevel@tonic-gate #include <locale.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include "utils.h"
45*7c478bd9Sstevel@tonic-gate #include "rcapd.h"
46*7c478bd9Sstevel@tonic-gate #include "rcapd_conf.h"
47*7c478bd9Sstevel@tonic-gate #include "rcapd_stat.h"
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #define	CFG_TEMPLATE_SUFFIX	".XXXXXX"	/* suffix of mkstemp() arg */
50*7c478bd9Sstevel@tonic-gate #define	RCAP_FMRI		"system/rcap:default"
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate static void
53*7c478bd9Sstevel@tonic-gate usage()
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
56*7c478bd9Sstevel@tonic-gate 	    gettext("usage: rcapadm\n"
57*7c478bd9Sstevel@tonic-gate 	    "               [-E|-D]                                "
58*7c478bd9Sstevel@tonic-gate 	    "# enable/disable rcapd\n"
59*7c478bd9Sstevel@tonic-gate 	    "               [-n]                                   "
60*7c478bd9Sstevel@tonic-gate 	    "# don't start/stop rcapd\n"
61*7c478bd9Sstevel@tonic-gate 	    "               [-i <scan|sample|report|config>=value] "
62*7c478bd9Sstevel@tonic-gate 	    "# set intervals\n"
63*7c478bd9Sstevel@tonic-gate 	    "               [-c <percent>]                         "
64*7c478bd9Sstevel@tonic-gate 	    "# set memory cap\n"
65*7c478bd9Sstevel@tonic-gate 	    "                                                      "
66*7c478bd9Sstevel@tonic-gate 	    "# enforcement threshold\n"));
67*7c478bd9Sstevel@tonic-gate 	exit(E_USAGE);
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate static rcfg_t conf;
71*7c478bd9Sstevel@tonic-gate static int enable = -1;
72*7c478bd9Sstevel@tonic-gate static int disable = -1;
73*7c478bd9Sstevel@tonic-gate static int pressure = -1;
74*7c478bd9Sstevel@tonic-gate static int no_starting_stopping = -1;
75*7c478bd9Sstevel@tonic-gate static int scan_interval = -1;
76*7c478bd9Sstevel@tonic-gate static int report_interval = -1;
77*7c478bd9Sstevel@tonic-gate static int config_interval = -1;
78*7c478bd9Sstevel@tonic-gate static int sample_interval = -1;
79*7c478bd9Sstevel@tonic-gate static char *fname = RCAPD_DEFAULT_CONF_FILE;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate static char *subopt_v[] = {
82*7c478bd9Sstevel@tonic-gate 	"scan",
83*7c478bd9Sstevel@tonic-gate 	"sample",
84*7c478bd9Sstevel@tonic-gate 	"report",
85*7c478bd9Sstevel@tonic-gate 	"config",
86*7c478bd9Sstevel@tonic-gate 	NULL
87*7c478bd9Sstevel@tonic-gate };
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate typedef enum {
90*7c478bd9Sstevel@tonic-gate 	OPT_SCAN = 0,
91*7c478bd9Sstevel@tonic-gate 	OPT_SAMPLE,
92*7c478bd9Sstevel@tonic-gate 	OPT_REPORT,
93*7c478bd9Sstevel@tonic-gate 	OPT_CONFIG
94*7c478bd9Sstevel@tonic-gate } subopt_idx_t;
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate static void
97*7c478bd9Sstevel@tonic-gate print_state(void)
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate 	scf_simple_prop_t *persistent_prop = NULL;
100*7c478bd9Sstevel@tonic-gate 	scf_simple_prop_t *temporary_prop = NULL;
101*7c478bd9Sstevel@tonic-gate 	uint8_t *persistent = NULL;
102*7c478bd9Sstevel@tonic-gate 	uint8_t *temporary = NULL;
103*7c478bd9Sstevel@tonic-gate 	scf_handle_t *h;
104*7c478bd9Sstevel@tonic-gate 	/* LINTED: conditionally assigned and used in function */
105*7c478bd9Sstevel@tonic-gate 	ssize_t numvals;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	if ((h = scf_handle_create(SCF_VERSION)) == NULL ||
108*7c478bd9Sstevel@tonic-gate 	    scf_handle_bind(h) != 0)
109*7c478bd9Sstevel@tonic-gate 		goto out;
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	if ((persistent_prop = scf_simple_prop_get(h, RCAP_FMRI,
112*7c478bd9Sstevel@tonic-gate 	    SCF_PG_GENERAL, SCF_PROPERTY_ENABLED)) != NULL && (numvals =
113*7c478bd9Sstevel@tonic-gate 	    scf_simple_prop_numvalues(persistent_prop)) > 0)
114*7c478bd9Sstevel@tonic-gate 		persistent = scf_simple_prop_next_boolean(persistent_prop);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	if ((temporary_prop = scf_simple_prop_get(h, RCAP_FMRI,
117*7c478bd9Sstevel@tonic-gate 	    SCF_PG_GENERAL_OVR, SCF_PROPERTY_ENABLED)) != NULL && (numvals =
118*7c478bd9Sstevel@tonic-gate 	    scf_simple_prop_numvalues(temporary_prop)) > 0)
119*7c478bd9Sstevel@tonic-gate 		temporary = scf_simple_prop_next_boolean(temporary_prop);
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate out:
122*7c478bd9Sstevel@tonic-gate 	if (!persistent)
123*7c478bd9Sstevel@tonic-gate 		(void) printf(gettext("                                      "
124*7c478bd9Sstevel@tonic-gate 		    "state: unknown"));
125*7c478bd9Sstevel@tonic-gate 	else if (temporary && *temporary != *persistent)
126*7c478bd9Sstevel@tonic-gate 		(void) printf(gettext("                                      "
127*7c478bd9Sstevel@tonic-gate 		    "state: %s (%s at next boot)\n"), *temporary ?
128*7c478bd9Sstevel@tonic-gate 		    gettext("enabled") : gettext("disabled"), *persistent ?
129*7c478bd9Sstevel@tonic-gate 		    gettext("enabled") : gettext("disabled"));
130*7c478bd9Sstevel@tonic-gate 	else
131*7c478bd9Sstevel@tonic-gate 		(void) printf(gettext("                                      "
132*7c478bd9Sstevel@tonic-gate 		    "state: %s\n"), *persistent ? gettext("enabled") :
133*7c478bd9Sstevel@tonic-gate 			gettext("disabled"));
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	scf_simple_prop_free(temporary_prop);
136*7c478bd9Sstevel@tonic-gate 	scf_simple_prop_free(persistent_prop);
137*7c478bd9Sstevel@tonic-gate 	scf_handle_destroy(h);
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate int
141*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
142*7c478bd9Sstevel@tonic-gate {
143*7c478bd9Sstevel@tonic-gate 	char *subopts, *optval, *template;
144*7c478bd9Sstevel@tonic-gate 	int modified = 0;
145*7c478bd9Sstevel@tonic-gate 	FILE *fp;
146*7c478bd9Sstevel@tonic-gate 	int fd, olderrno, opt;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	(void) setprogname("rcapadm");
149*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
150*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	while ((opt = getopt(argc, argv, "DEc:i:n")) != EOF) {
153*7c478bd9Sstevel@tonic-gate 		switch (opt) {
154*7c478bd9Sstevel@tonic-gate 		case 'n':
155*7c478bd9Sstevel@tonic-gate 			no_starting_stopping = 1;
156*7c478bd9Sstevel@tonic-gate 			break;
157*7c478bd9Sstevel@tonic-gate 		case 'c':
158*7c478bd9Sstevel@tonic-gate 			if ((pressure = xatoi(optarg)) < 0 ||
159*7c478bd9Sstevel@tonic-gate 			    pressure > 100 ||
160*7c478bd9Sstevel@tonic-gate 			    errno == EINVAL)
161*7c478bd9Sstevel@tonic-gate 				usage();
162*7c478bd9Sstevel@tonic-gate 			modified++;
163*7c478bd9Sstevel@tonic-gate 			break;
164*7c478bd9Sstevel@tonic-gate 		case 'E':
165*7c478bd9Sstevel@tonic-gate 			enable = 1;
166*7c478bd9Sstevel@tonic-gate 			disable = 0;
167*7c478bd9Sstevel@tonic-gate 			modified++;
168*7c478bd9Sstevel@tonic-gate 			break;
169*7c478bd9Sstevel@tonic-gate 		case 'D':
170*7c478bd9Sstevel@tonic-gate 			disable = 1;
171*7c478bd9Sstevel@tonic-gate 			enable = 0;
172*7c478bd9Sstevel@tonic-gate 			modified++;
173*7c478bd9Sstevel@tonic-gate 			break;
174*7c478bd9Sstevel@tonic-gate 		case 'i':
175*7c478bd9Sstevel@tonic-gate 			subopts = optarg;
176*7c478bd9Sstevel@tonic-gate 			while (*subopts != '\0') {
177*7c478bd9Sstevel@tonic-gate 				switch (getsubopt(&subopts, subopt_v,
178*7c478bd9Sstevel@tonic-gate 				    &optval)) {
179*7c478bd9Sstevel@tonic-gate 					case OPT_SCAN:
180*7c478bd9Sstevel@tonic-gate 						if (optval == NULL ||
181*7c478bd9Sstevel@tonic-gate 						    (scan_interval =
182*7c478bd9Sstevel@tonic-gate 						    xatoi(optval)) <= 0)
183*7c478bd9Sstevel@tonic-gate 							usage();
184*7c478bd9Sstevel@tonic-gate 						break;
185*7c478bd9Sstevel@tonic-gate 					case OPT_SAMPLE:
186*7c478bd9Sstevel@tonic-gate 						if (optval == NULL ||
187*7c478bd9Sstevel@tonic-gate 						    (sample_interval =
188*7c478bd9Sstevel@tonic-gate 						    xatoi(optval)) <= 0)
189*7c478bd9Sstevel@tonic-gate 							usage();
190*7c478bd9Sstevel@tonic-gate 						break;
191*7c478bd9Sstevel@tonic-gate 					case OPT_REPORT:
192*7c478bd9Sstevel@tonic-gate 						if (optval == NULL ||
193*7c478bd9Sstevel@tonic-gate 						    (report_interval =
194*7c478bd9Sstevel@tonic-gate 						    xatoi(optval)) < 0)
195*7c478bd9Sstevel@tonic-gate 							usage();
196*7c478bd9Sstevel@tonic-gate 						break;
197*7c478bd9Sstevel@tonic-gate 					case OPT_CONFIG:
198*7c478bd9Sstevel@tonic-gate 						if (optval == NULL ||
199*7c478bd9Sstevel@tonic-gate 						    (config_interval =
200*7c478bd9Sstevel@tonic-gate 						    xatoi(optval)) < 0)
201*7c478bd9Sstevel@tonic-gate 							usage();
202*7c478bd9Sstevel@tonic-gate 						break;
203*7c478bd9Sstevel@tonic-gate 					default:
204*7c478bd9Sstevel@tonic-gate 						usage();
205*7c478bd9Sstevel@tonic-gate 				}
206*7c478bd9Sstevel@tonic-gate 			}
207*7c478bd9Sstevel@tonic-gate 			modified++;
208*7c478bd9Sstevel@tonic-gate 			break;
209*7c478bd9Sstevel@tonic-gate 		default:
210*7c478bd9Sstevel@tonic-gate 			usage();
211*7c478bd9Sstevel@tonic-gate 		}
212*7c478bd9Sstevel@tonic-gate 	}
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	if (argc > optind)
215*7c478bd9Sstevel@tonic-gate 		usage();
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 	if (rcfg_read(fname, -1, &conf, NULL) < 0) {
218*7c478bd9Sstevel@tonic-gate 		if (!(errno == ENOENT && modified)) {
219*7c478bd9Sstevel@tonic-gate 			die(gettext("resource caps not configured\n"));
220*7c478bd9Sstevel@tonic-gate 			return (E_ERROR);
221*7c478bd9Sstevel@tonic-gate 		}
222*7c478bd9Sstevel@tonic-gate 		rcfg_init(&conf);
223*7c478bd9Sstevel@tonic-gate 		conf.rcfg_mode_name = "project";
224*7c478bd9Sstevel@tonic-gate 		conf.rcfg_reconfiguration_interval = 60;
225*7c478bd9Sstevel@tonic-gate 		conf.rcfg_proc_walk_interval = 15;
226*7c478bd9Sstevel@tonic-gate 		conf.rcfg_report_interval = 5;
227*7c478bd9Sstevel@tonic-gate 		conf.rcfg_rss_sample_interval = 5;
228*7c478bd9Sstevel@tonic-gate 	} else {
229*7c478bd9Sstevel@tonic-gate 		/*
230*7c478bd9Sstevel@tonic-gate 		 * The configuration file has been read.  Warn that any lnode
231*7c478bd9Sstevel@tonic-gate 		 * (or non-project) mode specification (by an SRM
232*7c478bd9Sstevel@tonic-gate 		 * 1.3 configuration file, for example) is ignored.
233*7c478bd9Sstevel@tonic-gate 		 */
234*7c478bd9Sstevel@tonic-gate 		if (strcmp(conf.rcfg_mode_name, "project") != 0) {
235*7c478bd9Sstevel@tonic-gate 			warn(gettext("%s mode specification ignored -- using"
236*7c478bd9Sstevel@tonic-gate 			    " project mode\n"), conf.rcfg_mode_name);
237*7c478bd9Sstevel@tonic-gate 			conf.rcfg_mode_name = "project";
238*7c478bd9Sstevel@tonic-gate 			conf.rcfg_mode = rctype_project;
239*7c478bd9Sstevel@tonic-gate 		}
240*7c478bd9Sstevel@tonic-gate 	}
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	if (modified) {
243*7c478bd9Sstevel@tonic-gate 		if (pressure >= 0)
244*7c478bd9Sstevel@tonic-gate 			conf.rcfg_memory_cap_enforcement_pressure = pressure;
245*7c478bd9Sstevel@tonic-gate 		if (config_interval >= 0)
246*7c478bd9Sstevel@tonic-gate 			conf.rcfg_reconfiguration_interval = config_interval;
247*7c478bd9Sstevel@tonic-gate 		if (scan_interval >= 0)
248*7c478bd9Sstevel@tonic-gate 			conf.rcfg_proc_walk_interval = scan_interval;
249*7c478bd9Sstevel@tonic-gate 		if (report_interval >= 0)
250*7c478bd9Sstevel@tonic-gate 			conf.rcfg_report_interval = report_interval;
251*7c478bd9Sstevel@tonic-gate 		if (sample_interval >= 0)
252*7c478bd9Sstevel@tonic-gate 			conf.rcfg_rss_sample_interval = sample_interval;
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 		if ((template = malloc(strlen(fname) +
255*7c478bd9Sstevel@tonic-gate 		    strlen(CFG_TEMPLATE_SUFFIX) + 1)) == NULL)
256*7c478bd9Sstevel@tonic-gate 			die(gettext("memory allocation failure"));
257*7c478bd9Sstevel@tonic-gate 		(void) strcpy(template, fname);
258*7c478bd9Sstevel@tonic-gate 		(void) strcpy(template + strlen(template), CFG_TEMPLATE_SUFFIX);
259*7c478bd9Sstevel@tonic-gate 		if ((fd = mkstemp(template)) < 0)
260*7c478bd9Sstevel@tonic-gate 			die("%s", template);
261*7c478bd9Sstevel@tonic-gate 		if ((fp = fdopen(fd, "w")) == NULL) {
262*7c478bd9Sstevel@tonic-gate 			olderrno = errno;
263*7c478bd9Sstevel@tonic-gate 			(void) close(fd);
264*7c478bd9Sstevel@tonic-gate 			(void) unlink(template);
265*7c478bd9Sstevel@tonic-gate 			errno = olderrno;
266*7c478bd9Sstevel@tonic-gate 			die("%s", template);
267*7c478bd9Sstevel@tonic-gate 			return (E_ERROR);
268*7c478bd9Sstevel@tonic-gate 		}
269*7c478bd9Sstevel@tonic-gate 		(void) fputs("#\n# rcap.conf\n#\n"
270*7c478bd9Sstevel@tonic-gate 		    "# Configuration parameters for resource capping daemon.\n"
271*7c478bd9Sstevel@tonic-gate 		    "# Do NOT edit by hand -- use rcapadm(1m) instead.\n"
272*7c478bd9Sstevel@tonic-gate 		    "#\n", fp);
273*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, "RCAPD_MEMORY_CAP_ENFORCEMENT_PRESSURE  "
274*7c478bd9Sstevel@tonic-gate 		    "= %d\n", conf.rcfg_memory_cap_enforcement_pressure);
275*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, "RCAPD_RECONFIGURATION_INTERVAL         "
276*7c478bd9Sstevel@tonic-gate 		    "= %d\n", conf.rcfg_reconfiguration_interval);
277*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, "RCAPD_PROC_WALK_INTERVAL               "
278*7c478bd9Sstevel@tonic-gate 		    "= %d\n", conf.rcfg_proc_walk_interval);
279*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, "RCAPD_REPORT_INTERVAL                  "
280*7c478bd9Sstevel@tonic-gate 		    "= %d\n", conf.rcfg_report_interval);
281*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, "RCAPD_RSS_SAMPLE_INTERVAL              "
282*7c478bd9Sstevel@tonic-gate 		    "= %d\n", conf.rcfg_rss_sample_interval);
283*7c478bd9Sstevel@tonic-gate 		if (fchmod(fd, 0644) != 0) {
284*7c478bd9Sstevel@tonic-gate 			olderrno = errno;
285*7c478bd9Sstevel@tonic-gate 			(void) close(fd);
286*7c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
287*7c478bd9Sstevel@tonic-gate 			(void) unlink(template);
288*7c478bd9Sstevel@tonic-gate 			errno = olderrno;
289*7c478bd9Sstevel@tonic-gate 			die("%s", template);
290*7c478bd9Sstevel@tonic-gate 		}
291*7c478bd9Sstevel@tonic-gate 		if (rename(template, fname) != 0) {
292*7c478bd9Sstevel@tonic-gate 			olderrno = errno;
293*7c478bd9Sstevel@tonic-gate 			(void) close(fd);
294*7c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
295*7c478bd9Sstevel@tonic-gate 			(void) unlink(template);
296*7c478bd9Sstevel@tonic-gate 			errno = olderrno;
297*7c478bd9Sstevel@tonic-gate 			die(gettext("cannot rename temporary file to %s"),
298*7c478bd9Sstevel@tonic-gate 			    fname);
299*7c478bd9Sstevel@tonic-gate 		}
300*7c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
301*7c478bd9Sstevel@tonic-gate 		(void) close(fd);
302*7c478bd9Sstevel@tonic-gate 		free(template);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 		if (enable > 0 && smf_enable_instance(RCAP_FMRI,
305*7c478bd9Sstevel@tonic-gate 		    no_starting_stopping > 0 ? SMF_AT_NEXT_BOOT : 0) != 0)
306*7c478bd9Sstevel@tonic-gate 			die(gettext("cannot enable service: %s\n"),
307*7c478bd9Sstevel@tonic-gate 			    scf_strerror(scf_error()));
308*7c478bd9Sstevel@tonic-gate 		else if (disable > 0 && smf_disable_instance(RCAP_FMRI,
309*7c478bd9Sstevel@tonic-gate 		    no_starting_stopping > 0 ? SMF_AT_NEXT_BOOT : 0) != 0)
310*7c478bd9Sstevel@tonic-gate 			die(gettext("cannot disable service: %s\n"),
311*7c478bd9Sstevel@tonic-gate 			    scf_strerror(scf_error()));
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 		return (E_SUCCESS);
314*7c478bd9Sstevel@tonic-gate 	}
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 	/*
317*7c478bd9Sstevel@tonic-gate 	 * Display current configuration
318*7c478bd9Sstevel@tonic-gate 	 */
319*7c478bd9Sstevel@tonic-gate 	print_state();
320*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("           memory cap enforcement"
321*7c478bd9Sstevel@tonic-gate 	    " threshold: %d%%\n"), conf.rcfg_memory_cap_enforcement_pressure);
322*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("                    process scan rate"
323*7c478bd9Sstevel@tonic-gate 	    " (sec): %d\n"), conf.rcfg_proc_walk_interval);
324*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("                 reconfiguration rate"
325*7c478bd9Sstevel@tonic-gate 	    " (sec): %d\n"), conf.rcfg_reconfiguration_interval);
326*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("                          report rate"
327*7c478bd9Sstevel@tonic-gate 	    " (sec): %d\n"), conf.rcfg_report_interval);
328*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("                    RSS sampling rate"
329*7c478bd9Sstevel@tonic-gate 	    " (sec): %d\n"), conf.rcfg_rss_sample_interval);
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	return (E_SUCCESS);
332*7c478bd9Sstevel@tonic-gate }
333