4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * svccfg - modify service configuration repository
31 #include <sys/types.h>
37 #include <libscf_priv.h>
51 #define TEXT_DOMAIN "SUNW_OST_OSCMD"
52 #endif /* TEXT_DOMAIN */
54 #define MAX_CMD_LINE_SZ 2048
56 static const char *myname
;
63 (void) fprintf(stderr
, gettext(
64 "Usage:\tsvccfg [-v] [-s FMRI] [-f file]\n"
65 "\tsvccfg [-v] [-s FMRI] <command> [args]\n"));
70 safe_malloc(size_t sz
)
74 if ((p
= calloc(1, sz
)) == NULL
)
75 uu_die(gettext("Out of memory.\n"));
81 safe_strdup(const char *cp
)
87 uu_die(gettext("Out of memory.\n"));
93 * Send a message to the user. If we're interactive, send it to stdout.
94 * Otherwise send it to stderr.
97 vmessage(const char *fmt
, va_list va
)
99 int interactive
= est
->sc_cmd_flags
& SC_CMD_IACTIVE
;
100 FILE *strm
= interactive
? stdout
: stderr
;
104 if (est
->sc_cmd_file
== NULL
)
105 (void) fprintf(stderr
, "%s: ", myname
);
107 (void) fprintf(stderr
, "%s (%s, line %d): ", myname
,
108 est
->sc_cmd_filename
, est
->sc_cmd_lineno
- 1);
111 if (vfprintf(strm
, fmt
, va
) < 0 && interactive
)
112 uu_die(gettext("printf() error"));
114 ptr
= strchr(fmt
, '\0');
115 if (*(ptr
- 1) != '\n')
116 (void) fprintf(strm
, ": %s.\n", strerror(errno
));
120 * Display a warning. Should usually be predicated by g_verbose.
124 warn(const char *fmt
, ...)
139 if (est
->sc_cmd_flags
& SC_CMD_IACTIVE
) {
144 warn(gettext("Syntax error.\n"));
146 if ((est
->sc_cmd_flags
& SC_CMD_DONT_EXIT
) == 0)
151 * Semantic error. Display the warning and exit if we're not interactive.
155 semerr(const char *fmt
, ...)
163 if ((est
->sc_cmd_flags
& (SC_CMD_IACTIVE
| SC_CMD_DONT_EXIT
)) == 0)
169 initialize(int argc
, char *argv
[])
171 myname
= uu_setpname(argv
[0]);
172 (void) atexit(lscf_cleanup
);
174 (void) setlocale(LC_ALL
, "");
175 (void) textdomain(TEXT_DOMAIN
);
180 lscf_init(); /* must follow engine_init() */
185 main(int argc
, char *argv
[])
187 char *cmd
, *command_file
= NULL
;
191 while ((c
= getopt(argc
, argv
, "vf:s:")) != EOF
)
202 command_file
= optarg
;
210 initialize(argc
, argv
);
215 if (command_file
!= NULL
)
216 return (engine_source(command_file
, 0));
218 if (optind
== argc
) {
219 if (isatty(fileno(stdin
)))
220 return (engine_interp());
222 return (engine_source("-", 0));
226 * Knit together remaining arguments into a single statement.
228 cmd
= safe_malloc(MAX_CMD_LINE_SZ
);
229 for (c
= optind
; c
< argc
; c
++) {
230 (void) strlcat(cmd
, argv
[c
], MAX_CMD_LINE_SZ
);
231 (void) strlcat(cmd
, " ", MAX_CMD_LINE_SZ
);
234 return (engine_exec(cmd
));