xref: /illumos-gate/usr/src/cmd/coreadm/coreadm.c (revision 588340b5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5dfac3eb2SDavid Powell  * Common Development and Distribution License (the "License").
6dfac3eb2SDavid Powell  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22dfac3eb2SDavid Powell  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*588340b5SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <fcntl.h>
297c478bd9Sstevel@tonic-gate #include <ctype.h>
307c478bd9Sstevel@tonic-gate #include <string.h>
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <limits.h>
357c478bd9Sstevel@tonic-gate #include <libintl.h>
367c478bd9Sstevel@tonic-gate #include <locale.h>
377c478bd9Sstevel@tonic-gate #include <sys/stat.h>
387c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
397c478bd9Sstevel@tonic-gate #include <libproc.h>
40dfac3eb2SDavid Powell #include <libscf.h>
41dfac3eb2SDavid Powell #include <libscf_priv.h>
42dfac3eb2SDavid Powell #include <assert.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	E_SUCCESS	0		/* Exit status for success */
457c478bd9Sstevel@tonic-gate #define	E_ERROR		1		/* Exit status for error */
467c478bd9Sstevel@tonic-gate #define	E_USAGE		2		/* Exit status for usage error */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static	const	char	PATH_CONFIG[] = "/etc/coreadm.conf";
49dfac3eb2SDavid Powell static	const	char	PATH_CONFIG_OLD[] = "/etc/coreadm.conf.old";
50dfac3eb2SDavid Powell 
51dfac3eb2SDavid Powell #define	COREADM_INST_NAME	"system/coreadm:default"
52dfac3eb2SDavid Powell #define	COREADM_INST_FMRI	\
53dfac3eb2SDavid Powell     SCF_FMRI_SVC_PREFIX SCF_FMRI_SERVICE_PREFIX COREADM_INST_NAME
54dfac3eb2SDavid Powell 
55dfac3eb2SDavid Powell #define	CONFIG_PARAMS		"config_params"
56dfac3eb2SDavid Powell #define	GLOBAL_ENABLED		"global_enabled"
57dfac3eb2SDavid Powell #define	PROCESS_ENABLED		"process_enabled"
58dfac3eb2SDavid Powell #define	GLOBAL_SETID_ENABLED	"global_setid_enabled"
59dfac3eb2SDavid Powell #define	PROCESS_SETID_ENABLED	"process_setid_enabled"
60dfac3eb2SDavid Powell #define	GLOBAL_LOG_ENABLED	"global_log_enabled"
61dfac3eb2SDavid Powell #define	GLOBAL_PATTERN		"global_pattern"
62dfac3eb2SDavid Powell #define	GLOBAL_CONTENT		"global_content"
63dfac3eb2SDavid Powell #define	INIT_PATTERN		"init_pattern"
64dfac3eb2SDavid Powell #define	INIT_CONTENT		"init_content"
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static	char		*command;
67dfac3eb2SDavid Powell static	uint64_t	options;
68dfac3eb2SDavid Powell static	int		alloptions;
697c478bd9Sstevel@tonic-gate static	char		*glob_pattern;
70dfac3eb2SDavid Powell static	char		gpattern[PATH_MAX];
717c478bd9Sstevel@tonic-gate static	core_content_t	glob_content = CC_CONTENT_INVALID;
727c478bd9Sstevel@tonic-gate static	char		*init_pattern;
73dfac3eb2SDavid Powell static	char		ipattern[PATH_MAX];
747c478bd9Sstevel@tonic-gate static	core_content_t	init_content = CC_CONTENT_INVALID;
757c478bd9Sstevel@tonic-gate static	char		*proc_pattern;
767c478bd9Sstevel@tonic-gate static	size_t		proc_size;
777c478bd9Sstevel@tonic-gate static	core_content_t	proc_content = CC_CONTENT_INVALID;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static	int		report_settings(void);
807c478bd9Sstevel@tonic-gate static	int		do_processes(int, char **);
81dfac3eb2SDavid Powell static	int		do_modify(boolean_t);
827c478bd9Sstevel@tonic-gate static	int		do_update(void);
83dfac3eb2SDavid Powell static	int		do_legacy(void);
84dfac3eb2SDavid Powell 
85dfac3eb2SDavid Powell static scf_propvec_t prop_gpattern = { GLOBAL_PATTERN, NULL, SCF_TYPE_ASTRING };
86dfac3eb2SDavid Powell static scf_propvec_t prop_gcontent = { GLOBAL_CONTENT, NULL, SCF_TYPE_ASTRING };
87dfac3eb2SDavid Powell static scf_propvec_t prop_ipattern = { INIT_PATTERN, NULL, SCF_TYPE_ASTRING };
88dfac3eb2SDavid Powell static scf_propvec_t prop_icontent = { INIT_CONTENT, NULL, SCF_TYPE_ASTRING };
89dfac3eb2SDavid Powell static scf_propvec_t prop_option[] = {
90dfac3eb2SDavid Powell     { GLOBAL_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_PATH },
91dfac3eb2SDavid Powell     { PROCESS_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_PROCESS_PATH },
92dfac3eb2SDavid Powell     { GLOBAL_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_SETID },
93dfac3eb2SDavid Powell     { PROCESS_SETID_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_PROCESS_SETID },
94dfac3eb2SDavid Powell     { GLOBAL_LOG_ENABLED, NULL, SCF_TYPE_BOOLEAN, NULL, CC_GLOBAL_LOG },
95dfac3eb2SDavid Powell     { NULL }
96dfac3eb2SDavid Powell };
97dfac3eb2SDavid Powell #define	MAX_PROPS	(4 + (sizeof (prop_option) / sizeof (scf_propvec_t)))
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate static void
usage(void)1007c478bd9Sstevel@tonic-gate usage(void)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
1037c478bd9Sstevel@tonic-gate "usage:\n"));
1047c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
1057c478bd9Sstevel@tonic-gate "    %s [ -g pattern ] [ -i pattern ] [ -G content ] [ -I content ]\n"),
106dfac3eb2SDavid Powell 	    command);
1077c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
1087c478bd9Sstevel@tonic-gate "            [ -e {global | process | global-setid | proc-setid | log} ]\n"));
1097c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
1107c478bd9Sstevel@tonic-gate "            [ -d {global | process | global-setid | proc-setid | log} ]\n"));
1117c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
1127c478bd9Sstevel@tonic-gate "    %s [ -p pattern ] [ -P content ] [ pid ... ]\n"), command);
1137c478bd9Sstevel@tonic-gate 	exit(E_USAGE);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate static int
perm(void)1177c478bd9Sstevel@tonic-gate perm(void)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("%s: insufficient privileges to "
120dfac3eb2SDavid Powell 	    "exercise the -[GIgied] options\n"), command);
1217c478bd9Sstevel@tonic-gate 	return (E_USAGE);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
124dfac3eb2SDavid Powell static int
parse_content(char * arg,core_content_t * content)125dfac3eb2SDavid Powell parse_content(char *arg, core_content_t *content)
126dfac3eb2SDavid Powell {
127dfac3eb2SDavid Powell 	if (proc_str2content(arg, content) == 0)
128dfac3eb2SDavid Powell 		return (0);
129dfac3eb2SDavid Powell 	(void) fprintf(stderr, gettext("%s: invalid content string '%s'\n"),
130dfac3eb2SDavid Powell 	    command, arg);
131dfac3eb2SDavid Powell 	return (1);
132dfac3eb2SDavid Powell }
133dfac3eb2SDavid Powell 
1347c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)1357c478bd9Sstevel@tonic-gate main(int argc, char **argv)
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate 	int flag;
1387c478bd9Sstevel@tonic-gate 	int opt;
1397c478bd9Sstevel@tonic-gate 	int modify;
1407c478bd9Sstevel@tonic-gate 	int update = 0;
141dfac3eb2SDavid Powell 	int legacy_update = 0;
1427c478bd9Sstevel@tonic-gate 	int error = 0;
1437c478bd9Sstevel@tonic-gate 	int npids;
1447c478bd9Sstevel@tonic-gate 	char **pidlist;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	char curpid[11];
1477c478bd9Sstevel@tonic-gate 	char *curpid_ptr = &curpid[0];
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1507c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	/* command name (e.g., "coreadm") */
1537c478bd9Sstevel@tonic-gate 	if ((command = strrchr(argv[0], '/')) != NULL)
1547c478bd9Sstevel@tonic-gate 		command++;
1557c478bd9Sstevel@tonic-gate 	else
1567c478bd9Sstevel@tonic-gate 		command = argv[0];
1577c478bd9Sstevel@tonic-gate 
158dfac3eb2SDavid Powell 	while ((opt = getopt(argc, argv, "g:G:i:I:p:P:e:d:uU?")) != EOF) {
1597c478bd9Sstevel@tonic-gate 		switch (opt) {
1607c478bd9Sstevel@tonic-gate 		case 'g':
1617c478bd9Sstevel@tonic-gate 			glob_pattern = optarg;
1627c478bd9Sstevel@tonic-gate 			break;
1637c478bd9Sstevel@tonic-gate 		case 'i':
1647c478bd9Sstevel@tonic-gate 			init_pattern = optarg;
1657c478bd9Sstevel@tonic-gate 			break;
1667c478bd9Sstevel@tonic-gate 		case 'p':
1677c478bd9Sstevel@tonic-gate 			proc_pattern = optarg;
1687c478bd9Sstevel@tonic-gate 			proc_size = strlen(proc_pattern) + 1;
1697c478bd9Sstevel@tonic-gate 			break;
1707c478bd9Sstevel@tonic-gate 		case 'G':
171dfac3eb2SDavid Powell 			error |= parse_content(optarg, &glob_content);
1727c478bd9Sstevel@tonic-gate 			break;
1737c478bd9Sstevel@tonic-gate 		case 'I':
174dfac3eb2SDavid Powell 			error |= parse_content(optarg, &init_content);
1757c478bd9Sstevel@tonic-gate 			break;
1767c478bd9Sstevel@tonic-gate 		case 'P':
177dfac3eb2SDavid Powell 			error |= parse_content(optarg, &proc_content);
1787c478bd9Sstevel@tonic-gate 			break;
1797c478bd9Sstevel@tonic-gate 		case 'e':
1807c478bd9Sstevel@tonic-gate 		case 'd':
1817c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "global") == 0)
1827c478bd9Sstevel@tonic-gate 				flag = CC_GLOBAL_PATH;
1837c478bd9Sstevel@tonic-gate 			else if (strcmp(optarg, "process") == 0)
1847c478bd9Sstevel@tonic-gate 				flag = CC_PROCESS_PATH;
1857c478bd9Sstevel@tonic-gate 			else if (strcmp(optarg, "global-setid") == 0)
1867c478bd9Sstevel@tonic-gate 				flag = CC_GLOBAL_SETID;
1877c478bd9Sstevel@tonic-gate 			else if (strcmp(optarg, "proc-setid") == 0)
1887c478bd9Sstevel@tonic-gate 				flag = CC_PROCESS_SETID;
1897c478bd9Sstevel@tonic-gate 			else if (strcmp(optarg, "log") == 0)
1907c478bd9Sstevel@tonic-gate 				flag = CC_GLOBAL_LOG;
1917c478bd9Sstevel@tonic-gate 			else {
1927c478bd9Sstevel@tonic-gate 				flag = 0;
1937c478bd9Sstevel@tonic-gate 				error = 1;
1947c478bd9Sstevel@tonic-gate 			}
195dfac3eb2SDavid Powell 			if (opt == 'e')
196dfac3eb2SDavid Powell 				options |= flag;
197dfac3eb2SDavid Powell 			else
198dfac3eb2SDavid Powell 				options &= ~flag;
199dfac3eb2SDavid Powell 			alloptions |= flag;
2007c478bd9Sstevel@tonic-gate 			break;
201dfac3eb2SDavid Powell 		case 'U':
2027c478bd9Sstevel@tonic-gate 			update = 1;
2037c478bd9Sstevel@tonic-gate 			break;
204dfac3eb2SDavid Powell 		case 'u':
205dfac3eb2SDavid Powell 			legacy_update = 1;
206dfac3eb2SDavid Powell 			break;
2077c478bd9Sstevel@tonic-gate 		case '?':
2087c478bd9Sstevel@tonic-gate 		default:
2097c478bd9Sstevel@tonic-gate 			error = 1;
2107c478bd9Sstevel@tonic-gate 			break;
2117c478bd9Sstevel@tonic-gate 		}
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	npids = argc - optind;
2157c478bd9Sstevel@tonic-gate 	pidlist = argv + optind;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	if (error)
2187c478bd9Sstevel@tonic-gate 		usage();
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * If 'modify' is true, we must modify the system settings
2227c478bd9Sstevel@tonic-gate 	 * and update the configuration file with the new parameters.
2237c478bd9Sstevel@tonic-gate 	 */
2247c478bd9Sstevel@tonic-gate 	modify = glob_pattern != NULL || glob_content != CC_CONTENT_INVALID ||
225dfac3eb2SDavid Powell 	    init_pattern != NULL || init_content != CC_CONTENT_INVALID ||
226dfac3eb2SDavid Powell 	    alloptions != 0;
2277c478bd9Sstevel@tonic-gate 
228dfac3eb2SDavid Powell 	if ((update || legacy_update) && (modify || proc_pattern != NULL ||
2297c478bd9Sstevel@tonic-gate 	    proc_content != CC_CONTENT_INVALID || npids != 0)) {
2307c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
231dfac3eb2SDavid Powell 		    gettext("%s: the -u option must stand alone\n"), command);
2327c478bd9Sstevel@tonic-gate 		usage();
2337c478bd9Sstevel@tonic-gate 	}
2347c478bd9Sstevel@tonic-gate 	if (modify &&
2357c478bd9Sstevel@tonic-gate 	    (proc_pattern != NULL || proc_content != CC_CONTENT_INVALID)) {
236dfac3eb2SDavid Powell 		(void) fprintf(stderr, gettext(
2377c478bd9Sstevel@tonic-gate 		    "%s: -[GIgied] and -[Pp] options are mutually exclusive\n"),
2387c478bd9Sstevel@tonic-gate 		    command);
2397c478bd9Sstevel@tonic-gate 		usage();
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 	if (modify && npids != 0) {
242dfac3eb2SDavid Powell 		(void) fprintf(stderr, gettext(
2437c478bd9Sstevel@tonic-gate 		    "%s: -[GIgied] options cannot have a process-id list\n"),
2447c478bd9Sstevel@tonic-gate 		    command);
2457c478bd9Sstevel@tonic-gate 		usage();
2467c478bd9Sstevel@tonic-gate 	}
2477c478bd9Sstevel@tonic-gate 	if ((proc_pattern != NULL || proc_content != CC_CONTENT_INVALID) &&
2487c478bd9Sstevel@tonic-gate 	    npids == 0) {
2497c478bd9Sstevel@tonic-gate 		(void) sprintf(curpid, "%u", (uint_t)getppid());
2507c478bd9Sstevel@tonic-gate 		npids = 1;
2517c478bd9Sstevel@tonic-gate 		pidlist = &curpid_ptr;
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate 
254dfac3eb2SDavid Powell 	if (legacy_update)
255dfac3eb2SDavid Powell 		return (do_legacy());
2567c478bd9Sstevel@tonic-gate 	if (update)
2577c478bd9Sstevel@tonic-gate 		return (do_update());
2587c478bd9Sstevel@tonic-gate 	if (modify)
259dfac3eb2SDavid Powell 		return (do_modify(B_FALSE));
2607c478bd9Sstevel@tonic-gate 	if (npids != 0)
2617c478bd9Sstevel@tonic-gate 		return (do_processes(npids, pidlist));
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	return (report_settings());
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate static int
report_settings(void)2677c478bd9Sstevel@tonic-gate report_settings(void)
2687c478bd9Sstevel@tonic-gate {
269dfac3eb2SDavid Powell 	char content_str[PRCONTENTBUFSZ];
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	if ((options = core_get_options()) == -1) {
2727c478bd9Sstevel@tonic-gate 		perror("core_get_options()");
2737c478bd9Sstevel@tonic-gate 		return (E_ERROR);
2747c478bd9Sstevel@tonic-gate 	}
275dfac3eb2SDavid Powell 	if (core_get_global_path(gpattern, sizeof (gpattern)) != 0) {
2767c478bd9Sstevel@tonic-gate 		perror("core_get_global_path()");
2777c478bd9Sstevel@tonic-gate 		return (E_ERROR);
2787c478bd9Sstevel@tonic-gate 	}
279dfac3eb2SDavid Powell 	if (core_get_default_path(ipattern, sizeof (ipattern)) != 0) {
2807c478bd9Sstevel@tonic-gate 		perror("core_get_default_path()");
2817c478bd9Sstevel@tonic-gate 		return (E_ERROR);
2827c478bd9Sstevel@tonic-gate 	}
283dfac3eb2SDavid Powell 	if (core_get_global_content(&glob_content) != 0) {
2847c478bd9Sstevel@tonic-gate 		perror("core_get_global_content()");
2857c478bd9Sstevel@tonic-gate 		return (E_ERROR);
2867c478bd9Sstevel@tonic-gate 	}
287dfac3eb2SDavid Powell 	if (core_get_default_content(&init_content) != 0) {
2887c478bd9Sstevel@tonic-gate 		perror("core_get_default_content()");
2897c478bd9Sstevel@tonic-gate 		return (E_ERROR);
2907c478bd9Sstevel@tonic-gate 	}
291dfac3eb2SDavid Powell 
2927c478bd9Sstevel@tonic-gate 	(void) printf(gettext("     global core file pattern: %s\n"),
293dfac3eb2SDavid Powell 	    gpattern);
294dfac3eb2SDavid Powell 	(void) proc_content2str(glob_content, content_str,
295dfac3eb2SDavid Powell 	    sizeof (content_str));
2967c478bd9Sstevel@tonic-gate 	(void) printf(gettext("     global core file content: %s\n"),
2977c478bd9Sstevel@tonic-gate 	    content_str);
2987c478bd9Sstevel@tonic-gate 	(void) printf(gettext("       init core file pattern: %s\n"),
299dfac3eb2SDavid Powell 	    ipattern);
300dfac3eb2SDavid Powell 	(void) proc_content2str(init_content, content_str,
301dfac3eb2SDavid Powell 	    sizeof (content_str));
3027c478bd9Sstevel@tonic-gate 	(void) printf(gettext("       init core file content: %s\n"),
3037c478bd9Sstevel@tonic-gate 	    content_str);
3047c478bd9Sstevel@tonic-gate 	(void) printf(gettext("            global core dumps: %s\n"),
3057c478bd9Sstevel@tonic-gate 	    (options & CC_GLOBAL_PATH)? "enabled" : "disabled");
3067c478bd9Sstevel@tonic-gate 	(void) printf(gettext("       per-process core dumps: %s\n"),
3077c478bd9Sstevel@tonic-gate 	    (options & CC_PROCESS_PATH)? "enabled" : "disabled");
3087c478bd9Sstevel@tonic-gate 	(void) printf(gettext("      global setid core dumps: %s\n"),
3097c478bd9Sstevel@tonic-gate 	    (options & CC_GLOBAL_SETID)? "enabled" : "disabled");
3107c478bd9Sstevel@tonic-gate 	(void) printf(gettext(" per-process setid core dumps: %s\n"),
3117c478bd9Sstevel@tonic-gate 	    (options & CC_PROCESS_SETID)? "enabled" : "disabled");
3127c478bd9Sstevel@tonic-gate 	(void) printf(gettext("     global core dump logging: %s\n"),
3137c478bd9Sstevel@tonic-gate 	    (options & CC_GLOBAL_LOG)? "enabled" : "disabled");
3147c478bd9Sstevel@tonic-gate 	return (E_SUCCESS);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate static int
do_processes(int npids,char ** pidlist)3187c478bd9Sstevel@tonic-gate do_processes(int npids, char **pidlist)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	char process_path[PATH_MAX];
3217c478bd9Sstevel@tonic-gate 	core_content_t content;
3227c478bd9Sstevel@tonic-gate 	pid_t pid;
3237c478bd9Sstevel@tonic-gate 	char *next;
3247c478bd9Sstevel@tonic-gate 	int rc = E_SUCCESS;
325dfac3eb2SDavid Powell 	char content_str[PRCONTENTBUFSZ];
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	if (proc_pattern == NULL && proc_content == CC_CONTENT_INVALID) {
3287c478bd9Sstevel@tonic-gate 		while (npids-- > 0) {
3297c478bd9Sstevel@tonic-gate 			pid = strtol(*pidlist, &next, 10);
3307c478bd9Sstevel@tonic-gate 			if (*next != '\0' || !isdigit(**pidlist)) {
3317c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3327c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid process-id\n"),
3337c478bd9Sstevel@tonic-gate 				    *pidlist);
3347c478bd9Sstevel@tonic-gate 				rc = E_USAGE;
3357c478bd9Sstevel@tonic-gate 			} else if (core_get_process_path(process_path,
3367c478bd9Sstevel@tonic-gate 			    sizeof (process_path), pid) != 0 ||
3377c478bd9Sstevel@tonic-gate 			    core_get_process_content(&content, pid) != 0) {
3387c478bd9Sstevel@tonic-gate 				perror(*pidlist);
3397c478bd9Sstevel@tonic-gate 				rc = E_USAGE;
3407c478bd9Sstevel@tonic-gate 			} else {
3417c478bd9Sstevel@tonic-gate 				(void) proc_content2str(content, content_str,
3427c478bd9Sstevel@tonic-gate 				    sizeof (content_str));
3437c478bd9Sstevel@tonic-gate 				(void) printf(gettext("%s:\t%s\t%s\n"),
3447c478bd9Sstevel@tonic-gate 				    *pidlist, process_path, content_str);
3457c478bd9Sstevel@tonic-gate 			}
3467c478bd9Sstevel@tonic-gate 			pidlist++;
3477c478bd9Sstevel@tonic-gate 		}
3487c478bd9Sstevel@tonic-gate 	} else {
3497c478bd9Sstevel@tonic-gate 		while (npids-- > 0) {
3507c478bd9Sstevel@tonic-gate 			pid = strtol(*pidlist, &next, 10);
3517c478bd9Sstevel@tonic-gate 			if (*next != '\0') {
3527c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3537c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid process-id\n"),
3547c478bd9Sstevel@tonic-gate 				    *pidlist);
3557c478bd9Sstevel@tonic-gate 				rc = E_USAGE;
3567c478bd9Sstevel@tonic-gate 			} else {
3577c478bd9Sstevel@tonic-gate 				if (proc_pattern != NULL &&
3587c478bd9Sstevel@tonic-gate 				    core_set_process_path(proc_pattern,
3597c478bd9Sstevel@tonic-gate 				    proc_size, pid) != 0) {
3607c478bd9Sstevel@tonic-gate 					perror(*pidlist);
3617c478bd9Sstevel@tonic-gate 					rc = E_USAGE;
3627c478bd9Sstevel@tonic-gate 				}
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 				if (proc_content != CC_CONTENT_INVALID &&
3657c478bd9Sstevel@tonic-gate 				    core_set_process_content(
3667c478bd9Sstevel@tonic-gate 				    &proc_content, pid) != 0) {
3677c478bd9Sstevel@tonic-gate 					perror(*pidlist);
3687c478bd9Sstevel@tonic-gate 					rc = E_USAGE;
3697c478bd9Sstevel@tonic-gate 				}
3707c478bd9Sstevel@tonic-gate 			}
3717c478bd9Sstevel@tonic-gate 			pidlist++;
3727c478bd9Sstevel@tonic-gate 		}
3737c478bd9Sstevel@tonic-gate 	}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	return (rc);
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate 
378dfac3eb2SDavid Powell static void
addprop(scf_propvec_t * props,int size,int count,scf_propvec_t * pv,void * ptr)379dfac3eb2SDavid Powell addprop(scf_propvec_t *props, int size, int count, scf_propvec_t *pv, void *ptr)
380dfac3eb2SDavid Powell {
381dfac3eb2SDavid Powell 	assert(count + 1 < size);
382dfac3eb2SDavid Powell 	props[count] = *pv;
383dfac3eb2SDavid Powell 	props[count].pv_ptr = ptr;
384dfac3eb2SDavid Powell }
385dfac3eb2SDavid Powell 
386dfac3eb2SDavid Powell static boolean_t
is_online(const char * fmri)387dfac3eb2SDavid Powell is_online(const char *fmri)
388dfac3eb2SDavid Powell {
389dfac3eb2SDavid Powell 	char *state = smf_get_state(fmri);
390dfac3eb2SDavid Powell 	boolean_t result = state != NULL &&
391dfac3eb2SDavid Powell 	    strcmp(state, SCF_STATE_STRING_ONLINE) == 0;
392dfac3eb2SDavid Powell 
393dfac3eb2SDavid Powell 	free(state);
394dfac3eb2SDavid Powell 	return (result);
395dfac3eb2SDavid Powell }
396dfac3eb2SDavid Powell 
397dfac3eb2SDavid Powell /*
398dfac3eb2SDavid Powell  * The user has specified the -g, -G, -i, -I, -d, or -e options to
399dfac3eb2SDavid Powell  * modify the given configuration parameter. Perform the modification
400dfac3eb2SDavid Powell  * in the smf repository and then perform a smf_refresh_instance which
401dfac3eb2SDavid Powell  * will cause a coreadm -u to occur which will transfer ALL coreadm
402dfac3eb2SDavid Powell  * configuration information from the repository to the kernel.
403dfac3eb2SDavid Powell  */
4047c478bd9Sstevel@tonic-gate static int
do_modify(boolean_t method)405dfac3eb2SDavid Powell do_modify(boolean_t method)
4067c478bd9Sstevel@tonic-gate {
407dfac3eb2SDavid Powell 	char gcontentstr[PRCONTENTBUFSZ];
408dfac3eb2SDavid Powell 	char icontentstr[PRCONTENTBUFSZ];
409dfac3eb2SDavid Powell 	scf_propvec_t *prop;
410dfac3eb2SDavid Powell 	scf_propvec_t properties[MAX_PROPS + 1];
411dfac3eb2SDavid Powell 	int count = 0;
4127c478bd9Sstevel@tonic-gate 
413dfac3eb2SDavid Powell 	if (!method && !is_online(COREADM_INST_FMRI)) {
414dfac3eb2SDavid Powell 		(void) fprintf(stderr,
415dfac3eb2SDavid Powell 		    gettext("%s: coreadm service not online\n"), command);
4167c478bd9Sstevel@tonic-gate 		return (E_ERROR);
4177c478bd9Sstevel@tonic-gate 	}
418dfac3eb2SDavid Powell 
419dfac3eb2SDavid Powell 	if (glob_pattern != NULL)
420dfac3eb2SDavid Powell 		addprop(properties, MAX_PROPS, count++, &prop_gpattern,
421dfac3eb2SDavid Powell 		    glob_pattern);
422dfac3eb2SDavid Powell 
423dfac3eb2SDavid Powell 	if (glob_content != CC_CONTENT_INVALID) {
424dfac3eb2SDavid Powell 		(void) proc_content2str(glob_content, gcontentstr,
425dfac3eb2SDavid Powell 		    sizeof (gcontentstr));
426dfac3eb2SDavid Powell 		addprop(properties, MAX_PROPS, count++, &prop_gcontent,
427dfac3eb2SDavid Powell 		    gcontentstr);
4287c478bd9Sstevel@tonic-gate 	}
429dfac3eb2SDavid Powell 
430dfac3eb2SDavid Powell 	if (init_pattern != NULL)
431dfac3eb2SDavid Powell 		addprop(properties, MAX_PROPS, count++, &prop_ipattern,
432dfac3eb2SDavid Powell 		    init_pattern);
433dfac3eb2SDavid Powell 
434dfac3eb2SDavid Powell 	if (init_content != CC_CONTENT_INVALID) {
435dfac3eb2SDavid Powell 		(void) proc_content2str(init_content, icontentstr,
436dfac3eb2SDavid Powell 		    sizeof (icontentstr));
437dfac3eb2SDavid Powell 		addprop(properties, MAX_PROPS, count++, &prop_icontent,
438dfac3eb2SDavid Powell 		    icontentstr);
4397c478bd9Sstevel@tonic-gate 	}
440dfac3eb2SDavid Powell 
441dfac3eb2SDavid Powell 	for (prop = prop_option; prop->pv_prop != NULL; prop++)
442dfac3eb2SDavid Powell 		if ((alloptions & prop->pv_aux) != 0)
443dfac3eb2SDavid Powell 			addprop(properties, MAX_PROPS, count++, prop, &options);
444dfac3eb2SDavid Powell 
445dfac3eb2SDavid Powell 	properties[count].pv_prop = NULL;
446dfac3eb2SDavid Powell 
447dfac3eb2SDavid Powell 	prop = NULL;
448dfac3eb2SDavid Powell 	if (scf_write_propvec(COREADM_INST_FMRI, CONFIG_PARAMS, properties,
449dfac3eb2SDavid Powell 	    &prop) == SCF_FAILED) {
450dfac3eb2SDavid Powell 		if (prop != NULL) {
451dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
452dfac3eb2SDavid Powell 			    "%s: Unable to write property '%s': %s"), command,
453dfac3eb2SDavid Powell 			    prop->pv_prop, scf_strerror(scf_error()));
454dfac3eb2SDavid Powell 		} else {
455dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
456dfac3eb2SDavid Powell 			    "%s: Unable to write configuration: %s\n"),
457dfac3eb2SDavid Powell 			    command, scf_strerror(scf_error()));
458dfac3eb2SDavid Powell 		}
4597c478bd9Sstevel@tonic-gate 		return (E_ERROR);
4607c478bd9Sstevel@tonic-gate 	}
461dfac3eb2SDavid Powell 
462dfac3eb2SDavid Powell 	if (smf_refresh_instance(COREADM_INST_FMRI) != 0) {
463dfac3eb2SDavid Powell 		(void) fprintf(stderr,
464dfac3eb2SDavid Powell 		    gettext("%s: Unable to refresh %s: %s\n"
465dfac3eb2SDavid Powell 		    "Configuration stored but not made active.\n"),
466dfac3eb2SDavid Powell 		    command, COREADM_INST_FMRI, scf_strerror(scf_error()));
4677c478bd9Sstevel@tonic-gate 		return (E_ERROR);
4687c478bd9Sstevel@tonic-gate 	}
469dfac3eb2SDavid Powell 
470dfac3eb2SDavid Powell 	return (E_SUCCESS);
471dfac3eb2SDavid Powell }
472dfac3eb2SDavid Powell 
473dfac3eb2SDavid Powell static const char *
write_kernel(void)474dfac3eb2SDavid Powell write_kernel(void)
475dfac3eb2SDavid Powell {
476dfac3eb2SDavid Powell 	if (core_set_global_path(glob_pattern, strlen(glob_pattern) + 1) != 0)
477dfac3eb2SDavid Powell 		return ("core_set_global_path()");
478dfac3eb2SDavid Powell 
479dfac3eb2SDavid Powell 	if (core_set_global_content(&glob_content) != 0)
480dfac3eb2SDavid Powell 		return ("core_set_global_content()");
481dfac3eb2SDavid Powell 
482dfac3eb2SDavid Powell 	if (core_set_default_path(init_pattern, strlen(init_pattern) + 1) != 0)
483dfac3eb2SDavid Powell 		return ("core_set_default_path()");
484dfac3eb2SDavid Powell 
485dfac3eb2SDavid Powell 	if (core_set_default_content(&init_content) != 0)
486dfac3eb2SDavid Powell 		return ("core_set_init_content()");
487dfac3eb2SDavid Powell 
488dfac3eb2SDavid Powell 	if (core_set_options((int)options) != 0)
489dfac3eb2SDavid Powell 		return ("core_set_options()");
490dfac3eb2SDavid Powell 
491dfac3eb2SDavid Powell 	return (NULL);
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate /*
4957c478bd9Sstevel@tonic-gate  * BUFSIZE must be large enough to contain the longest path plus some more.
4967c478bd9Sstevel@tonic-gate  */
4977c478bd9Sstevel@tonic-gate #define	BUFSIZE	(PATH_MAX + 80)
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate static int
yes(char * name,char * value,int line)5007c478bd9Sstevel@tonic-gate yes(char *name, char *value, int line)
5017c478bd9Sstevel@tonic-gate {
5027c478bd9Sstevel@tonic-gate 	if (strcmp(value, "yes") == 0)
5037c478bd9Sstevel@tonic-gate 		return (1);
5047c478bd9Sstevel@tonic-gate 	if (strcmp(value, "no") == 0)
5057c478bd9Sstevel@tonic-gate 		return (0);
506dfac3eb2SDavid Powell 	(void) fprintf(stderr, gettext(
507dfac3eb2SDavid Powell 	    "\"%s\", line %d: warning: value must be yes or no: %s=%s\n"),
508dfac3eb2SDavid Powell 	    PATH_CONFIG, line, name, value);
5097c478bd9Sstevel@tonic-gate 	return (0);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate static int
read_legacy(void)513dfac3eb2SDavid Powell read_legacy(void)
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate 	FILE *fp;
5167c478bd9Sstevel@tonic-gate 	int line;
5177c478bd9Sstevel@tonic-gate 	char buf[BUFSIZE];
5187c478bd9Sstevel@tonic-gate 	char name[BUFSIZE], value[BUFSIZE];
519dfac3eb2SDavid Powell 	int n, len;
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	/* defaults */
522dfac3eb2SDavid Powell 	alloptions = CC_OPTIONS;
5237c478bd9Sstevel@tonic-gate 	options = CC_PROCESS_PATH;
5247c478bd9Sstevel@tonic-gate 	gpattern[0] = '\0';
5257c478bd9Sstevel@tonic-gate 	(void) strcpy(ipattern, "core");
526dfac3eb2SDavid Powell 	glob_content = init_content = CC_CONTENT_DEFAULT;
5277c478bd9Sstevel@tonic-gate 
528dfac3eb2SDavid Powell 	glob_pattern = gpattern;
529dfac3eb2SDavid Powell 	init_pattern = ipattern;
530dfac3eb2SDavid Powell 
531dfac3eb2SDavid Powell 	if ((fp = fopen(PATH_CONFIG, "r")) == NULL)
532dfac3eb2SDavid Powell 		return (0);
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	for (line = 1; fgets(buf, sizeof (buf), fp) != NULL; line++) {
5357c478bd9Sstevel@tonic-gate 		/*
5367c478bd9Sstevel@tonic-gate 		 * Skip comment lines and empty lines.
5377c478bd9Sstevel@tonic-gate 		 */
5387c478bd9Sstevel@tonic-gate 		if (buf[0] == '#' || buf[0] == '\n')
5397c478bd9Sstevel@tonic-gate 			continue;
5407c478bd9Sstevel@tonic-gate 		/*
5417c478bd9Sstevel@tonic-gate 		 * Look for "name=value", with optional whitespace on either
5427c478bd9Sstevel@tonic-gate 		 * side, terminated by a newline, and consuming the whole line.
5437c478bd9Sstevel@tonic-gate 		 */
5447c478bd9Sstevel@tonic-gate 		/* LINTED - unbounded string specifier */
5457c478bd9Sstevel@tonic-gate 		n = sscanf(buf, " %[^=]=%s \n%n", name, value, &len);
5467c478bd9Sstevel@tonic-gate 		if (n >= 1 && name[0] != '\0' &&
5477c478bd9Sstevel@tonic-gate 		    (n == 1 || len == strlen(buf))) {
5487c478bd9Sstevel@tonic-gate 			if (n == 1)
5497c478bd9Sstevel@tonic-gate 				value[0] = '\0';
5507c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_GLOB_PATTERN") == 0) {
551*588340b5SJohn Levon 				(void) strlcpy(gpattern, value,
552*588340b5SJohn Levon 				    sizeof (gpattern));
5537c478bd9Sstevel@tonic-gate 				continue;
5547c478bd9Sstevel@tonic-gate 			}
5557c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_GLOB_CONTENT") == 0) {
556dfac3eb2SDavid Powell 				(void) proc_str2content(value, &glob_content);
5577c478bd9Sstevel@tonic-gate 				continue;
5587c478bd9Sstevel@tonic-gate 			}
5597c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_INIT_PATTERN") == 0) {
560*588340b5SJohn Levon 				(void) strlcpy(ipattern, value,
561*588340b5SJohn Levon 				    sizeof (ipattern));
5627c478bd9Sstevel@tonic-gate 				continue;
5637c478bd9Sstevel@tonic-gate 			}
5647c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_INIT_CONTENT") == 0) {
565dfac3eb2SDavid Powell 				(void) proc_str2content(value, &init_content);
5667c478bd9Sstevel@tonic-gate 				continue;
5677c478bd9Sstevel@tonic-gate 			}
5687c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_GLOB_ENABLED") == 0) {
5697c478bd9Sstevel@tonic-gate 				if (yes(name, value, line))
5707c478bd9Sstevel@tonic-gate 					options |= CC_GLOBAL_PATH;
5717c478bd9Sstevel@tonic-gate 				continue;
5727c478bd9Sstevel@tonic-gate 			}
5737c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_PROC_ENABLED") == 0) {
5747c478bd9Sstevel@tonic-gate 				if (yes(name, value, line))
5757c478bd9Sstevel@tonic-gate 					options |= CC_PROCESS_PATH;
5767c478bd9Sstevel@tonic-gate 				else
5777c478bd9Sstevel@tonic-gate 					options &= ~CC_PROCESS_PATH;
5787c478bd9Sstevel@tonic-gate 				continue;
5797c478bd9Sstevel@tonic-gate 			}
5807c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_GLOB_SETID_ENABLED") == 0) {
5817c478bd9Sstevel@tonic-gate 				if (yes(name, value, line))
5827c478bd9Sstevel@tonic-gate 					options |= CC_GLOBAL_SETID;
5837c478bd9Sstevel@tonic-gate 				continue;
5847c478bd9Sstevel@tonic-gate 			}
5857c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_PROC_SETID_ENABLED") == 0) {
5867c478bd9Sstevel@tonic-gate 				if (yes(name, value, line))
5877c478bd9Sstevel@tonic-gate 					options |= CC_PROCESS_SETID;
5887c478bd9Sstevel@tonic-gate 				continue;
5897c478bd9Sstevel@tonic-gate 			}
5907c478bd9Sstevel@tonic-gate 			if (strcmp(name, "COREADM_GLOB_LOG_ENABLED") == 0) {
5917c478bd9Sstevel@tonic-gate 				if (yes(name, value, line))
5927c478bd9Sstevel@tonic-gate 					options |= CC_GLOBAL_LOG;
5937c478bd9Sstevel@tonic-gate 				continue;
5947c478bd9Sstevel@tonic-gate 			}
595dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
596dfac3eb2SDavid Powell 			    "\"%s\", line %d: warning: invalid token: %s\n"),
597dfac3eb2SDavid Powell 			    PATH_CONFIG, line, name);
5987c478bd9Sstevel@tonic-gate 		} else {
5997c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
600dfac3eb2SDavid Powell 			    gettext("\"%s\", line %d: syntax error\n"),
601dfac3eb2SDavid Powell 			    PATH_CONFIG, line);
6027c478bd9Sstevel@tonic-gate 		}
6037c478bd9Sstevel@tonic-gate 	}
6047c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
605dfac3eb2SDavid Powell 
606dfac3eb2SDavid Powell 	return (1);
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate 
609dfac3eb2SDavid Powell /*
610dfac3eb2SDavid Powell  * Loads and applies the coreadm configuration stored in the default
611dfac3eb2SDavid Powell  * coreadm instance.  As this option is (only) used from within an SMF
612dfac3eb2SDavid Powell  * service method, this function must return an SMF_EXIT_* exit status
613dfac3eb2SDavid Powell  * to its caller.
614dfac3eb2SDavid Powell  */
6157c478bd9Sstevel@tonic-gate static int
do_update(void)616dfac3eb2SDavid Powell do_update(void)
6177c478bd9Sstevel@tonic-gate {
618dfac3eb2SDavid Powell 	char		*gcstr, *icstr;
619dfac3eb2SDavid Powell 	scf_propvec_t	properties[MAX_PROPS + 1];
620dfac3eb2SDavid Powell 	scf_propvec_t	*prop;
621dfac3eb2SDavid Powell 	int		count = 0;
622dfac3eb2SDavid Powell 	const char	*errstr;
623dfac3eb2SDavid Powell 
624dfac3eb2SDavid Powell 	if (read_legacy()) {
625dfac3eb2SDavid Powell 		if ((errstr = write_kernel()) != NULL)
626dfac3eb2SDavid Powell 			goto error;
627dfac3eb2SDavid Powell 
628dfac3eb2SDavid Powell 		if (do_modify(B_TRUE) != 0 ||
629dfac3eb2SDavid Powell 		    rename(PATH_CONFIG, PATH_CONFIG_OLD) != 0) {
630dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
631dfac3eb2SDavid Powell 			    "%s: failed to import legacy configuration.\n"),
632dfac3eb2SDavid Powell 			    command);
633dfac3eb2SDavid Powell 			return (SMF_EXIT_ERR_FATAL);
6347c478bd9Sstevel@tonic-gate 		}
635dfac3eb2SDavid Powell 		return (SMF_EXIT_OK);
6367c478bd9Sstevel@tonic-gate 	}
637dfac3eb2SDavid Powell 
638dfac3eb2SDavid Powell 	addprop(properties, MAX_PROPS, count++, &prop_gpattern, &glob_pattern);
639dfac3eb2SDavid Powell 	addprop(properties, MAX_PROPS, count++, &prop_gcontent, &gcstr);
640dfac3eb2SDavid Powell 	addprop(properties, MAX_PROPS, count++, &prop_ipattern, &init_pattern);
641dfac3eb2SDavid Powell 	addprop(properties, MAX_PROPS, count++, &prop_icontent, &icstr);
642dfac3eb2SDavid Powell 	for (prop = prop_option; prop->pv_prop != NULL; prop++)
643dfac3eb2SDavid Powell 		addprop(properties, MAX_PROPS, count++, prop, &options);
644dfac3eb2SDavid Powell 	properties[count].pv_prop = NULL;
645dfac3eb2SDavid Powell 
646dfac3eb2SDavid Powell 	alloptions = CC_OPTIONS;
647dfac3eb2SDavid Powell 	if (scf_read_propvec(COREADM_INST_FMRI, CONFIG_PARAMS, B_TRUE,
648dfac3eb2SDavid Powell 	    properties, &prop) == SCF_FAILED) {
649dfac3eb2SDavid Powell 		if (prop != NULL) {
650dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
651dfac3eb2SDavid Powell 			    "%s: configuration property '%s' not found.\n"),
652dfac3eb2SDavid Powell 			    command, prop->pv_prop);
653dfac3eb2SDavid Powell 		} else {
654dfac3eb2SDavid Powell 			(void) fprintf(stderr, gettext(
655dfac3eb2SDavid Powell 			    "%s: unable to read configuration: %s\n"),
656dfac3eb2SDavid Powell 			    command, scf_strerror(scf_error()));
657dfac3eb2SDavid Powell 		}
658dfac3eb2SDavid Powell 		return (SMF_EXIT_ERR_FATAL);
6597c478bd9Sstevel@tonic-gate 	}
660dfac3eb2SDavid Powell 
661dfac3eb2SDavid Powell 	(void) proc_str2content(gcstr, &glob_content);
662dfac3eb2SDavid Powell 	(void) proc_str2content(icstr, &init_content);
663dfac3eb2SDavid Powell 
664dfac3eb2SDavid Powell 	errstr = write_kernel();
665dfac3eb2SDavid Powell 	scf_clean_propvec(properties);
666dfac3eb2SDavid Powell 	if (errstr == NULL)
667dfac3eb2SDavid Powell 		return (SMF_EXIT_OK);
668dfac3eb2SDavid Powell 
669dfac3eb2SDavid Powell error:
670dfac3eb2SDavid Powell 	if (errno == EPERM) {
671dfac3eb2SDavid Powell 		(void) perm();
672dfac3eb2SDavid Powell 		return (SMF_EXIT_ERR_PERM);
6737c478bd9Sstevel@tonic-gate 	}
674dfac3eb2SDavid Powell 	perror(errstr);
675dfac3eb2SDavid Powell 	return (SMF_EXIT_ERR_FATAL);
676dfac3eb2SDavid Powell }
6777c478bd9Sstevel@tonic-gate 
do_legacy()678dfac3eb2SDavid Powell static int do_legacy()
679dfac3eb2SDavid Powell {
680dfac3eb2SDavid Powell 	const char *errstr;
681dfac3eb2SDavid Powell 
682dfac3eb2SDavid Powell 	if (read_legacy() && (errstr = write_kernel()) != NULL) {
683dfac3eb2SDavid Powell 		if (errno == EPERM)
684dfac3eb2SDavid Powell 			return (perm());
685dfac3eb2SDavid Powell 		perror(errstr);
686dfac3eb2SDavid Powell 		return (E_ERROR);
687dfac3eb2SDavid Powell 	}
6887c478bd9Sstevel@tonic-gate 
689dfac3eb2SDavid Powell 	return (E_SUCCESS);
6907c478bd9Sstevel@tonic-gate }
691