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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 #include <sys/types.h>
42 static int svcStart(int, char **, cmdOptions_t
*, void *);
43 static int svcStop(int, char **, cmdOptions_t
*, void *);
47 * MAJOR - This should only change when there is an incompatible change made
48 * to the interfaces or the output.
50 * MINOR - This should change whenever there is a new command or new feature
51 * with no incompatible change.
53 #define VERSION_STRING_MAJOR "1"
54 #define VERSION_STRING_MINOR "0"
55 #define VERSION_STRING_MAX_LEN 10
57 /* 10 ms sleep in nanoseconds */
58 #define TEN_MS_NANOSLEEP 10000000
60 /* tables set up based on cmdparse instructions */
62 /* add new options here */
63 optionTbl_t longOptions
[] = {
68 * Add new subcommands here
70 subCommandProps_t subcommands
[] = {
71 {"start", svcStart
, NULL
, NULL
, NULL
, OPERAND_NONE
, NULL
},
72 {"stop", svcStop
, NULL
, NULL
, NULL
, OPERAND_NONE
, NULL
},
73 {NULL
, 0, NULL
, NULL
, 0, NULL
, 0, NULL
}
82 * Offlines the stmf service
87 svcStop(int operandLen
, char *operands
[], cmdOptions_t
*options
,
93 boolean_t serviceOffline
= B_FALSE
;
96 bzero(&rqtp
, sizeof (rqtp
));
98 rqtp
.tv_nsec
= TEN_MS_NANOSLEEP
;
100 if ((stmfRet
= stmfOffline()) != STMF_STATUS_SUCCESS
) {
102 case STMF_ERROR_PERM
:
103 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
104 gettext("permission denied"));
106 case STMF_ERROR_SERVICE_NOT_FOUND
:
107 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
108 gettext("STMF service not found"));
110 case STMF_ERROR_SERVICE_OFFLINE
:
111 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
112 gettext("STMF service already offline"));
115 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
116 gettext("unable to offline service"));
122 /* wait for service offline */
123 while (!serviceOffline
) {
124 stmfRet
= stmfGetState(&state
);
125 if (stmfRet
!= STMF_STATUS_SUCCESS
) {
129 if (state
.operationalState
== STMF_SERVICE_STATE_OFFLINE
) {
130 serviceOffline
= B_TRUE
;
132 (void) nanosleep(&rqtp
, NULL
);
142 * Loads the stmf config from the SMF repository
147 svcStart(int operandLen
, char *operands
[], cmdOptions_t
*options
,
152 (void) stmfLoadStmfProps();
153 if ((stmfRet
= stmfLoadConfig()) != STMF_STATUS_SUCCESS
) {
155 case STMF_ERROR_PERM
:
156 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
157 gettext("permission denied"));
159 case STMF_ERROR_SERVICE_NOT_FOUND
:
160 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
161 gettext("STMF service not found"));
163 case STMF_ERROR_SERVICE_ONLINE
:
164 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
165 gettext("STMF service must be offline"));
168 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
169 gettext("Unable to load the configuration. "
170 "See /var/adm/messages for details"));
171 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
172 gettext("For information on reverting the "
173 "stmf:default instance to a previously "
174 "running configuration see the man page "
176 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
177 gettext("After reverting the instance "
178 "you must clear the service maintenance "
179 "state. See the man page for svcadm(1M)"));
192 * Onlines the stmf service
202 boolean_t serviceOnline
= B_FALSE
;
203 struct timespec rqtp
;
205 bzero(&rqtp
, sizeof (rqtp
));
207 rqtp
.tv_nsec
= TEN_MS_NANOSLEEP
;
209 if ((stmfRet
= stmfOnline()) != STMF_STATUS_SUCCESS
) {
211 case STMF_ERROR_PERM
:
212 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
213 gettext("permission denied"));
215 case STMF_ERROR_SERVICE_NOT_FOUND
:
216 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
217 gettext("STMF service not found"));
219 case STMF_ERROR_SERVICE_ONLINE
:
220 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
221 gettext("STMF service already online"));
224 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
225 gettext("unable to online service"));
231 /* wait for service online */
232 while (!serviceOnline
) {
233 stmfRet
= stmfGetState(&state
);
234 if (stmfRet
!= STMF_STATUS_SUCCESS
) {
238 if (state
.operationalState
== STMF_SERVICE_STATE_ONLINE
) {
239 serviceOnline
= B_TRUE
;
241 (void) nanosleep(&rqtp
, NULL
);
251 * execFullName - exec name of program (argv[0])
253 * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
254 * (changed name to lowerCamelCase to keep consistent with this file)
257 * command name portion of execFullName
260 getExecBasename(char *execFullname
)
262 char *lastSlash
, *execBasename
;
264 /* guard against '/' at end of command invocation */
266 lastSlash
= strrchr(execFullname
, '/');
267 if (lastSlash
== NULL
) {
268 execBasename
= execFullname
;
271 execBasename
= lastSlash
+ 1;
272 if (*execBasename
== '\0') {
279 return (execBasename
);
283 main(int argc
, char *argv
[])
285 synTables_t synTables
;
286 char versionString
[VERSION_STRING_MAX_LEN
];
289 void *subcommandArgs
= NULL
;
291 (void) setlocale(LC_ALL
, "");
292 /* set global command name */
293 cmdName
= getExecBasename(argv
[0]);
295 (void) snprintf(versionString
, VERSION_STRING_MAX_LEN
, "%s.%s",
296 VERSION_STRING_MAJOR
, VERSION_STRING_MINOR
);
297 synTables
.versionString
= versionString
;
298 synTables
.longOptionTbl
= &longOptions
[0];
299 synTables
.subCommandPropsTbl
= &subcommands
[0];
301 ret
= cmdParse(argc
, argv
, synTables
, subcommandArgs
, &funcRet
);