fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <assert.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <getopt.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <cmdparse.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libstmf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <pthread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int svcStart(int, char **, cmdOptions_t *, void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int svcStop(int, char **, cmdOptions_t *, void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int online();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MAJOR - This should only change when there is an incompatible change made
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the interfaces or the output.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MINOR - This should change whenever there is a new command or new feature
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with no incompatible change.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define VERSION_STRING_MAJOR "1"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define VERSION_STRING_MINOR "0"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define VERSION_STRING_MAX_LEN 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* 10 ms sleep in nanoseconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TEN_MS_NANOSLEEP 10000000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* tables set up based on cmdparse instructions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* add new options here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteoptionTbl_t longOptions[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {NULL, 0, 0, 0}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add new subcommands here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesubCommandProps_t subcommands[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {"start", svcStart, NULL, NULL, NULL, OPERAND_NONE, NULL},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {"stop", svcStop, NULL, NULL, NULL, OPERAND_NONE, NULL},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* globals */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *cmdName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * svcStop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Offlines the stmf service
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesvcStop(int operandLen, char *operands[], cmdOptions_t *options,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *args)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stmfRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t serviceOffline = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timespec rqtp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&rqtp, sizeof (rqtp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rqtp.tv_nsec = TEN_MS_NANOSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmfRet = stmfOffline()) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfRet) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_PERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("permission denied"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service not found"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_OFFLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service already offline"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to offline service"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for service offline */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!serviceOffline) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfRet = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.operationalState == STMF_SERVICE_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte serviceOffline = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nanosleep(&rqtp, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loadConfig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Loads the stmf config from the SMF repository
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesvcStart(int operandLen, char *operands[], cmdOptions_t *options,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *args)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stmfRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (void) stmfLoadStmfProps();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmfRet = stmfLoadConfig()) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfRet) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_PERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("permission denied"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service not found"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_ONLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service must be offline"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill gettext("Unable to load the configuration. "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "See /var/adm/messages for details"));
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill (void) fprintf(stderr, "%s: %s\n", cmdName,
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill gettext("For information on reverting the "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "stmf:default instance to a previously "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "running configuration see the man page "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "for svccfg(1M)"));
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill (void) fprintf(stderr, "%s: %s\n", cmdName,
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill gettext("After reverting the instance "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "you must clear the service maintenance "
86b7dbefda771542da92c8e031c0153fd809ff01Peter Gill "state. See the man page for svcadm(1M)"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = online();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Onlines the stmf service
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteonline()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stmfRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t serviceOnline = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timespec rqtp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&rqtp, sizeof (rqtp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rqtp.tv_nsec = TEN_MS_NANOSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmfRet = stmfOnline()) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfRet) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_PERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("permission denied"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service not found"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ERROR_SERVICE_ONLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("STMF service already online"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to online service"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for service online */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!serviceOnline) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfRet = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.operationalState == STMF_SERVICE_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte serviceOnline = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nanosleep(&rqtp, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * input:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * execFullName - exec name of program (argv[0])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (changed name to lowerCamelCase to keep consistent with this file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * command name portion of execFullName
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegetExecBasename(char *execFullname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *lastSlash, *execBasename;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* guard against '/' at end of command invocation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lastSlash = strrchr(execFullname, '/');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lastSlash == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte execBasename = execFullname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte execBasename = lastSlash + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*execBasename == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lastSlash = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (execBasename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte synTables_t synTables;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char versionString[VERSION_STRING_MAX_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int funcRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *subcommandArgs = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set global command name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdName = getExecBasename(argv[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte synTables.versionString = versionString;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte synTables.longOptionTbl = &longOptions[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte synTables.subCommandPropsTbl = &subcommands[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (funcRet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* end main */