1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * svcadm - request adminstrative actions for service instances 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <locale.h> 34*0Sstevel@tonic-gate #include <libintl.h> 35*0Sstevel@tonic-gate #include <libscf.h> 36*0Sstevel@tonic-gate #include <libscf_priv.h> 37*0Sstevel@tonic-gate #include <libuutil.h> 38*0Sstevel@tonic-gate #include <stddef.h> 39*0Sstevel@tonic-gate #include <stdio.h> 40*0Sstevel@tonic-gate #include <stdlib.h> 41*0Sstevel@tonic-gate #include <string.h> 42*0Sstevel@tonic-gate #include <unistd.h> 43*0Sstevel@tonic-gate #include <assert.h> 44*0Sstevel@tonic-gate #include <errno.h> 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate #ifndef TEXT_DOMAIN 47*0Sstevel@tonic-gate #define TEXT_DOMAIN "SUNW_OST_OSCMD" 48*0Sstevel@tonic-gate #endif /* TEXT_DOMAIN */ 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* Must be a power of two */ 51*0Sstevel@tonic-gate #define HT_BUCKETS 64 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate /* 54*0Sstevel@tonic-gate * Exit codes for enable and disable -s. 55*0Sstevel@tonic-gate */ 56*0Sstevel@tonic-gate #define EXIT_SVC_FAILURE 3 57*0Sstevel@tonic-gate #define EXIT_DEP_FAILURE 4 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate /* 60*0Sstevel@tonic-gate * How long we will wait (in seconds) for a service to change state 61*0Sstevel@tonic-gate * before re-checking its dependencies. 62*0Sstevel@tonic-gate */ 63*0Sstevel@tonic-gate #define WAIT_INTERVAL 3 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #ifndef NDEBUG 66*0Sstevel@tonic-gate #define bad_error(func, err) { \ 67*0Sstevel@tonic-gate uu_warn("%s:%d: %s() failed with unexpected error %d.\n", \ 68*0Sstevel@tonic-gate __FILE__, __LINE__, (func), (err)); \ 69*0Sstevel@tonic-gate abort(); \ 70*0Sstevel@tonic-gate } 71*0Sstevel@tonic-gate #else 72*0Sstevel@tonic-gate #define bad_error(func, err) abort() 73*0Sstevel@tonic-gate #endif 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate struct ht_elt { 77*0Sstevel@tonic-gate struct ht_elt *next; 78*0Sstevel@tonic-gate boolean_t active; 79*0Sstevel@tonic-gate char str[1]; 80*0Sstevel@tonic-gate }; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate scf_handle_t *h; 84*0Sstevel@tonic-gate ssize_t max_scf_fmri_sz; 85*0Sstevel@tonic-gate static const char *emsg_permission_denied; 86*0Sstevel@tonic-gate static const char *emsg_nomem; 87*0Sstevel@tonic-gate static const char *emsg_create_pg_perm_denied; 88*0Sstevel@tonic-gate static const char *emsg_pg_perm_denied; 89*0Sstevel@tonic-gate static const char *emsg_prop_perm_denied; 90*0Sstevel@tonic-gate static const char *emsg_no_service; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate static int exit_status = 0; 93*0Sstevel@tonic-gate static int verbose = 0; 94*0Sstevel@tonic-gate static char *scratch_fmri; 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate static struct ht_elt **visited; 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate /* 99*0Sstevel@tonic-gate * Visitors from synch.c, needed for enable -s and disable -s. 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate extern int is_enabled(scf_instance_t *); 102*0Sstevel@tonic-gate extern int has_potential(scf_instance_t *, int); 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate void 105*0Sstevel@tonic-gate do_scfdie(int lineno) 106*0Sstevel@tonic-gate { 107*0Sstevel@tonic-gate scf_error_t err; 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate switch (err = scf_error()) { 110*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 111*0Sstevel@tonic-gate uu_die(gettext("Connection to repository server broken. " 112*0Sstevel@tonic-gate "Exiting.\n")); 113*0Sstevel@tonic-gate /* NOTREACHED */ 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 116*0Sstevel@tonic-gate uu_die(gettext("Repository is read-only. Exiting.\n")); 117*0Sstevel@tonic-gate /* NOTREACHED */ 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate default: 120*0Sstevel@tonic-gate #ifdef NDEBUG 121*0Sstevel@tonic-gate uu_die(gettext("Unexpected libscf error: %s. Exiting.\n"), 122*0Sstevel@tonic-gate scf_strerror(err)); 123*0Sstevel@tonic-gate #else 124*0Sstevel@tonic-gate uu_die("Unexpected libscf error on line %d: %s.\n", lineno, 125*0Sstevel@tonic-gate scf_strerror(err)); 126*0Sstevel@tonic-gate #endif 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate } 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate #define scfdie() do_scfdie(__LINE__) 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate static void 133*0Sstevel@tonic-gate usage() 134*0Sstevel@tonic-gate { 135*0Sstevel@tonic-gate (void) fprintf(stderr, gettext( 136*0Sstevel@tonic-gate "Usage: %1$s [-v] [cmd [args ... ]]\n\n" 137*0Sstevel@tonic-gate "\t%1$s enable [-rst] <service> ...\t- enable and online service(s)\n" 138*0Sstevel@tonic-gate "\t%1$s disable [-st] <service> ...\t- disable and offline service(s)\n" 139*0Sstevel@tonic-gate "\t%1$s restart <service> ...\t\t- restart specified service(s)\n" 140*0Sstevel@tonic-gate "\t%1$s refresh <service> ...\t\t- re-read service configuration\n" 141*0Sstevel@tonic-gate "\t%1$s mark [-It] <state> <service> ...\t- set maintenance state\n" 142*0Sstevel@tonic-gate "\t%1$s clear <service> ...\t\t- clear maintenance state\n" 143*0Sstevel@tonic-gate "\t%1$s milestone [-d] <milestone>\t- advance to a service milestone\n" 144*0Sstevel@tonic-gate "\n\t" 145*0Sstevel@tonic-gate "Services can be specified using an FMRI, abbreviation, or fnmatch(5)\n" 146*0Sstevel@tonic-gate "\tpattern, as shown in these examples for svc:/network/smtp:sendmail\n" 147*0Sstevel@tonic-gate "\n" 148*0Sstevel@tonic-gate "\t%1$s <cmd> svc:/network/smtp:sendmail\n" 149*0Sstevel@tonic-gate "\t%1$s <cmd> network/smtp:sendmail\n" 150*0Sstevel@tonic-gate "\t%1$s <cmd> network/*mail\n" 151*0Sstevel@tonic-gate "\t%1$s <cmd> network/smtp\n" 152*0Sstevel@tonic-gate "\t%1$s <cmd> smtp:sendmail\n" 153*0Sstevel@tonic-gate "\t%1$s <cmd> smtp\n" 154*0Sstevel@tonic-gate "\t%1$s <cmd> sendmail\n"), uu_getpname()); 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate exit(UU_EXIT_USAGE); 157*0Sstevel@tonic-gate } 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate /* 161*0Sstevel@tonic-gate * FMRI hash table for recursive enable. 162*0Sstevel@tonic-gate */ 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate static uint32_t 165*0Sstevel@tonic-gate hash_fmri(const char *str) 166*0Sstevel@tonic-gate { 167*0Sstevel@tonic-gate uint32_t h = 0, g; 168*0Sstevel@tonic-gate const char *p; 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate /* Generic hash function from uts/common/os/modhash.c . */ 171*0Sstevel@tonic-gate for (p = str; *p != '\0'; ++p) { 172*0Sstevel@tonic-gate h = (h << 4) + *p; 173*0Sstevel@tonic-gate if ((g = (h & 0xf0000000)) != 0) { 174*0Sstevel@tonic-gate h ^= (g >> 24); 175*0Sstevel@tonic-gate h ^= g; 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate return (h); 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate /* 183*0Sstevel@tonic-gate * Return 1 if str has been visited, 0 if it has not, and -1 if memory could not 184*0Sstevel@tonic-gate * be allocated. 185*0Sstevel@tonic-gate */ 186*0Sstevel@tonic-gate static int 187*0Sstevel@tonic-gate visited_find_or_add(const char *str, struct ht_elt **hep) 188*0Sstevel@tonic-gate { 189*0Sstevel@tonic-gate uint32_t h; 190*0Sstevel@tonic-gate uint_t i; 191*0Sstevel@tonic-gate struct ht_elt *he; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate h = hash_fmri(str); 194*0Sstevel@tonic-gate i = h & (HT_BUCKETS - 1); 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate for (he = visited[i]; he != NULL; he = he->next) { 197*0Sstevel@tonic-gate if (strcmp(he->str, str) == 0) { 198*0Sstevel@tonic-gate if (hep) 199*0Sstevel@tonic-gate *hep = he; 200*0Sstevel@tonic-gate return (1); 201*0Sstevel@tonic-gate } 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate he = malloc(offsetof(struct ht_elt, str) + strlen(str) + 1); 205*0Sstevel@tonic-gate if (he == NULL) 206*0Sstevel@tonic-gate return (-1); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate (void) strcpy(he->str, str); 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate he->next = visited[i]; 211*0Sstevel@tonic-gate visited[i] = he; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate if (hep) 214*0Sstevel@tonic-gate *hep = he; 215*0Sstevel@tonic-gate return (0); 216*0Sstevel@tonic-gate } 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* 220*0Sstevel@tonic-gate * Returns 0, ECANCELED if pg is deleted, ENOENT if propname doesn't exist, 221*0Sstevel@tonic-gate * EINVAL if the property is not of boolean type or has no values, and E2BIG 222*0Sstevel@tonic-gate * if it has more than one value. *bp is set if 0 or E2BIG is returned. 223*0Sstevel@tonic-gate */ 224*0Sstevel@tonic-gate int 225*0Sstevel@tonic-gate get_bool_prop(scf_propertygroup_t *pg, const char *propname, uint8_t *bp) 226*0Sstevel@tonic-gate { 227*0Sstevel@tonic-gate scf_property_t *prop; 228*0Sstevel@tonic-gate scf_value_t *val; 229*0Sstevel@tonic-gate int ret; 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate if ((prop = scf_property_create(h)) == NULL || 232*0Sstevel@tonic-gate (val = scf_value_create(h)) == NULL) 233*0Sstevel@tonic-gate scfdie(); 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate if (scf_pg_get_property(pg, propname, prop) != 0) { 236*0Sstevel@tonic-gate switch (scf_error()) { 237*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 238*0Sstevel@tonic-gate ret = ECANCELED; 239*0Sstevel@tonic-gate goto out; 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 242*0Sstevel@tonic-gate ret = ENOENT; 243*0Sstevel@tonic-gate goto out; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 246*0Sstevel@tonic-gate assert(0); 247*0Sstevel@tonic-gate abort(); 248*0Sstevel@tonic-gate /* NOTREACHED */ 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate default: 251*0Sstevel@tonic-gate scfdie(); 252*0Sstevel@tonic-gate } 253*0Sstevel@tonic-gate } 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate if (scf_property_get_value(prop, val) == 0) { 256*0Sstevel@tonic-gate ret = 0; 257*0Sstevel@tonic-gate } else { 258*0Sstevel@tonic-gate switch (scf_error()) { 259*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 260*0Sstevel@tonic-gate ret = ENOENT; 261*0Sstevel@tonic-gate goto out; 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 264*0Sstevel@tonic-gate ret = EINVAL; 265*0Sstevel@tonic-gate goto out; 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate case SCF_ERROR_CONSTRAINT_VIOLATED: 268*0Sstevel@tonic-gate ret = E2BIG; 269*0Sstevel@tonic-gate break; 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 272*0Sstevel@tonic-gate assert(0); 273*0Sstevel@tonic-gate abort(); 274*0Sstevel@tonic-gate /* NOTREACHED */ 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate default: 277*0Sstevel@tonic-gate scfdie(); 278*0Sstevel@tonic-gate } 279*0Sstevel@tonic-gate } 280*0Sstevel@tonic-gate 281*0Sstevel@tonic-gate if (scf_value_get_boolean(val, bp) != 0) { 282*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_TYPE_MISMATCH) 283*0Sstevel@tonic-gate scfdie(); 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate ret = EINVAL; 286*0Sstevel@tonic-gate goto out; 287*0Sstevel@tonic-gate } 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate out: 290*0Sstevel@tonic-gate scf_value_destroy(val); 291*0Sstevel@tonic-gate scf_property_destroy(prop); 292*0Sstevel@tonic-gate return (ret); 293*0Sstevel@tonic-gate } 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate /* 296*0Sstevel@tonic-gate * Returns 0, EPERM, or EROFS. 297*0Sstevel@tonic-gate */ 298*0Sstevel@tonic-gate static int 299*0Sstevel@tonic-gate set_bool_prop(scf_propertygroup_t *pg, const char *propname, boolean_t b) 300*0Sstevel@tonic-gate { 301*0Sstevel@tonic-gate scf_value_t *v; 302*0Sstevel@tonic-gate scf_transaction_t *tx; 303*0Sstevel@tonic-gate scf_transaction_entry_t *ent; 304*0Sstevel@tonic-gate int ret = 0, r; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate if ((tx = scf_transaction_create(h)) == NULL || 307*0Sstevel@tonic-gate (ent = scf_entry_create(h)) == NULL || 308*0Sstevel@tonic-gate (v = scf_value_create(h)) == NULL) 309*0Sstevel@tonic-gate scfdie(); 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate scf_value_set_boolean(v, b); 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate for (;;) { 314*0Sstevel@tonic-gate if (scf_transaction_start(tx, pg) == -1) { 315*0Sstevel@tonic-gate switch (scf_error()) { 316*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 317*0Sstevel@tonic-gate ret = EPERM; 318*0Sstevel@tonic-gate goto out; 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 321*0Sstevel@tonic-gate ret = EROFS; 322*0Sstevel@tonic-gate goto out; 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate default: 325*0Sstevel@tonic-gate scfdie(); 326*0Sstevel@tonic-gate } 327*0Sstevel@tonic-gate } 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate if (scf_transaction_property_change_type(tx, ent, propname, 330*0Sstevel@tonic-gate SCF_TYPE_BOOLEAN) != 0) { 331*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 332*0Sstevel@tonic-gate scfdie(); 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate if (scf_transaction_property_new(tx, ent, propname, 335*0Sstevel@tonic-gate SCF_TYPE_BOOLEAN) != 0) 336*0Sstevel@tonic-gate scfdie(); 337*0Sstevel@tonic-gate } 338*0Sstevel@tonic-gate 339*0Sstevel@tonic-gate r = scf_entry_add_value(ent, v); 340*0Sstevel@tonic-gate assert(r == 0); 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate r = scf_transaction_commit(tx); 343*0Sstevel@tonic-gate if (r == 1) 344*0Sstevel@tonic-gate break; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate scf_transaction_reset(tx); 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate if (r != 0) { 349*0Sstevel@tonic-gate switch (scf_error()) { 350*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 351*0Sstevel@tonic-gate ret = EPERM; 352*0Sstevel@tonic-gate goto out; 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 355*0Sstevel@tonic-gate ret = EROFS; 356*0Sstevel@tonic-gate goto out; 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate default: 359*0Sstevel@tonic-gate scfdie(); 360*0Sstevel@tonic-gate } 361*0Sstevel@tonic-gate } 362*0Sstevel@tonic-gate 363*0Sstevel@tonic-gate if (scf_pg_update(pg) == -1) 364*0Sstevel@tonic-gate scfdie(); 365*0Sstevel@tonic-gate } 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gate out: 368*0Sstevel@tonic-gate scf_transaction_destroy(tx); 369*0Sstevel@tonic-gate scf_entry_destroy(ent); 370*0Sstevel@tonic-gate scf_value_destroy(v); 371*0Sstevel@tonic-gate return (ret); 372*0Sstevel@tonic-gate } 373*0Sstevel@tonic-gate 374*0Sstevel@tonic-gate /* 375*0Sstevel@tonic-gate * Gets the single astring value of the propname property of pg. prop & v are 376*0Sstevel@tonic-gate * scratch space. Returns the length of the string on success or 377*0Sstevel@tonic-gate * -ENOENT - pg has no property named propname 378*0Sstevel@tonic-gate * -E2BIG - property has no values or multiple values 379*0Sstevel@tonic-gate * -EINVAL - property type is not compatible with astring 380*0Sstevel@tonic-gate */ 381*0Sstevel@tonic-gate ssize_t 382*0Sstevel@tonic-gate get_astring_prop(const scf_propertygroup_t *pg, const char *propname, 383*0Sstevel@tonic-gate scf_property_t *prop, scf_value_t *v, char *buf, size_t bufsz) 384*0Sstevel@tonic-gate { 385*0Sstevel@tonic-gate ssize_t sz; 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate if (scf_pg_get_property(pg, propname, prop) != 0) { 388*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 389*0Sstevel@tonic-gate scfdie(); 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate return (-ENOENT); 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate if (scf_property_get_value(prop, v) != 0) { 395*0Sstevel@tonic-gate switch (scf_error()) { 396*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 397*0Sstevel@tonic-gate case SCF_ERROR_CONSTRAINT_VIOLATED: 398*0Sstevel@tonic-gate return (-E2BIG); 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate default: 401*0Sstevel@tonic-gate scfdie(); 402*0Sstevel@tonic-gate } 403*0Sstevel@tonic-gate } 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate sz = scf_value_get_astring(v, buf, bufsz); 406*0Sstevel@tonic-gate if (sz < 0) { 407*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_TYPE_MISMATCH) 408*0Sstevel@tonic-gate scfdie(); 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate return (-EINVAL); 411*0Sstevel@tonic-gate } 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate return (sz); 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate /* 417*0Sstevel@tonic-gate * Returns 418*0Sstevel@tonic-gate * 0 - success 419*0Sstevel@tonic-gate * ECANCELED - pg was deleted 420*0Sstevel@tonic-gate * EPERM - permission denied 421*0Sstevel@tonic-gate * EACCES - access denied 422*0Sstevel@tonic-gate * EROFS - readonly 423*0Sstevel@tonic-gate */ 424*0Sstevel@tonic-gate static int 425*0Sstevel@tonic-gate delete_prop(scf_propertygroup_t *pg, const char *propname) 426*0Sstevel@tonic-gate { 427*0Sstevel@tonic-gate scf_transaction_t *tx; 428*0Sstevel@tonic-gate scf_transaction_entry_t *ent; 429*0Sstevel@tonic-gate int ret = 0, r; 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate if ((tx = scf_transaction_create(h)) == NULL || 432*0Sstevel@tonic-gate (ent = scf_entry_create(h)) == NULL) 433*0Sstevel@tonic-gate scfdie(); 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate for (;;) { 436*0Sstevel@tonic-gate if (scf_transaction_start(tx, pg) == -1) { 437*0Sstevel@tonic-gate switch (scf_error()) { 438*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 439*0Sstevel@tonic-gate ret = ECANCELED; 440*0Sstevel@tonic-gate goto out; 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 443*0Sstevel@tonic-gate ret = EPERM; 444*0Sstevel@tonic-gate goto out; 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_ACCESS: 447*0Sstevel@tonic-gate ret = EACCES; 448*0Sstevel@tonic-gate goto out; 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 451*0Sstevel@tonic-gate ret = EROFS; 452*0Sstevel@tonic-gate goto out; 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 455*0Sstevel@tonic-gate case SCF_ERROR_HANDLE_MISMATCH: 456*0Sstevel@tonic-gate case SCF_ERROR_NOT_BOUND: 457*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 458*0Sstevel@tonic-gate case SCF_ERROR_IN_USE: 459*0Sstevel@tonic-gate default: 460*0Sstevel@tonic-gate scfdie(); 461*0Sstevel@tonic-gate } 462*0Sstevel@tonic-gate } 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate if (scf_transaction_property_delete(tx, ent, propname) == -1) 465*0Sstevel@tonic-gate switch (scf_error()) { 466*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 467*0Sstevel@tonic-gate ret = ECANCELED; 468*0Sstevel@tonic-gate goto out; 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 471*0Sstevel@tonic-gate ret = 0; 472*0Sstevel@tonic-gate goto out; 473*0Sstevel@tonic-gate 474*0Sstevel@tonic-gate case SCF_ERROR_HANDLE_MISMATCH: 475*0Sstevel@tonic-gate case SCF_ERROR_NOT_BOUND: 476*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 477*0Sstevel@tonic-gate case SCF_ERROR_INVALID_ARGUMENT: 478*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 479*0Sstevel@tonic-gate default: 480*0Sstevel@tonic-gate scfdie(); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate r = scf_transaction_commit(tx); 484*0Sstevel@tonic-gate if (r == 1) 485*0Sstevel@tonic-gate break; 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate scf_transaction_reset(tx); 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate if (r != 0) { 490*0Sstevel@tonic-gate switch (scf_error()) { 491*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 492*0Sstevel@tonic-gate ret = ECANCELED; 493*0Sstevel@tonic-gate goto out; 494*0Sstevel@tonic-gate 495*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 496*0Sstevel@tonic-gate ret = EPERM; 497*0Sstevel@tonic-gate goto out; 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_ACCESS: 500*0Sstevel@tonic-gate ret = EACCES; 501*0Sstevel@tonic-gate goto out; 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 504*0Sstevel@tonic-gate ret = EROFS; 505*0Sstevel@tonic-gate goto out; 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gate case SCF_ERROR_INVALID_ARGUMENT: 508*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 509*0Sstevel@tonic-gate case SCF_ERROR_NOT_BOUND: 510*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 511*0Sstevel@tonic-gate default: 512*0Sstevel@tonic-gate scfdie(); 513*0Sstevel@tonic-gate } 514*0Sstevel@tonic-gate } 515*0Sstevel@tonic-gate 516*0Sstevel@tonic-gate if (scf_pg_update(pg) == -1) { 517*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_DELETED) 518*0Sstevel@tonic-gate scfdie(); 519*0Sstevel@tonic-gate 520*0Sstevel@tonic-gate ret = ECANCELED; 521*0Sstevel@tonic-gate goto out; 522*0Sstevel@tonic-gate } 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate 525*0Sstevel@tonic-gate out: 526*0Sstevel@tonic-gate scf_transaction_destroy(tx); 527*0Sstevel@tonic-gate scf_entry_destroy(ent); 528*0Sstevel@tonic-gate return (ret); 529*0Sstevel@tonic-gate } 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate /* 532*0Sstevel@tonic-gate * Returns 0 or EPERM. 533*0Sstevel@tonic-gate */ 534*0Sstevel@tonic-gate static int 535*0Sstevel@tonic-gate pg_get_or_add(scf_instance_t *inst, const char *pgname, const char *pgtype, 536*0Sstevel@tonic-gate uint32_t pgflags, scf_propertygroup_t *pg) 537*0Sstevel@tonic-gate { 538*0Sstevel@tonic-gate again: 539*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, pgname, pg) == 0) 540*0Sstevel@tonic-gate return (0); 541*0Sstevel@tonic-gate 542*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 543*0Sstevel@tonic-gate scfdie(); 544*0Sstevel@tonic-gate 545*0Sstevel@tonic-gate if (scf_instance_add_pg(inst, pgname, pgtype, pgflags, pg) == 0) 546*0Sstevel@tonic-gate return (0); 547*0Sstevel@tonic-gate 548*0Sstevel@tonic-gate switch (scf_error()) { 549*0Sstevel@tonic-gate case SCF_ERROR_EXISTS: 550*0Sstevel@tonic-gate goto again; 551*0Sstevel@tonic-gate 552*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 553*0Sstevel@tonic-gate return (EPERM); 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gate default: 556*0Sstevel@tonic-gate scfdie(); 557*0Sstevel@tonic-gate /* NOTREACHED */ 558*0Sstevel@tonic-gate } 559*0Sstevel@tonic-gate } 560*0Sstevel@tonic-gate 561*0Sstevel@tonic-gate /* 562*0Sstevel@tonic-gate * Enable or disable inst, per enable. If temp is true, set 563*0Sstevel@tonic-gate * general_ovr/enabled. Otherwise set general/enabled and delete 564*0Sstevel@tonic-gate * general_ovr/enabled if it exists (order is important here: we don't want the 565*0Sstevel@tonic-gate * enabled status to glitch). 566*0Sstevel@tonic-gate */ 567*0Sstevel@tonic-gate static void 568*0Sstevel@tonic-gate set_inst_enabled(const char *fmri, scf_instance_t *inst, boolean_t temp, 569*0Sstevel@tonic-gate boolean_t enable) 570*0Sstevel@tonic-gate { 571*0Sstevel@tonic-gate scf_propertygroup_t *pg; 572*0Sstevel@tonic-gate uint8_t b; 573*0Sstevel@tonic-gate const char *pgname = NULL; /* For emsg_pg_perm_denied */ 574*0Sstevel@tonic-gate int r; 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate pg = scf_pg_create(h); 577*0Sstevel@tonic-gate if (pg == NULL) 578*0Sstevel@tonic-gate scfdie(); 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate if (temp) { 581*0Sstevel@tonic-gate /* Set general_ovr/enabled */ 582*0Sstevel@tonic-gate pgname = SCF_PG_GENERAL_OVR; 583*0Sstevel@tonic-gate if (pg_get_or_add(inst, pgname, SCF_PG_GENERAL_OVR_TYPE, 584*0Sstevel@tonic-gate SCF_PG_GENERAL_OVR_FLAGS, pg) != 0) 585*0Sstevel@tonic-gate goto eperm; 586*0Sstevel@tonic-gate 587*0Sstevel@tonic-gate switch (set_bool_prop(pg, SCF_PROPERTY_ENABLED, enable) != 0) { 588*0Sstevel@tonic-gate case 0: 589*0Sstevel@tonic-gate break; 590*0Sstevel@tonic-gate 591*0Sstevel@tonic-gate case EPERM: 592*0Sstevel@tonic-gate goto eperm; 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate case EROFS: 595*0Sstevel@tonic-gate /* Shouldn't happen, but it can. */ 596*0Sstevel@tonic-gate if (!verbose) 597*0Sstevel@tonic-gate uu_warn(gettext("%s: Repository read-only.\n"), 598*0Sstevel@tonic-gate fmri); 599*0Sstevel@tonic-gate else 600*0Sstevel@tonic-gate uu_warn(gettext("%s: Could not set %s/%s " 601*0Sstevel@tonic-gate "(repository read-only).\n"), fmri, 602*0Sstevel@tonic-gate SCF_PG_GENERAL_OVR, SCF_PROPERTY_ENABLED); 603*0Sstevel@tonic-gate goto out; 604*0Sstevel@tonic-gate 605*0Sstevel@tonic-gate default: 606*0Sstevel@tonic-gate assert(0); 607*0Sstevel@tonic-gate abort(); 608*0Sstevel@tonic-gate } 609*0Sstevel@tonic-gate 610*0Sstevel@tonic-gate if (verbose) 611*0Sstevel@tonic-gate (void) printf(enable ? 612*0Sstevel@tonic-gate gettext("%s temporarily enabled.\n") : 613*0Sstevel@tonic-gate gettext("%s temporarily disabled.\n"), fmri); 614*0Sstevel@tonic-gate } else { 615*0Sstevel@tonic-gate again: 616*0Sstevel@tonic-gate pgname = SCF_PG_GENERAL; 617*0Sstevel@tonic-gate if (pg_get_or_add(inst, pgname, SCF_PG_GENERAL_TYPE, 618*0Sstevel@tonic-gate SCF_PG_GENERAL_FLAGS, pg) != 0) 619*0Sstevel@tonic-gate goto eperm; 620*0Sstevel@tonic-gate 621*0Sstevel@tonic-gate switch (set_bool_prop(pg, SCF_PROPERTY_ENABLED, enable)) { 622*0Sstevel@tonic-gate case 0: 623*0Sstevel@tonic-gate break; 624*0Sstevel@tonic-gate 625*0Sstevel@tonic-gate case EPERM: 626*0Sstevel@tonic-gate goto eperm; 627*0Sstevel@tonic-gate 628*0Sstevel@tonic-gate case EROFS: 629*0Sstevel@tonic-gate /* 630*0Sstevel@tonic-gate * If general/enabled is already set the way we want, 631*0Sstevel@tonic-gate * proceed. 632*0Sstevel@tonic-gate */ 633*0Sstevel@tonic-gate switch (get_bool_prop(pg, SCF_PROPERTY_ENABLED, &b)) { 634*0Sstevel@tonic-gate case 0: 635*0Sstevel@tonic-gate if ((b != 0) == (enable != B_FALSE)) 636*0Sstevel@tonic-gate break; 637*0Sstevel@tonic-gate /* FALLTHROUGH */ 638*0Sstevel@tonic-gate 639*0Sstevel@tonic-gate case ENOENT: 640*0Sstevel@tonic-gate case EINVAL: 641*0Sstevel@tonic-gate case E2BIG: 642*0Sstevel@tonic-gate if (!verbose) 643*0Sstevel@tonic-gate uu_warn(gettext("%s: Repository " 644*0Sstevel@tonic-gate "read-only.\n"), fmri); 645*0Sstevel@tonic-gate else 646*0Sstevel@tonic-gate uu_warn(gettext("%s: Could not set " 647*0Sstevel@tonic-gate "%s/%s (repository read-only).\n"), 648*0Sstevel@tonic-gate fmri, SCF_PG_GENERAL, 649*0Sstevel@tonic-gate SCF_PROPERTY_ENABLED); 650*0Sstevel@tonic-gate goto out; 651*0Sstevel@tonic-gate 652*0Sstevel@tonic-gate case ECANCELED: 653*0Sstevel@tonic-gate goto again; 654*0Sstevel@tonic-gate 655*0Sstevel@tonic-gate default: 656*0Sstevel@tonic-gate assert(0); 657*0Sstevel@tonic-gate abort(); 658*0Sstevel@tonic-gate } 659*0Sstevel@tonic-gate break; 660*0Sstevel@tonic-gate 661*0Sstevel@tonic-gate default: 662*0Sstevel@tonic-gate assert(0); 663*0Sstevel@tonic-gate abort(); 664*0Sstevel@tonic-gate } 665*0Sstevel@tonic-gate 666*0Sstevel@tonic-gate pgname = SCF_PG_GENERAL_OVR; 667*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, pgname, pg) == 0) { 668*0Sstevel@tonic-gate r = delete_prop(pg, SCF_PROPERTY_ENABLED); 669*0Sstevel@tonic-gate switch (r) { 670*0Sstevel@tonic-gate case 0: 671*0Sstevel@tonic-gate break; 672*0Sstevel@tonic-gate 673*0Sstevel@tonic-gate case ECANCELED: 674*0Sstevel@tonic-gate uu_warn(emsg_no_service, fmri); 675*0Sstevel@tonic-gate goto out; 676*0Sstevel@tonic-gate 677*0Sstevel@tonic-gate case EPERM: 678*0Sstevel@tonic-gate goto eperm; 679*0Sstevel@tonic-gate 680*0Sstevel@tonic-gate case EACCES: 681*0Sstevel@tonic-gate uu_warn(gettext("Could not delete %s/%s " 682*0Sstevel@tonic-gate "property of %s: backend access denied.\n"), 683*0Sstevel@tonic-gate pgname, SCF_PROPERTY_ENABLED, fmri); 684*0Sstevel@tonic-gate goto out; 685*0Sstevel@tonic-gate 686*0Sstevel@tonic-gate case EROFS: 687*0Sstevel@tonic-gate uu_warn(gettext("Could not delete %s/%s " 688*0Sstevel@tonic-gate "property of %s: backend is read-only.\n"), 689*0Sstevel@tonic-gate pgname, SCF_PROPERTY_ENABLED, fmri); 690*0Sstevel@tonic-gate goto out; 691*0Sstevel@tonic-gate 692*0Sstevel@tonic-gate default: 693*0Sstevel@tonic-gate bad_error("delete_prop", r); 694*0Sstevel@tonic-gate } 695*0Sstevel@tonic-gate } else { 696*0Sstevel@tonic-gate switch (scf_error()) { 697*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 698*0Sstevel@tonic-gate /* Print something? */ 699*0Sstevel@tonic-gate 700*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 701*0Sstevel@tonic-gate break; 702*0Sstevel@tonic-gate 703*0Sstevel@tonic-gate case SCF_ERROR_HANDLE_MISMATCH: 704*0Sstevel@tonic-gate case SCF_ERROR_INVALID_ARGUMENT: 705*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 706*0Sstevel@tonic-gate assert(0); 707*0Sstevel@tonic-gate abort(); 708*0Sstevel@tonic-gate /* NOTREACHED */ 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 711*0Sstevel@tonic-gate default: 712*0Sstevel@tonic-gate scfdie(); 713*0Sstevel@tonic-gate } 714*0Sstevel@tonic-gate } 715*0Sstevel@tonic-gate 716*0Sstevel@tonic-gate if (verbose) 717*0Sstevel@tonic-gate (void) printf(enable ? gettext("%s enabled.\n") : 718*0Sstevel@tonic-gate gettext("%s disabled.\n"), fmri); 719*0Sstevel@tonic-gate } 720*0Sstevel@tonic-gate 721*0Sstevel@tonic-gate scf_pg_destroy(pg); 722*0Sstevel@tonic-gate return; 723*0Sstevel@tonic-gate 724*0Sstevel@tonic-gate eperm: 725*0Sstevel@tonic-gate assert(pgname != NULL); 726*0Sstevel@tonic-gate if (!verbose) 727*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 728*0Sstevel@tonic-gate else 729*0Sstevel@tonic-gate uu_warn(emsg_pg_perm_denied, fmri, pgname); 730*0Sstevel@tonic-gate 731*0Sstevel@tonic-gate out: 732*0Sstevel@tonic-gate scf_pg_destroy(pg); 733*0Sstevel@tonic-gate exit_status = 1; 734*0Sstevel@tonic-gate } 735*0Sstevel@tonic-gate 736*0Sstevel@tonic-gate /* 737*0Sstevel@tonic-gate * Set inst to the instance which corresponds to fmri. If fmri identifies 738*0Sstevel@tonic-gate * a service with a single instance, get that instance. 739*0Sstevel@tonic-gate * 740*0Sstevel@tonic-gate * Fails with 741*0Sstevel@tonic-gate * ENOTSUP - fmri has an unsupported scheme 742*0Sstevel@tonic-gate * EINVAL - fmri is invalid 743*0Sstevel@tonic-gate * ENOTDIR - fmri does not identify a service or instance 744*0Sstevel@tonic-gate * ENOENT - could not locate instance 745*0Sstevel@tonic-gate * E2BIG - fmri is a service with multiple instances (warning not printed) 746*0Sstevel@tonic-gate */ 747*0Sstevel@tonic-gate static int 748*0Sstevel@tonic-gate get_inst_mult(const char *fmri, scf_instance_t *inst) 749*0Sstevel@tonic-gate { 750*0Sstevel@tonic-gate char *cfmri; 751*0Sstevel@tonic-gate const char *svc_name, *inst_name, *pg_name; 752*0Sstevel@tonic-gate scf_service_t *svc; 753*0Sstevel@tonic-gate scf_instance_t *inst2; 754*0Sstevel@tonic-gate scf_iter_t *iter; 755*0Sstevel@tonic-gate int ret; 756*0Sstevel@tonic-gate 757*0Sstevel@tonic-gate if (strncmp(fmri, "lrc:", sizeof ("lrc:") - 1) == 0) { 758*0Sstevel@tonic-gate uu_warn(gettext("FMRI \"%s\" is a legacy service.\n"), fmri); 759*0Sstevel@tonic-gate exit_status = 1; 760*0Sstevel@tonic-gate return (ENOTSUP); 761*0Sstevel@tonic-gate } 762*0Sstevel@tonic-gate 763*0Sstevel@tonic-gate cfmri = strdup(fmri); 764*0Sstevel@tonic-gate if (cfmri == NULL) 765*0Sstevel@tonic-gate uu_die(emsg_nomem); 766*0Sstevel@tonic-gate 767*0Sstevel@tonic-gate if (scf_parse_svc_fmri(cfmri, NULL, &svc_name, &inst_name, &pg_name, 768*0Sstevel@tonic-gate NULL) != SCF_SUCCESS) { 769*0Sstevel@tonic-gate free(cfmri); 770*0Sstevel@tonic-gate uu_warn(gettext("FMRI \"%s\" is invalid.\n"), fmri); 771*0Sstevel@tonic-gate exit_status = 1; 772*0Sstevel@tonic-gate return (EINVAL); 773*0Sstevel@tonic-gate } 774*0Sstevel@tonic-gate 775*0Sstevel@tonic-gate free(cfmri); 776*0Sstevel@tonic-gate 777*0Sstevel@tonic-gate if (svc_name == NULL || pg_name != NULL) { 778*0Sstevel@tonic-gate uu_warn(gettext( 779*0Sstevel@tonic-gate "FMRI \"%s\" does not designate a service or instance.\n"), 780*0Sstevel@tonic-gate fmri); 781*0Sstevel@tonic-gate exit_status = 1; 782*0Sstevel@tonic-gate return (ENOTDIR); 783*0Sstevel@tonic-gate } 784*0Sstevel@tonic-gate 785*0Sstevel@tonic-gate if (inst_name != NULL) { 786*0Sstevel@tonic-gate if (scf_handle_decode_fmri(h, fmri, NULL, NULL, inst, NULL, 787*0Sstevel@tonic-gate NULL, SCF_DECODE_FMRI_EXACT) == 0) 788*0Sstevel@tonic-gate return (0); 789*0Sstevel@tonic-gate 790*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 791*0Sstevel@tonic-gate scfdie(); 792*0Sstevel@tonic-gate 793*0Sstevel@tonic-gate uu_warn(gettext("No such instance \"%s\".\n"), fmri); 794*0Sstevel@tonic-gate exit_status = 1; 795*0Sstevel@tonic-gate 796*0Sstevel@tonic-gate return (ENOENT); 797*0Sstevel@tonic-gate } 798*0Sstevel@tonic-gate 799*0Sstevel@tonic-gate if ((svc = scf_service_create(h)) == NULL || 800*0Sstevel@tonic-gate (inst2 = scf_instance_create(h)) == NULL || 801*0Sstevel@tonic-gate (iter = scf_iter_create(h)) == NULL) 802*0Sstevel@tonic-gate scfdie(); 803*0Sstevel@tonic-gate 804*0Sstevel@tonic-gate if (scf_handle_decode_fmri(h, fmri, NULL, svc, NULL, NULL, NULL, 805*0Sstevel@tonic-gate SCF_DECODE_FMRI_EXACT) != SCF_SUCCESS) { 806*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 807*0Sstevel@tonic-gate scfdie(); 808*0Sstevel@tonic-gate 809*0Sstevel@tonic-gate uu_warn(emsg_no_service, fmri); 810*0Sstevel@tonic-gate exit_status = 1; 811*0Sstevel@tonic-gate 812*0Sstevel@tonic-gate ret = ENOENT; 813*0Sstevel@tonic-gate goto out; 814*0Sstevel@tonic-gate } 815*0Sstevel@tonic-gate 816*0Sstevel@tonic-gate /* If the service has only one child, use it. */ 817*0Sstevel@tonic-gate if (scf_iter_service_instances(iter, svc) != SCF_SUCCESS) 818*0Sstevel@tonic-gate scfdie(); 819*0Sstevel@tonic-gate 820*0Sstevel@tonic-gate ret = scf_iter_next_instance(iter, inst); 821*0Sstevel@tonic-gate if (ret < 0) 822*0Sstevel@tonic-gate scfdie(); 823*0Sstevel@tonic-gate if (ret != 1) { 824*0Sstevel@tonic-gate uu_warn(gettext("Service \"%s\" has no instances.\n"), 825*0Sstevel@tonic-gate fmri); 826*0Sstevel@tonic-gate exit_status = 1; 827*0Sstevel@tonic-gate ret = ENOENT; 828*0Sstevel@tonic-gate goto out; 829*0Sstevel@tonic-gate } 830*0Sstevel@tonic-gate 831*0Sstevel@tonic-gate ret = scf_iter_next_instance(iter, inst2); 832*0Sstevel@tonic-gate if (ret < 0) 833*0Sstevel@tonic-gate scfdie(); 834*0Sstevel@tonic-gate 835*0Sstevel@tonic-gate if (ret != 0) { 836*0Sstevel@tonic-gate ret = E2BIG; 837*0Sstevel@tonic-gate goto out; 838*0Sstevel@tonic-gate } 839*0Sstevel@tonic-gate 840*0Sstevel@tonic-gate ret = 0; 841*0Sstevel@tonic-gate 842*0Sstevel@tonic-gate out: 843*0Sstevel@tonic-gate scf_iter_destroy(iter); 844*0Sstevel@tonic-gate scf_instance_destroy(inst2); 845*0Sstevel@tonic-gate scf_service_destroy(svc); 846*0Sstevel@tonic-gate return (ret); 847*0Sstevel@tonic-gate } 848*0Sstevel@tonic-gate 849*0Sstevel@tonic-gate /* 850*0Sstevel@tonic-gate * Same as get_inst_mult(), but on E2BIG prints a warning and returns ENOENT. 851*0Sstevel@tonic-gate */ 852*0Sstevel@tonic-gate static int 853*0Sstevel@tonic-gate get_inst(const char *fmri, scf_instance_t *inst) 854*0Sstevel@tonic-gate { 855*0Sstevel@tonic-gate int r; 856*0Sstevel@tonic-gate 857*0Sstevel@tonic-gate r = get_inst_mult(fmri, inst); 858*0Sstevel@tonic-gate if (r != E2BIG) 859*0Sstevel@tonic-gate return (r); 860*0Sstevel@tonic-gate 861*0Sstevel@tonic-gate uu_warn(gettext("operation on service %s is ambiguous; " 862*0Sstevel@tonic-gate "instance specification needed.\n"), fmri); 863*0Sstevel@tonic-gate return (ENOENT); 864*0Sstevel@tonic-gate } 865*0Sstevel@tonic-gate 866*0Sstevel@tonic-gate static char * 867*0Sstevel@tonic-gate inst_get_fmri(const scf_instance_t *inst) 868*0Sstevel@tonic-gate { 869*0Sstevel@tonic-gate ssize_t sz; 870*0Sstevel@tonic-gate 871*0Sstevel@tonic-gate sz = scf_instance_to_fmri(inst, scratch_fmri, max_scf_fmri_sz); 872*0Sstevel@tonic-gate if (sz < 0) 873*0Sstevel@tonic-gate scfdie(); 874*0Sstevel@tonic-gate if (sz >= max_scf_fmri_sz) 875*0Sstevel@tonic-gate uu_die(gettext("scf_instance_to_fmri() returned unexpectedly " 876*0Sstevel@tonic-gate "long value.\n")); 877*0Sstevel@tonic-gate 878*0Sstevel@tonic-gate return (scratch_fmri); 879*0Sstevel@tonic-gate } 880*0Sstevel@tonic-gate 881*0Sstevel@tonic-gate static ssize_t 882*0Sstevel@tonic-gate dep_get_astring(const char *fmri, const char *pgname, 883*0Sstevel@tonic-gate const scf_propertygroup_t *pg, const char *propname, scf_property_t *prop, 884*0Sstevel@tonic-gate scf_value_t *v, char *buf, size_t bufsz) 885*0Sstevel@tonic-gate { 886*0Sstevel@tonic-gate ssize_t sz; 887*0Sstevel@tonic-gate 888*0Sstevel@tonic-gate sz = get_astring_prop(pg, propname, prop, v, buf, bufsz); 889*0Sstevel@tonic-gate if (sz >= 0) 890*0Sstevel@tonic-gate return (sz); 891*0Sstevel@tonic-gate 892*0Sstevel@tonic-gate switch (-sz) { 893*0Sstevel@tonic-gate case ENOENT: 894*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s\" dependency " 895*0Sstevel@tonic-gate "lacks \"%s\" property.)\n"), fmri, pgname, propname); 896*0Sstevel@tonic-gate return (-1); 897*0Sstevel@tonic-gate 898*0Sstevel@tonic-gate case E2BIG: 899*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s/%s\" property " 900*0Sstevel@tonic-gate "is not single-valued.)\n"), fmri, pgname, propname); 901*0Sstevel@tonic-gate return (-1); 902*0Sstevel@tonic-gate 903*0Sstevel@tonic-gate case EINVAL: 904*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s/%s\" property " 905*0Sstevel@tonic-gate "is not of astring type.)\n"), fmri, pgname, propname); 906*0Sstevel@tonic-gate return (-1); 907*0Sstevel@tonic-gate 908*0Sstevel@tonic-gate default: 909*0Sstevel@tonic-gate assert(0); 910*0Sstevel@tonic-gate abort(); 911*0Sstevel@tonic-gate /* NOTREACHED */ 912*0Sstevel@tonic-gate } 913*0Sstevel@tonic-gate } 914*0Sstevel@tonic-gate 915*0Sstevel@tonic-gate static boolean_t 916*0Sstevel@tonic-gate multiple_instances(scf_iter_t *iter, scf_value_t *v, char *buf) 917*0Sstevel@tonic-gate { 918*0Sstevel@tonic-gate int count = 0, r; 919*0Sstevel@tonic-gate boolean_t ret; 920*0Sstevel@tonic-gate scf_instance_t *inst; 921*0Sstevel@tonic-gate 922*0Sstevel@tonic-gate inst = scf_instance_create(h); 923*0Sstevel@tonic-gate if (inst == NULL) 924*0Sstevel@tonic-gate scfdie(); 925*0Sstevel@tonic-gate 926*0Sstevel@tonic-gate for (;;) { 927*0Sstevel@tonic-gate r = scf_iter_next_value(iter, v); 928*0Sstevel@tonic-gate if (r == 0) { 929*0Sstevel@tonic-gate ret = B_FALSE; 930*0Sstevel@tonic-gate goto out; 931*0Sstevel@tonic-gate } 932*0Sstevel@tonic-gate if (r != 1) 933*0Sstevel@tonic-gate scfdie(); 934*0Sstevel@tonic-gate 935*0Sstevel@tonic-gate if (scf_value_get_astring(v, buf, max_scf_fmri_sz) < 0) 936*0Sstevel@tonic-gate scfdie(); 937*0Sstevel@tonic-gate 938*0Sstevel@tonic-gate switch (get_inst_mult(buf, inst)) { 939*0Sstevel@tonic-gate case 0: 940*0Sstevel@tonic-gate ++count; 941*0Sstevel@tonic-gate if (count > 1) { 942*0Sstevel@tonic-gate ret = B_TRUE; 943*0Sstevel@tonic-gate goto out; 944*0Sstevel@tonic-gate } 945*0Sstevel@tonic-gate break; 946*0Sstevel@tonic-gate 947*0Sstevel@tonic-gate case ENOTSUP: 948*0Sstevel@tonic-gate case EINVAL: 949*0Sstevel@tonic-gate case ENOTDIR: 950*0Sstevel@tonic-gate case ENOENT: 951*0Sstevel@tonic-gate continue; 952*0Sstevel@tonic-gate 953*0Sstevel@tonic-gate case E2BIG: 954*0Sstevel@tonic-gate ret = B_TRUE; 955*0Sstevel@tonic-gate goto out; 956*0Sstevel@tonic-gate 957*0Sstevel@tonic-gate default: 958*0Sstevel@tonic-gate assert(0); 959*0Sstevel@tonic-gate abort(); 960*0Sstevel@tonic-gate } 961*0Sstevel@tonic-gate } 962*0Sstevel@tonic-gate 963*0Sstevel@tonic-gate out: 964*0Sstevel@tonic-gate scf_instance_destroy(inst); 965*0Sstevel@tonic-gate return (ret); 966*0Sstevel@tonic-gate } 967*0Sstevel@tonic-gate 968*0Sstevel@tonic-gate /* 969*0Sstevel@tonic-gate * Enable the service or instance identified by fmri and its dependencies, 970*0Sstevel@tonic-gate * recursively. Specifically, call get_inst(fmri), enable the result, and 971*0Sstevel@tonic-gate * recurse on its restarter and the dependencies. To avoid duplication of 972*0Sstevel@tonic-gate * effort or looping around a dependency cycle, each FMRI is entered into the 973*0Sstevel@tonic-gate * "visited" hash table. While recursing, the hash table entry is marked 974*0Sstevel@tonic-gate * "active", so that if we come upon it again, we know we've hit a cycle. 975*0Sstevel@tonic-gate * exclude_all and optional_all dependencies are ignored. require_any 976*0Sstevel@tonic-gate * dependencies are followed only if they comprise a single service; otherwise 977*0Sstevel@tonic-gate * the user is warned. 978*0Sstevel@tonic-gate * 979*0Sstevel@tonic-gate * fmri must point to a writable max_scf_fmri_sz buffer. Returns EINVAL if fmri 980*0Sstevel@tonic-gate * is invalid, E2BIG if fmri identifies a service with multiple instances, ELOOP 981*0Sstevel@tonic-gate * on cycle detection, or 0 on success. 982*0Sstevel@tonic-gate */ 983*0Sstevel@tonic-gate static int 984*0Sstevel@tonic-gate enable_fmri_rec(char *fmri, boolean_t temp) 985*0Sstevel@tonic-gate { 986*0Sstevel@tonic-gate scf_instance_t *inst; 987*0Sstevel@tonic-gate scf_snapshot_t *snap; 988*0Sstevel@tonic-gate scf_propertygroup_t *pg; 989*0Sstevel@tonic-gate scf_property_t *prop; 990*0Sstevel@tonic-gate scf_value_t *v; 991*0Sstevel@tonic-gate scf_iter_t *pg_iter, *val_iter; 992*0Sstevel@tonic-gate scf_type_t ty; 993*0Sstevel@tonic-gate char *buf, *pgname; 994*0Sstevel@tonic-gate ssize_t name_sz, len, sz; 995*0Sstevel@tonic-gate int ret; 996*0Sstevel@tonic-gate struct ht_elt *he; 997*0Sstevel@tonic-gate 998*0Sstevel@tonic-gate len = scf_canonify_fmri(fmri, fmri, max_scf_fmri_sz); 999*0Sstevel@tonic-gate if (len < 0) { 1000*0Sstevel@tonic-gate assert(scf_error() == SCF_ERROR_INVALID_ARGUMENT); 1001*0Sstevel@tonic-gate return (EINVAL); 1002*0Sstevel@tonic-gate } 1003*0Sstevel@tonic-gate assert(len < max_scf_fmri_sz); 1004*0Sstevel@tonic-gate 1005*0Sstevel@tonic-gate switch (visited_find_or_add(fmri, &he)) { 1006*0Sstevel@tonic-gate case 0: 1007*0Sstevel@tonic-gate he->active = B_TRUE; 1008*0Sstevel@tonic-gate break; 1009*0Sstevel@tonic-gate 1010*0Sstevel@tonic-gate case 1: 1011*0Sstevel@tonic-gate return (he->active ? ELOOP : 0); 1012*0Sstevel@tonic-gate 1013*0Sstevel@tonic-gate case -1: 1014*0Sstevel@tonic-gate uu_die(emsg_nomem); 1015*0Sstevel@tonic-gate 1016*0Sstevel@tonic-gate default: 1017*0Sstevel@tonic-gate assert(0); 1018*0Sstevel@tonic-gate abort(); 1019*0Sstevel@tonic-gate } 1020*0Sstevel@tonic-gate 1021*0Sstevel@tonic-gate inst = scf_instance_create(h); 1022*0Sstevel@tonic-gate if (inst == NULL) 1023*0Sstevel@tonic-gate scfdie(); 1024*0Sstevel@tonic-gate 1025*0Sstevel@tonic-gate switch (get_inst_mult(fmri, inst)) { 1026*0Sstevel@tonic-gate case 0: 1027*0Sstevel@tonic-gate break; 1028*0Sstevel@tonic-gate 1029*0Sstevel@tonic-gate case E2BIG: 1030*0Sstevel@tonic-gate he->active = B_FALSE; 1031*0Sstevel@tonic-gate return (E2BIG); 1032*0Sstevel@tonic-gate 1033*0Sstevel@tonic-gate default: 1034*0Sstevel@tonic-gate he->active = B_FALSE; 1035*0Sstevel@tonic-gate return (0); 1036*0Sstevel@tonic-gate } 1037*0Sstevel@tonic-gate 1038*0Sstevel@tonic-gate set_inst_enabled(fmri, inst, temp, B_TRUE); 1039*0Sstevel@tonic-gate 1040*0Sstevel@tonic-gate if ((snap = scf_snapshot_create(h)) == NULL || 1041*0Sstevel@tonic-gate (pg = scf_pg_create(h)) == NULL || 1042*0Sstevel@tonic-gate (prop = scf_property_create(h)) == NULL || 1043*0Sstevel@tonic-gate (v = scf_value_create(h)) == NULL || 1044*0Sstevel@tonic-gate (pg_iter = scf_iter_create(h)) == NULL || 1045*0Sstevel@tonic-gate (val_iter = scf_iter_create(h)) == NULL) 1046*0Sstevel@tonic-gate scfdie(); 1047*0Sstevel@tonic-gate 1048*0Sstevel@tonic-gate buf = malloc(max_scf_fmri_sz); 1049*0Sstevel@tonic-gate if (buf == NULL) 1050*0Sstevel@tonic-gate uu_die(emsg_nomem); 1051*0Sstevel@tonic-gate 1052*0Sstevel@tonic-gate name_sz = scf_limit(SCF_LIMIT_MAX_NAME_LENGTH); 1053*0Sstevel@tonic-gate if (name_sz < 0) 1054*0Sstevel@tonic-gate scfdie(); 1055*0Sstevel@tonic-gate ++name_sz; 1056*0Sstevel@tonic-gate pgname = malloc(name_sz); 1057*0Sstevel@tonic-gate if (pgname == NULL) 1058*0Sstevel@tonic-gate uu_die(emsg_nomem); 1059*0Sstevel@tonic-gate 1060*0Sstevel@tonic-gate if (scf_instance_get_snapshot(inst, "running", snap) != 0) { 1061*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1062*0Sstevel@tonic-gate scfdie(); 1063*0Sstevel@tonic-gate 1064*0Sstevel@tonic-gate scf_snapshot_destroy(snap); 1065*0Sstevel@tonic-gate snap = NULL; 1066*0Sstevel@tonic-gate } 1067*0Sstevel@tonic-gate 1068*0Sstevel@tonic-gate /* Enable restarter */ 1069*0Sstevel@tonic-gate if (scf_instance_get_pg_composed(inst, snap, SCF_PG_GENERAL, pg) != 0) { 1070*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1071*0Sstevel@tonic-gate scfdie(); 1072*0Sstevel@tonic-gate 1073*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (lacks \"%s\" " 1074*0Sstevel@tonic-gate "property group).\n"), fmri, SCF_PG_GENERAL); 1075*0Sstevel@tonic-gate ret = 0; 1076*0Sstevel@tonic-gate goto out; 1077*0Sstevel@tonic-gate } 1078*0Sstevel@tonic-gate 1079*0Sstevel@tonic-gate sz = get_astring_prop(pg, SCF_PROPERTY_RESTARTER, prop, v, buf, 1080*0Sstevel@tonic-gate max_scf_fmri_sz); 1081*0Sstevel@tonic-gate if (sz > max_scf_fmri_sz) { 1082*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (the value of " 1083*0Sstevel@tonic-gate "\"%s/%s\" is too long).\n"), fmri, SCF_PG_GENERAL, 1084*0Sstevel@tonic-gate SCF_PROPERTY_RESTARTER); 1085*0Sstevel@tonic-gate ret = 0; 1086*0Sstevel@tonic-gate goto out; 1087*0Sstevel@tonic-gate } else if (sz >= 0) { 1088*0Sstevel@tonic-gate switch (enable_fmri_rec(buf, temp)) { 1089*0Sstevel@tonic-gate case 0: 1090*0Sstevel@tonic-gate break; 1091*0Sstevel@tonic-gate 1092*0Sstevel@tonic-gate case EINVAL: 1093*0Sstevel@tonic-gate uu_warn(gettext("Restarter FMRI for \"%s\" is " 1094*0Sstevel@tonic-gate "invalid.\n"), fmri); 1095*0Sstevel@tonic-gate break; 1096*0Sstevel@tonic-gate 1097*0Sstevel@tonic-gate case E2BIG: 1098*0Sstevel@tonic-gate uu_warn(gettext("Restarter FMRI for \"%s\" identifies " 1099*0Sstevel@tonic-gate "a service with multiple instances.\n"), fmri); 1100*0Sstevel@tonic-gate break; 1101*0Sstevel@tonic-gate 1102*0Sstevel@tonic-gate case ELOOP: 1103*0Sstevel@tonic-gate ret = ELOOP; 1104*0Sstevel@tonic-gate goto out; 1105*0Sstevel@tonic-gate 1106*0Sstevel@tonic-gate default: 1107*0Sstevel@tonic-gate assert(0); 1108*0Sstevel@tonic-gate abort(); 1109*0Sstevel@tonic-gate } 1110*0Sstevel@tonic-gate } else if (sz < 0) { 1111*0Sstevel@tonic-gate switch (-sz) { 1112*0Sstevel@tonic-gate case ENOENT: 1113*0Sstevel@tonic-gate break; 1114*0Sstevel@tonic-gate 1115*0Sstevel@tonic-gate case E2BIG: 1116*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s/%s\" " 1117*0Sstevel@tonic-gate "property is not single-valued).\n"), fmri, 1118*0Sstevel@tonic-gate SCF_PG_GENERAL, SCF_PROPERTY_RESTARTER); 1119*0Sstevel@tonic-gate ret = 0; 1120*0Sstevel@tonic-gate goto out; 1121*0Sstevel@tonic-gate 1122*0Sstevel@tonic-gate case EINVAL: 1123*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s/%s\" " 1124*0Sstevel@tonic-gate "property is not of astring type).\n"), fmri, 1125*0Sstevel@tonic-gate SCF_PG_GENERAL, SCF_PROPERTY_RESTARTER); 1126*0Sstevel@tonic-gate ret = 0; 1127*0Sstevel@tonic-gate goto out; 1128*0Sstevel@tonic-gate 1129*0Sstevel@tonic-gate default: 1130*0Sstevel@tonic-gate assert(0); 1131*0Sstevel@tonic-gate abort(); 1132*0Sstevel@tonic-gate } 1133*0Sstevel@tonic-gate } 1134*0Sstevel@tonic-gate 1135*0Sstevel@tonic-gate if (scf_iter_instance_pgs_typed_composed(pg_iter, inst, snap, 1136*0Sstevel@tonic-gate SCF_GROUP_DEPENDENCY) == -1) 1137*0Sstevel@tonic-gate scfdie(); 1138*0Sstevel@tonic-gate 1139*0Sstevel@tonic-gate while (scf_iter_next_pg(pg_iter, pg) > 0) { 1140*0Sstevel@tonic-gate len = scf_pg_get_name(pg, pgname, name_sz); 1141*0Sstevel@tonic-gate if (len < 0) 1142*0Sstevel@tonic-gate scfdie(); 1143*0Sstevel@tonic-gate assert(len < name_sz); 1144*0Sstevel@tonic-gate 1145*0Sstevel@tonic-gate if (dep_get_astring(fmri, pgname, pg, SCF_PROPERTY_TYPE, prop, 1146*0Sstevel@tonic-gate v, buf, max_scf_fmri_sz) < 0) 1147*0Sstevel@tonic-gate continue; 1148*0Sstevel@tonic-gate 1149*0Sstevel@tonic-gate if (strcmp(buf, "service") != 0) 1150*0Sstevel@tonic-gate continue; 1151*0Sstevel@tonic-gate 1152*0Sstevel@tonic-gate if (dep_get_astring(fmri, pgname, pg, SCF_PROPERTY_GROUPING, 1153*0Sstevel@tonic-gate prop, v, buf, max_scf_fmri_sz) < 0) 1154*0Sstevel@tonic-gate continue; 1155*0Sstevel@tonic-gate 1156*0Sstevel@tonic-gate if (strcmp(buf, SCF_DEP_EXCLUDE_ALL) == 0 || 1157*0Sstevel@tonic-gate strcmp(buf, SCF_DEP_OPTIONAL_ALL) == 0) 1158*0Sstevel@tonic-gate continue; 1159*0Sstevel@tonic-gate 1160*0Sstevel@tonic-gate if (strcmp(buf, SCF_DEP_REQUIRE_ALL) != 0 && 1161*0Sstevel@tonic-gate strcmp(buf, SCF_DEP_REQUIRE_ANY) != 0) { 1162*0Sstevel@tonic-gate uu_warn(gettext("Dependency \"%s\" of \"%s\" has " 1163*0Sstevel@tonic-gate "unknown type \"%s\".\n"), pgname, fmri, buf); 1164*0Sstevel@tonic-gate continue; 1165*0Sstevel@tonic-gate } 1166*0Sstevel@tonic-gate 1167*0Sstevel@tonic-gate if (scf_pg_get_property(pg, SCF_PROPERTY_ENTITIES, prop) == 1168*0Sstevel@tonic-gate -1) { 1169*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1170*0Sstevel@tonic-gate scfdie(); 1171*0Sstevel@tonic-gate 1172*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (\"%s\" " 1173*0Sstevel@tonic-gate "dependency lacks \"%s\" property.)\n"), fmri, 1174*0Sstevel@tonic-gate pgname, SCF_PROPERTY_ENTITIES); 1175*0Sstevel@tonic-gate continue; 1176*0Sstevel@tonic-gate } 1177*0Sstevel@tonic-gate 1178*0Sstevel@tonic-gate if (scf_property_type(prop, &ty) != SCF_SUCCESS) 1179*0Sstevel@tonic-gate scfdie(); 1180*0Sstevel@tonic-gate 1181*0Sstevel@tonic-gate if (ty != SCF_TYPE_FMRI) { 1182*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" is misconfigured (property " 1183*0Sstevel@tonic-gate "\"%s/%s\" is not of fmri type).\n"), fmri, pgname, 1184*0Sstevel@tonic-gate SCF_PROPERTY_ENTITIES); 1185*0Sstevel@tonic-gate continue; 1186*0Sstevel@tonic-gate } 1187*0Sstevel@tonic-gate 1188*0Sstevel@tonic-gate if (scf_iter_property_values(val_iter, prop) == -1) 1189*0Sstevel@tonic-gate scfdie(); 1190*0Sstevel@tonic-gate 1191*0Sstevel@tonic-gate if (strcmp(buf, SCF_DEP_REQUIRE_ANY) == 0) { 1192*0Sstevel@tonic-gate if (multiple_instances(val_iter, v, buf)) { 1193*0Sstevel@tonic-gate (void) printf(gettext("%s requires one of:\n"), 1194*0Sstevel@tonic-gate fmri); 1195*0Sstevel@tonic-gate 1196*0Sstevel@tonic-gate if (scf_iter_property_values(val_iter, prop) != 1197*0Sstevel@tonic-gate 0) 1198*0Sstevel@tonic-gate scfdie(); 1199*0Sstevel@tonic-gate 1200*0Sstevel@tonic-gate for (;;) { 1201*0Sstevel@tonic-gate int r; 1202*0Sstevel@tonic-gate 1203*0Sstevel@tonic-gate r = scf_iter_next_value(val_iter, v); 1204*0Sstevel@tonic-gate if (r == 0) 1205*0Sstevel@tonic-gate break; 1206*0Sstevel@tonic-gate if (r != 1) 1207*0Sstevel@tonic-gate scfdie(); 1208*0Sstevel@tonic-gate 1209*0Sstevel@tonic-gate if (scf_value_get_astring(v, buf, 1210*0Sstevel@tonic-gate max_scf_fmri_sz) < 0) 1211*0Sstevel@tonic-gate scfdie(); 1212*0Sstevel@tonic-gate 1213*0Sstevel@tonic-gate (void) fputs(" ", stdout); 1214*0Sstevel@tonic-gate (void) puts(buf); 1215*0Sstevel@tonic-gate } 1216*0Sstevel@tonic-gate 1217*0Sstevel@tonic-gate continue; 1218*0Sstevel@tonic-gate } 1219*0Sstevel@tonic-gate 1220*0Sstevel@tonic-gate /* 1221*0Sstevel@tonic-gate * Since there's only one instance, we can enable it. 1222*0Sstevel@tonic-gate * Reset val_iter and continue. 1223*0Sstevel@tonic-gate */ 1224*0Sstevel@tonic-gate if (scf_iter_property_values(val_iter, prop) != 0) 1225*0Sstevel@tonic-gate scfdie(); 1226*0Sstevel@tonic-gate } 1227*0Sstevel@tonic-gate 1228*0Sstevel@tonic-gate for (;;) { 1229*0Sstevel@tonic-gate ret = scf_iter_next_value(val_iter, v); 1230*0Sstevel@tonic-gate if (ret == 0) 1231*0Sstevel@tonic-gate break; 1232*0Sstevel@tonic-gate if (ret != 1) 1233*0Sstevel@tonic-gate scfdie(); 1234*0Sstevel@tonic-gate 1235*0Sstevel@tonic-gate if (scf_value_get_astring(v, buf, max_scf_fmri_sz) == 1236*0Sstevel@tonic-gate -1) 1237*0Sstevel@tonic-gate scfdie(); 1238*0Sstevel@tonic-gate 1239*0Sstevel@tonic-gate switch (enable_fmri_rec(buf, temp)) { 1240*0Sstevel@tonic-gate case 0: 1241*0Sstevel@tonic-gate break; 1242*0Sstevel@tonic-gate 1243*0Sstevel@tonic-gate case EINVAL: 1244*0Sstevel@tonic-gate uu_warn(gettext("\"%s\" dependency of \"%s\" " 1245*0Sstevel@tonic-gate "has invalid FMRI \"%s\".\n"), pgname, 1246*0Sstevel@tonic-gate fmri, buf); 1247*0Sstevel@tonic-gate break; 1248*0Sstevel@tonic-gate 1249*0Sstevel@tonic-gate case E2BIG: 1250*0Sstevel@tonic-gate uu_warn(gettext("%s depends on %s, which has " 1251*0Sstevel@tonic-gate "multiple instances.\n"), fmri, buf); 1252*0Sstevel@tonic-gate break; 1253*0Sstevel@tonic-gate 1254*0Sstevel@tonic-gate case ELOOP: 1255*0Sstevel@tonic-gate ret = ELOOP; 1256*0Sstevel@tonic-gate goto out; 1257*0Sstevel@tonic-gate 1258*0Sstevel@tonic-gate default: 1259*0Sstevel@tonic-gate assert(0); 1260*0Sstevel@tonic-gate abort(); 1261*0Sstevel@tonic-gate } 1262*0Sstevel@tonic-gate } 1263*0Sstevel@tonic-gate } 1264*0Sstevel@tonic-gate 1265*0Sstevel@tonic-gate ret = 0; 1266*0Sstevel@tonic-gate 1267*0Sstevel@tonic-gate out: 1268*0Sstevel@tonic-gate he->active = B_FALSE; 1269*0Sstevel@tonic-gate 1270*0Sstevel@tonic-gate free(buf); 1271*0Sstevel@tonic-gate free(pgname); 1272*0Sstevel@tonic-gate 1273*0Sstevel@tonic-gate (void) scf_value_destroy(v); 1274*0Sstevel@tonic-gate scf_property_destroy(prop); 1275*0Sstevel@tonic-gate scf_pg_destroy(pg); 1276*0Sstevel@tonic-gate scf_snapshot_destroy(snap); 1277*0Sstevel@tonic-gate scf_iter_destroy(pg_iter); 1278*0Sstevel@tonic-gate scf_iter_destroy(val_iter); 1279*0Sstevel@tonic-gate 1280*0Sstevel@tonic-gate return (ret); 1281*0Sstevel@tonic-gate } 1282*0Sstevel@tonic-gate 1283*0Sstevel@tonic-gate /* 1284*0Sstevel@tonic-gate * fmri here is only used for verbose messages. 1285*0Sstevel@tonic-gate */ 1286*0Sstevel@tonic-gate static void 1287*0Sstevel@tonic-gate set_inst_action(const char *fmri, const scf_instance_t *inst, 1288*0Sstevel@tonic-gate const char *action) 1289*0Sstevel@tonic-gate { 1290*0Sstevel@tonic-gate scf_transaction_t *tx; 1291*0Sstevel@tonic-gate scf_transaction_entry_t *ent; 1292*0Sstevel@tonic-gate scf_propertygroup_t *pg; 1293*0Sstevel@tonic-gate scf_property_t *prop; 1294*0Sstevel@tonic-gate scf_value_t *v; 1295*0Sstevel@tonic-gate int ret; 1296*0Sstevel@tonic-gate int64_t t; 1297*0Sstevel@tonic-gate hrtime_t timestamp; 1298*0Sstevel@tonic-gate 1299*0Sstevel@tonic-gate const char * const scf_pg_restarter_actions = SCF_PG_RESTARTER_ACTIONS; 1300*0Sstevel@tonic-gate 1301*0Sstevel@tonic-gate if ((pg = scf_pg_create(h)) == NULL || 1302*0Sstevel@tonic-gate (prop = scf_property_create(h)) == NULL || 1303*0Sstevel@tonic-gate (v = scf_value_create(h)) == NULL || 1304*0Sstevel@tonic-gate (tx = scf_transaction_create(h)) == NULL || 1305*0Sstevel@tonic-gate (ent = scf_entry_create(h)) == NULL) 1306*0Sstevel@tonic-gate scfdie(); 1307*0Sstevel@tonic-gate 1308*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, scf_pg_restarter_actions, pg) == -1) { 1309*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1310*0Sstevel@tonic-gate scfdie(); 1311*0Sstevel@tonic-gate 1312*0Sstevel@tonic-gate /* Try creating the restarter_actions property group. */ 1313*0Sstevel@tonic-gate if (scf_instance_add_pg(inst, scf_pg_restarter_actions, 1314*0Sstevel@tonic-gate SCF_PG_RESTARTER_ACTIONS_TYPE, 1315*0Sstevel@tonic-gate SCF_PG_RESTARTER_ACTIONS_FLAGS, pg) == -1) { 1316*0Sstevel@tonic-gate switch (scf_error()) { 1317*0Sstevel@tonic-gate case SCF_ERROR_EXISTS: 1318*0Sstevel@tonic-gate /* Someone must have added it. */ 1319*0Sstevel@tonic-gate break; 1320*0Sstevel@tonic-gate 1321*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 1322*0Sstevel@tonic-gate if (!verbose) 1323*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1324*0Sstevel@tonic-gate else 1325*0Sstevel@tonic-gate uu_warn(emsg_create_pg_perm_denied, 1326*0Sstevel@tonic-gate fmri, scf_pg_restarter_actions); 1327*0Sstevel@tonic-gate goto out; 1328*0Sstevel@tonic-gate 1329*0Sstevel@tonic-gate default: 1330*0Sstevel@tonic-gate scfdie(); 1331*0Sstevel@tonic-gate } 1332*0Sstevel@tonic-gate } 1333*0Sstevel@tonic-gate } 1334*0Sstevel@tonic-gate 1335*0Sstevel@tonic-gate /* 1336*0Sstevel@tonic-gate * If we lose the transaction race and need to retry, there are 2 1337*0Sstevel@tonic-gate * potential other winners: 1338*0Sstevel@tonic-gate * - another process setting actions 1339*0Sstevel@tonic-gate * - the restarter marking the action complete 1340*0Sstevel@tonic-gate * Therefore, re-read the property every time through the loop before 1341*0Sstevel@tonic-gate * making any decisions based on their values. 1342*0Sstevel@tonic-gate */ 1343*0Sstevel@tonic-gate do { 1344*0Sstevel@tonic-gate timestamp = gethrtime(); 1345*0Sstevel@tonic-gate 1346*0Sstevel@tonic-gate if (scf_transaction_start(tx, pg) == -1) { 1347*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_PERMISSION_DENIED) 1348*0Sstevel@tonic-gate scfdie(); 1349*0Sstevel@tonic-gate 1350*0Sstevel@tonic-gate if (!verbose) 1351*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1352*0Sstevel@tonic-gate else 1353*0Sstevel@tonic-gate uu_warn(emsg_pg_perm_denied, fmri, 1354*0Sstevel@tonic-gate scf_pg_restarter_actions); 1355*0Sstevel@tonic-gate goto out; 1356*0Sstevel@tonic-gate } 1357*0Sstevel@tonic-gate 1358*0Sstevel@tonic-gate if (scf_pg_get_property(pg, action, prop) == -1) { 1359*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1360*0Sstevel@tonic-gate scfdie(); 1361*0Sstevel@tonic-gate if (scf_transaction_property_new(tx, ent, 1362*0Sstevel@tonic-gate action, SCF_TYPE_INTEGER) == -1) 1363*0Sstevel@tonic-gate scfdie(); 1364*0Sstevel@tonic-gate goto action_set; 1365*0Sstevel@tonic-gate } else { 1366*0Sstevel@tonic-gate if (scf_transaction_property_change_type(tx, ent, 1367*0Sstevel@tonic-gate action, SCF_TYPE_INTEGER) == -1) 1368*0Sstevel@tonic-gate scfdie(); 1369*0Sstevel@tonic-gate } 1370*0Sstevel@tonic-gate 1371*0Sstevel@tonic-gate if (scf_property_get_value(prop, v) == -1) { 1372*0Sstevel@tonic-gate switch (scf_error()) { 1373*0Sstevel@tonic-gate case SCF_ERROR_CONSTRAINT_VIOLATED: 1374*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 1375*0Sstevel@tonic-gate /* Misconfigured, so set anyway. */ 1376*0Sstevel@tonic-gate goto action_set; 1377*0Sstevel@tonic-gate 1378*0Sstevel@tonic-gate default: 1379*0Sstevel@tonic-gate scfdie(); 1380*0Sstevel@tonic-gate } 1381*0Sstevel@tonic-gate } else { 1382*0Sstevel@tonic-gate if (scf_value_get_integer(v, &t) == -1) { 1383*0Sstevel@tonic-gate assert(scf_error() == SCF_ERROR_TYPE_MISMATCH); 1384*0Sstevel@tonic-gate goto action_set; 1385*0Sstevel@tonic-gate } 1386*0Sstevel@tonic-gate if (t > timestamp) 1387*0Sstevel@tonic-gate break; 1388*0Sstevel@tonic-gate } 1389*0Sstevel@tonic-gate 1390*0Sstevel@tonic-gate action_set: 1391*0Sstevel@tonic-gate scf_value_set_integer(v, timestamp); 1392*0Sstevel@tonic-gate if (scf_entry_add_value(ent, v) == -1) 1393*0Sstevel@tonic-gate scfdie(); 1394*0Sstevel@tonic-gate 1395*0Sstevel@tonic-gate ret = scf_transaction_commit(tx); 1396*0Sstevel@tonic-gate if (ret == -1) { 1397*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_PERMISSION_DENIED) 1398*0Sstevel@tonic-gate scfdie(); 1399*0Sstevel@tonic-gate 1400*0Sstevel@tonic-gate if (!verbose) 1401*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1402*0Sstevel@tonic-gate else 1403*0Sstevel@tonic-gate uu_warn(emsg_prop_perm_denied, fmri, 1404*0Sstevel@tonic-gate scf_pg_restarter_actions, action); 1405*0Sstevel@tonic-gate scf_transaction_reset(tx); 1406*0Sstevel@tonic-gate goto out; 1407*0Sstevel@tonic-gate } 1408*0Sstevel@tonic-gate 1409*0Sstevel@tonic-gate scf_transaction_reset(tx); 1410*0Sstevel@tonic-gate 1411*0Sstevel@tonic-gate if (ret == 0) { 1412*0Sstevel@tonic-gate if (scf_pg_update(pg) == -1) 1413*0Sstevel@tonic-gate scfdie(); 1414*0Sstevel@tonic-gate } 1415*0Sstevel@tonic-gate } while (ret == 0); 1416*0Sstevel@tonic-gate 1417*0Sstevel@tonic-gate if (verbose) 1418*0Sstevel@tonic-gate (void) printf(gettext("Action %s set for %s.\n"), action, fmri); 1419*0Sstevel@tonic-gate 1420*0Sstevel@tonic-gate out: 1421*0Sstevel@tonic-gate scf_value_destroy(v); 1422*0Sstevel@tonic-gate scf_entry_destroy(ent); 1423*0Sstevel@tonic-gate scf_transaction_destroy(tx); 1424*0Sstevel@tonic-gate scf_property_destroy(prop); 1425*0Sstevel@tonic-gate scf_pg_destroy(pg); 1426*0Sstevel@tonic-gate } 1427*0Sstevel@tonic-gate 1428*0Sstevel@tonic-gate /* 1429*0Sstevel@tonic-gate * Get the state of inst. state should point to a buffer of 1430*0Sstevel@tonic-gate * MAX_SCF_STATE_STRING_SZ bytes. Returns 0 on success or -1 if 1431*0Sstevel@tonic-gate * no restarter property group 1432*0Sstevel@tonic-gate * no state property 1433*0Sstevel@tonic-gate * state property is misconfigured (wrong type, not single-valued) 1434*0Sstevel@tonic-gate * state value is too long 1435*0Sstevel@tonic-gate * In these cases, fmri is used to print a warning. 1436*0Sstevel@tonic-gate * 1437*0Sstevel@tonic-gate * If pgp is non-NULL, a successful call to inst_get_state will store 1438*0Sstevel@tonic-gate * the SCF_PG_RESTARTER property group in *pgp, and the caller will be 1439*0Sstevel@tonic-gate * responsible for calling scf_pg_destroy on the property group. 1440*0Sstevel@tonic-gate */ 1441*0Sstevel@tonic-gate int 1442*0Sstevel@tonic-gate inst_get_state(scf_instance_t *inst, char *state, const char *fmri, 1443*0Sstevel@tonic-gate scf_propertygroup_t **pgp) 1444*0Sstevel@tonic-gate { 1445*0Sstevel@tonic-gate scf_propertygroup_t *pg; 1446*0Sstevel@tonic-gate scf_property_t *prop; 1447*0Sstevel@tonic-gate scf_value_t *val; 1448*0Sstevel@tonic-gate int ret = -1; 1449*0Sstevel@tonic-gate ssize_t szret; 1450*0Sstevel@tonic-gate 1451*0Sstevel@tonic-gate if ((pg = scf_pg_create(h)) == NULL || 1452*0Sstevel@tonic-gate (prop = scf_property_create(h)) == NULL || 1453*0Sstevel@tonic-gate (val = scf_value_create(h)) == NULL) 1454*0Sstevel@tonic-gate scfdie(); 1455*0Sstevel@tonic-gate 1456*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, SCF_PG_RESTARTER, pg) != SCF_SUCCESS) { 1457*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1458*0Sstevel@tonic-gate scfdie(); 1459*0Sstevel@tonic-gate 1460*0Sstevel@tonic-gate uu_warn(gettext("%s is misconfigured (lacks \"%s\" property " 1461*0Sstevel@tonic-gate "group).\n"), fmri ? fmri : inst_get_fmri(inst), 1462*0Sstevel@tonic-gate SCF_PG_RESTARTER); 1463*0Sstevel@tonic-gate goto out; 1464*0Sstevel@tonic-gate } 1465*0Sstevel@tonic-gate 1466*0Sstevel@tonic-gate szret = get_astring_prop(pg, SCF_PROPERTY_STATE, prop, val, state, 1467*0Sstevel@tonic-gate MAX_SCF_STATE_STRING_SZ); 1468*0Sstevel@tonic-gate if (szret < 0) { 1469*0Sstevel@tonic-gate switch (-szret) { 1470*0Sstevel@tonic-gate case ENOENT: 1471*0Sstevel@tonic-gate uu_warn(gettext("%s is misconfigured (\"%s\" property " 1472*0Sstevel@tonic-gate "group lacks \"%s\" property).\n"), 1473*0Sstevel@tonic-gate fmri ? fmri : inst_get_fmri(inst), SCF_PG_RESTARTER, 1474*0Sstevel@tonic-gate SCF_PROPERTY_STATE); 1475*0Sstevel@tonic-gate goto out; 1476*0Sstevel@tonic-gate 1477*0Sstevel@tonic-gate case E2BIG: 1478*0Sstevel@tonic-gate uu_warn(gettext("%s is misconfigured (\"%s/%s\" " 1479*0Sstevel@tonic-gate "property is not single-valued).\n"), 1480*0Sstevel@tonic-gate fmri ? fmri : inst_get_fmri(inst), SCF_PG_RESTARTER, 1481*0Sstevel@tonic-gate SCF_PROPERTY_STATE); 1482*0Sstevel@tonic-gate goto out; 1483*0Sstevel@tonic-gate 1484*0Sstevel@tonic-gate case EINVAL: 1485*0Sstevel@tonic-gate uu_warn(gettext("%s is misconfigured (\"%s/%s\" " 1486*0Sstevel@tonic-gate "property is not of type astring).\n"), 1487*0Sstevel@tonic-gate fmri ? fmri : inst_get_fmri(inst), SCF_PG_RESTARTER, 1488*0Sstevel@tonic-gate SCF_PROPERTY_STATE); 1489*0Sstevel@tonic-gate goto out; 1490*0Sstevel@tonic-gate 1491*0Sstevel@tonic-gate default: 1492*0Sstevel@tonic-gate assert(0); 1493*0Sstevel@tonic-gate abort(); 1494*0Sstevel@tonic-gate } 1495*0Sstevel@tonic-gate } 1496*0Sstevel@tonic-gate if (szret >= MAX_SCF_STATE_STRING_SZ) { 1497*0Sstevel@tonic-gate uu_warn(gettext("%s is misconfigured (\"%s/%s\" property value " 1498*0Sstevel@tonic-gate "is too long).\n"), fmri ? fmri : inst_get_fmri(inst), 1499*0Sstevel@tonic-gate SCF_PG_RESTARTER, SCF_PROPERTY_STATE); 1500*0Sstevel@tonic-gate goto out; 1501*0Sstevel@tonic-gate } 1502*0Sstevel@tonic-gate 1503*0Sstevel@tonic-gate ret = 0; 1504*0Sstevel@tonic-gate if (pgp) 1505*0Sstevel@tonic-gate *pgp = pg; 1506*0Sstevel@tonic-gate 1507*0Sstevel@tonic-gate out: 1508*0Sstevel@tonic-gate (void) scf_value_destroy(val); 1509*0Sstevel@tonic-gate scf_property_destroy(prop); 1510*0Sstevel@tonic-gate if (ret || pgp == NULL) 1511*0Sstevel@tonic-gate scf_pg_destroy(pg); 1512*0Sstevel@tonic-gate return (ret); 1513*0Sstevel@tonic-gate } 1514*0Sstevel@tonic-gate 1515*0Sstevel@tonic-gate static void 1516*0Sstevel@tonic-gate set_astring_prop(const char *fmri, const char *pgname, const char *pgtype, 1517*0Sstevel@tonic-gate uint32_t pgflags, const char *propname, const char *str) 1518*0Sstevel@tonic-gate { 1519*0Sstevel@tonic-gate scf_instance_t *inst; 1520*0Sstevel@tonic-gate scf_propertygroup_t *pg; 1521*0Sstevel@tonic-gate scf_property_t *prop; 1522*0Sstevel@tonic-gate scf_value_t *val; 1523*0Sstevel@tonic-gate scf_transaction_t *tx; 1524*0Sstevel@tonic-gate scf_transaction_entry_t *txent; 1525*0Sstevel@tonic-gate int ret; 1526*0Sstevel@tonic-gate 1527*0Sstevel@tonic-gate inst = scf_instance_create(h); 1528*0Sstevel@tonic-gate if (inst == NULL) 1529*0Sstevel@tonic-gate scfdie(); 1530*0Sstevel@tonic-gate 1531*0Sstevel@tonic-gate if (get_inst(fmri, inst) != 0) 1532*0Sstevel@tonic-gate return; 1533*0Sstevel@tonic-gate 1534*0Sstevel@tonic-gate if ((pg = scf_pg_create(h)) == NULL || 1535*0Sstevel@tonic-gate (prop = scf_property_create(h)) == NULL || 1536*0Sstevel@tonic-gate (val = scf_value_create(h)) == NULL || 1537*0Sstevel@tonic-gate (tx = scf_transaction_create(h)) == NULL || 1538*0Sstevel@tonic-gate (txent = scf_entry_create(h)) == NULL) 1539*0Sstevel@tonic-gate scfdie(); 1540*0Sstevel@tonic-gate 1541*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, pgname, pg) != SCF_SUCCESS) { 1542*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1543*0Sstevel@tonic-gate scfdie(); 1544*0Sstevel@tonic-gate 1545*0Sstevel@tonic-gate if (scf_instance_add_pg(inst, pgname, pgtype, pgflags, pg) != 1546*0Sstevel@tonic-gate SCF_SUCCESS) { 1547*0Sstevel@tonic-gate switch (scf_error()) { 1548*0Sstevel@tonic-gate case SCF_ERROR_EXISTS: 1549*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, pgname, pg) != 1550*0Sstevel@tonic-gate SCF_SUCCESS) { 1551*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1552*0Sstevel@tonic-gate scfdie(); 1553*0Sstevel@tonic-gate 1554*0Sstevel@tonic-gate uu_warn(gettext("Repository write " 1555*0Sstevel@tonic-gate "contention.\n")); 1556*0Sstevel@tonic-gate goto out; 1557*0Sstevel@tonic-gate } 1558*0Sstevel@tonic-gate break; 1559*0Sstevel@tonic-gate 1560*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 1561*0Sstevel@tonic-gate if (!verbose) 1562*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1563*0Sstevel@tonic-gate else 1564*0Sstevel@tonic-gate uu_warn(emsg_create_pg_perm_denied, 1565*0Sstevel@tonic-gate fmri, pgname); 1566*0Sstevel@tonic-gate goto out; 1567*0Sstevel@tonic-gate 1568*0Sstevel@tonic-gate default: 1569*0Sstevel@tonic-gate scfdie(); 1570*0Sstevel@tonic-gate } 1571*0Sstevel@tonic-gate } 1572*0Sstevel@tonic-gate } 1573*0Sstevel@tonic-gate 1574*0Sstevel@tonic-gate do { 1575*0Sstevel@tonic-gate if (scf_transaction_start(tx, pg) != SCF_SUCCESS) { 1576*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_PERMISSION_DENIED) 1577*0Sstevel@tonic-gate scfdie(); 1578*0Sstevel@tonic-gate 1579*0Sstevel@tonic-gate if (!verbose) 1580*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1581*0Sstevel@tonic-gate else 1582*0Sstevel@tonic-gate uu_warn(emsg_pg_perm_denied, fmri, pgname); 1583*0Sstevel@tonic-gate goto out; 1584*0Sstevel@tonic-gate } 1585*0Sstevel@tonic-gate 1586*0Sstevel@tonic-gate if (scf_transaction_property_change_type(tx, txent, propname, 1587*0Sstevel@tonic-gate SCF_TYPE_ASTRING) != 0) { 1588*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_NOT_FOUND) 1589*0Sstevel@tonic-gate scfdie(); 1590*0Sstevel@tonic-gate 1591*0Sstevel@tonic-gate if (scf_transaction_property_new(tx, txent, propname, 1592*0Sstevel@tonic-gate SCF_TYPE_ASTRING) != 0) 1593*0Sstevel@tonic-gate scfdie(); 1594*0Sstevel@tonic-gate } 1595*0Sstevel@tonic-gate 1596*0Sstevel@tonic-gate if (scf_value_set_astring(val, str) != SCF_SUCCESS) 1597*0Sstevel@tonic-gate scfdie(); 1598*0Sstevel@tonic-gate 1599*0Sstevel@tonic-gate if (scf_entry_add_value(txent, val) != SCF_SUCCESS) 1600*0Sstevel@tonic-gate scfdie(); 1601*0Sstevel@tonic-gate 1602*0Sstevel@tonic-gate ret = scf_transaction_commit(tx); 1603*0Sstevel@tonic-gate if (ret == -1) { 1604*0Sstevel@tonic-gate if (scf_error() != SCF_ERROR_PERMISSION_DENIED) 1605*0Sstevel@tonic-gate scfdie(); 1606*0Sstevel@tonic-gate 1607*0Sstevel@tonic-gate if (!verbose) 1608*0Sstevel@tonic-gate uu_warn(emsg_permission_denied, fmri); 1609*0Sstevel@tonic-gate else 1610*0Sstevel@tonic-gate uu_warn(emsg_prop_perm_denied, fmri, pgname, 1611*0Sstevel@tonic-gate propname); 1612*0Sstevel@tonic-gate goto out; 1613*0Sstevel@tonic-gate } 1614*0Sstevel@tonic-gate 1615*0Sstevel@tonic-gate if (ret == 0) { 1616*0Sstevel@tonic-gate scf_transaction_reset(tx); 1617*0Sstevel@tonic-gate 1618*0Sstevel@tonic-gate if (scf_pg_update(pg) != SCF_SUCCESS) 1619*0Sstevel@tonic-gate scfdie(); 1620*0Sstevel@tonic-gate } 1621*0Sstevel@tonic-gate } while (ret == 0); 1622*0Sstevel@tonic-gate 1623*0Sstevel@tonic-gate out: 1624*0Sstevel@tonic-gate scf_transaction_destroy(tx); 1625*0Sstevel@tonic-gate scf_entry_destroy(txent); 1626*0Sstevel@tonic-gate scf_value_destroy(val); 1627*0Sstevel@tonic-gate scf_property_destroy(prop); 1628*0Sstevel@tonic-gate scf_pg_destroy(pg); 1629*0Sstevel@tonic-gate scf_instance_destroy(inst); 1630*0Sstevel@tonic-gate } 1631*0Sstevel@tonic-gate 1632*0Sstevel@tonic-gate 1633*0Sstevel@tonic-gate /* 1634*0Sstevel@tonic-gate * Flags to control enable and disable actions. 1635*0Sstevel@tonic-gate */ 1636*0Sstevel@tonic-gate #define SET_ENABLED 0x1 1637*0Sstevel@tonic-gate #define SET_TEMPORARY 0x2 1638*0Sstevel@tonic-gate #define SET_RECURSIVE 0x4 1639*0Sstevel@tonic-gate 1640*0Sstevel@tonic-gate static int 1641*0Sstevel@tonic-gate set_fmri_enabled(void *data, scf_walkinfo_t *wip) 1642*0Sstevel@tonic-gate { 1643*0Sstevel@tonic-gate int flags = (int)data; 1644*0Sstevel@tonic-gate 1645*0Sstevel@tonic-gate assert(wip->inst != NULL); 1646*0Sstevel@tonic-gate assert(wip->pg == NULL); 1647*0Sstevel@tonic-gate 1648*0Sstevel@tonic-gate if (flags & SET_RECURSIVE) { 1649*0Sstevel@tonic-gate char *fmri_buf = malloc(max_scf_fmri_sz); 1650*0Sstevel@tonic-gate if (fmri_buf == NULL) 1651*0Sstevel@tonic-gate uu_die(emsg_nomem); 1652*0Sstevel@tonic-gate 1653*0Sstevel@tonic-gate visited = calloc(HT_BUCKETS, sizeof (*visited)); 1654*0Sstevel@tonic-gate if (visited == NULL) 1655*0Sstevel@tonic-gate uu_die(emsg_nomem); 1656*0Sstevel@tonic-gate 1657*0Sstevel@tonic-gate /* scf_walk_fmri() guarantees that fmri isn't too long */ 1658*0Sstevel@tonic-gate assert(strlen(wip->fmri) <= max_scf_fmri_sz); 1659*0Sstevel@tonic-gate (void) strlcpy(fmri_buf, wip->fmri, max_scf_fmri_sz); 1660*0Sstevel@tonic-gate 1661*0Sstevel@tonic-gate switch (enable_fmri_rec(fmri_buf, (flags & SET_TEMPORARY))) { 1662*0Sstevel@tonic-gate case E2BIG: 1663*0Sstevel@tonic-gate uu_warn(gettext("operation on service %s is ambiguous; " 1664*0Sstevel@tonic-gate "instance specification needed.\n"), fmri_buf); 1665*0Sstevel@tonic-gate break; 1666*0Sstevel@tonic-gate 1667*0Sstevel@tonic-gate case ELOOP: 1668*0Sstevel@tonic-gate uu_warn(gettext("%s: Dependency cycle detected.\n"), 1669*0Sstevel@tonic-gate fmri_buf); 1670*0Sstevel@tonic-gate } 1671*0Sstevel@tonic-gate 1672*0Sstevel@tonic-gate free(visited); 1673*0Sstevel@tonic-gate free(fmri_buf); 1674*0Sstevel@tonic-gate 1675*0Sstevel@tonic-gate } else { 1676*0Sstevel@tonic-gate set_inst_enabled(wip->fmri, wip->inst, 1677*0Sstevel@tonic-gate (flags & SET_TEMPORARY) != 0, (flags & SET_ENABLED) != 0); 1678*0Sstevel@tonic-gate } 1679*0Sstevel@tonic-gate 1680*0Sstevel@tonic-gate return (0); 1681*0Sstevel@tonic-gate } 1682*0Sstevel@tonic-gate 1683*0Sstevel@tonic-gate /* ARGSUSED */ 1684*0Sstevel@tonic-gate static int 1685*0Sstevel@tonic-gate wait_fmri_enabled(void *data, scf_walkinfo_t *wip) 1686*0Sstevel@tonic-gate { 1687*0Sstevel@tonic-gate scf_propertygroup_t *pg = NULL; 1688*0Sstevel@tonic-gate char state[MAX_SCF_STATE_STRING_SZ]; 1689*0Sstevel@tonic-gate 1690*0Sstevel@tonic-gate assert(wip->inst != NULL); 1691*0Sstevel@tonic-gate assert(wip->pg == NULL); 1692*0Sstevel@tonic-gate 1693*0Sstevel@tonic-gate do { 1694*0Sstevel@tonic-gate if (pg) 1695*0Sstevel@tonic-gate scf_pg_destroy(pg); 1696*0Sstevel@tonic-gate if (inst_get_state(wip->inst, state, wip->fmri, &pg) != 0) { 1697*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1698*0Sstevel@tonic-gate return (0); 1699*0Sstevel@tonic-gate } 1700*0Sstevel@tonic-gate 1701*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_ONLINE) == 0 || 1702*0Sstevel@tonic-gate strcmp(state, SCF_STATE_STRING_DEGRADED) == 0) { 1703*0Sstevel@tonic-gate /* 1704*0Sstevel@tonic-gate * We're done. 1705*0Sstevel@tonic-gate */ 1706*0Sstevel@tonic-gate goto out; 1707*0Sstevel@tonic-gate } 1708*0Sstevel@tonic-gate 1709*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_MAINT) == 0) { 1710*0Sstevel@tonic-gate /* 1711*0Sstevel@tonic-gate * The service is ill. 1712*0Sstevel@tonic-gate */ 1713*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" is in maintenance" 1714*0Sstevel@tonic-gate " state.\n"), wip->fmri); 1715*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1716*0Sstevel@tonic-gate goto out; 1717*0Sstevel@tonic-gate } 1718*0Sstevel@tonic-gate 1719*0Sstevel@tonic-gate if (!is_enabled(wip->inst)) { 1720*0Sstevel@tonic-gate /* 1721*0Sstevel@tonic-gate * Someone stepped in and disabled the service. 1722*0Sstevel@tonic-gate */ 1723*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" has been disabled" 1724*0Sstevel@tonic-gate " by another entity.\n"), wip->fmri); 1725*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1726*0Sstevel@tonic-gate goto out; 1727*0Sstevel@tonic-gate } 1728*0Sstevel@tonic-gate 1729*0Sstevel@tonic-gate if (!has_potential(wip->inst, B_FALSE)) { 1730*0Sstevel@tonic-gate /* 1731*0Sstevel@tonic-gate * Our dependencies aren't met. We'll never 1732*0Sstevel@tonic-gate * amount to anything. 1733*0Sstevel@tonic-gate */ 1734*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" has unsatisfied" 1735*0Sstevel@tonic-gate " dependencies.\n"), wip->fmri); 1736*0Sstevel@tonic-gate /* 1737*0Sstevel@tonic-gate * EXIT_SVC_FAILURE takes precedence over 1738*0Sstevel@tonic-gate * EXIT_DEP_FAILURE 1739*0Sstevel@tonic-gate */ 1740*0Sstevel@tonic-gate if (exit_status == 0) 1741*0Sstevel@tonic-gate exit_status = EXIT_DEP_FAILURE; 1742*0Sstevel@tonic-gate goto out; 1743*0Sstevel@tonic-gate } 1744*0Sstevel@tonic-gate } while (_scf_pg_wait(pg, WAIT_INTERVAL) >= 0); 1745*0Sstevel@tonic-gate scfdie(); 1746*0Sstevel@tonic-gate /* NOTREACHED */ 1747*0Sstevel@tonic-gate 1748*0Sstevel@tonic-gate out: 1749*0Sstevel@tonic-gate scf_pg_destroy(pg); 1750*0Sstevel@tonic-gate return (0); 1751*0Sstevel@tonic-gate } 1752*0Sstevel@tonic-gate 1753*0Sstevel@tonic-gate /* ARGSUSED */ 1754*0Sstevel@tonic-gate static int 1755*0Sstevel@tonic-gate wait_fmri_disabled(void *data, scf_walkinfo_t *wip) 1756*0Sstevel@tonic-gate { 1757*0Sstevel@tonic-gate scf_propertygroup_t *pg = NULL; 1758*0Sstevel@tonic-gate char state[MAX_SCF_STATE_STRING_SZ]; 1759*0Sstevel@tonic-gate 1760*0Sstevel@tonic-gate assert(wip->inst != NULL); 1761*0Sstevel@tonic-gate assert(wip->pg == NULL); 1762*0Sstevel@tonic-gate 1763*0Sstevel@tonic-gate do { 1764*0Sstevel@tonic-gate if (pg) 1765*0Sstevel@tonic-gate scf_pg_destroy(pg); 1766*0Sstevel@tonic-gate if (inst_get_state(wip->inst, state, wip->fmri, &pg) != 0) { 1767*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1768*0Sstevel@tonic-gate return (0); 1769*0Sstevel@tonic-gate } 1770*0Sstevel@tonic-gate 1771*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_DISABLED) == 0) { 1772*0Sstevel@tonic-gate /* 1773*0Sstevel@tonic-gate * We're done. 1774*0Sstevel@tonic-gate */ 1775*0Sstevel@tonic-gate goto out; 1776*0Sstevel@tonic-gate } 1777*0Sstevel@tonic-gate 1778*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_MAINT) == 0) { 1779*0Sstevel@tonic-gate /* 1780*0Sstevel@tonic-gate * The service is ill. 1781*0Sstevel@tonic-gate */ 1782*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" is in maintenance" 1783*0Sstevel@tonic-gate " state.\n"), wip->fmri); 1784*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1785*0Sstevel@tonic-gate goto out; 1786*0Sstevel@tonic-gate } 1787*0Sstevel@tonic-gate 1788*0Sstevel@tonic-gate if (is_enabled(wip->inst)) { 1789*0Sstevel@tonic-gate /* 1790*0Sstevel@tonic-gate * Someone stepped in and enabled the service. 1791*0Sstevel@tonic-gate */ 1792*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" has been enabled" 1793*0Sstevel@tonic-gate " by another entity.\n"), wip->fmri); 1794*0Sstevel@tonic-gate exit_status = EXIT_SVC_FAILURE; 1795*0Sstevel@tonic-gate goto out; 1796*0Sstevel@tonic-gate } 1797*0Sstevel@tonic-gate 1798*0Sstevel@tonic-gate if (!has_potential(wip->inst, B_TRUE)) { 1799*0Sstevel@tonic-gate /* 1800*0Sstevel@tonic-gate * Our restarter is hopeless. 1801*0Sstevel@tonic-gate */ 1802*0Sstevel@tonic-gate uu_warn(gettext("Restarter for instance \"%s\" is" 1803*0Sstevel@tonic-gate " unavailable.\n"), wip->fmri); 1804*0Sstevel@tonic-gate /* 1805*0Sstevel@tonic-gate * EXIT_SVC_FAILURE takes precedence over 1806*0Sstevel@tonic-gate * EXIT_DEP_FAILURE 1807*0Sstevel@tonic-gate */ 1808*0Sstevel@tonic-gate if (exit_status == 0) 1809*0Sstevel@tonic-gate exit_status = EXIT_DEP_FAILURE; 1810*0Sstevel@tonic-gate goto out; 1811*0Sstevel@tonic-gate } 1812*0Sstevel@tonic-gate 1813*0Sstevel@tonic-gate } while (_scf_pg_wait(pg, WAIT_INTERVAL) >= 0); 1814*0Sstevel@tonic-gate scfdie(); 1815*0Sstevel@tonic-gate /* NOTREACHED */ 1816*0Sstevel@tonic-gate 1817*0Sstevel@tonic-gate out: 1818*0Sstevel@tonic-gate scf_pg_destroy(pg); 1819*0Sstevel@tonic-gate return (0); 1820*0Sstevel@tonic-gate } 1821*0Sstevel@tonic-gate 1822*0Sstevel@tonic-gate /* ARGSUSED */ 1823*0Sstevel@tonic-gate static int 1824*0Sstevel@tonic-gate clear_instance(void *data, scf_walkinfo_t *wip) 1825*0Sstevel@tonic-gate { 1826*0Sstevel@tonic-gate char state[MAX_SCF_STATE_STRING_SZ]; 1827*0Sstevel@tonic-gate 1828*0Sstevel@tonic-gate assert(wip->inst != NULL); 1829*0Sstevel@tonic-gate assert(wip->pg == NULL); 1830*0Sstevel@tonic-gate 1831*0Sstevel@tonic-gate if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0) 1832*0Sstevel@tonic-gate return (0); 1833*0Sstevel@tonic-gate 1834*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_MAINT) == 0) { 1835*0Sstevel@tonic-gate set_inst_action(wip->fmri, wip->inst, SCF_PROPERTY_MAINT_OFF); 1836*0Sstevel@tonic-gate } else if (strcmp(state, SCF_STATE_STRING_DEGRADED) == 1837*0Sstevel@tonic-gate 0) { 1838*0Sstevel@tonic-gate set_inst_action(wip->fmri, wip->inst, SCF_PROPERTY_RESTORE); 1839*0Sstevel@tonic-gate } else { 1840*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" is not in a " 1841*0Sstevel@tonic-gate "maintenance or degraded state.\n"), wip->fmri); 1842*0Sstevel@tonic-gate 1843*0Sstevel@tonic-gate exit_status = 1; 1844*0Sstevel@tonic-gate } 1845*0Sstevel@tonic-gate 1846*0Sstevel@tonic-gate return (0); 1847*0Sstevel@tonic-gate } 1848*0Sstevel@tonic-gate 1849*0Sstevel@tonic-gate static int 1850*0Sstevel@tonic-gate set_fmri_action(void *action, scf_walkinfo_t *wip) 1851*0Sstevel@tonic-gate { 1852*0Sstevel@tonic-gate assert(wip->inst != NULL && wip->pg == NULL); 1853*0Sstevel@tonic-gate 1854*0Sstevel@tonic-gate set_inst_action(wip->fmri, wip->inst, action); 1855*0Sstevel@tonic-gate 1856*0Sstevel@tonic-gate return (0); 1857*0Sstevel@tonic-gate } 1858*0Sstevel@tonic-gate 1859*0Sstevel@tonic-gate /* 1860*0Sstevel@tonic-gate * Flags to control 'mark' action. 1861*0Sstevel@tonic-gate */ 1862*0Sstevel@tonic-gate #define MARK_IMMEDIATE 0x1 1863*0Sstevel@tonic-gate #define MARK_TEMPORARY 0x2 1864*0Sstevel@tonic-gate 1865*0Sstevel@tonic-gate static int 1866*0Sstevel@tonic-gate force_degraded(void *data, scf_walkinfo_t *wip) 1867*0Sstevel@tonic-gate { 1868*0Sstevel@tonic-gate int flags = (int)data; 1869*0Sstevel@tonic-gate char state[MAX_SCF_STATE_STRING_SZ]; 1870*0Sstevel@tonic-gate 1871*0Sstevel@tonic-gate if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0) { 1872*0Sstevel@tonic-gate exit_status = 1; 1873*0Sstevel@tonic-gate return (0); 1874*0Sstevel@tonic-gate } 1875*0Sstevel@tonic-gate 1876*0Sstevel@tonic-gate if (strcmp(state, SCF_STATE_STRING_ONLINE) != 0) { 1877*0Sstevel@tonic-gate uu_warn(gettext("Instance \"%s\" is not online.\n"), wip->fmri); 1878*0Sstevel@tonic-gate exit_status = 1; 1879*0Sstevel@tonic-gate return (0); 1880*0Sstevel@tonic-gate } 1881*0Sstevel@tonic-gate 1882*0Sstevel@tonic-gate set_inst_action(wip->fmri, wip->inst, (flags & MARK_IMMEDIATE) ? 1883*0Sstevel@tonic-gate SCF_PROPERTY_DEGRADE_IMMEDIATE : SCF_PROPERTY_DEGRADED); 1884*0Sstevel@tonic-gate 1885*0Sstevel@tonic-gate return (0); 1886*0Sstevel@tonic-gate } 1887*0Sstevel@tonic-gate 1888*0Sstevel@tonic-gate static int 1889*0Sstevel@tonic-gate force_maintenance(void *data, scf_walkinfo_t *wip) 1890*0Sstevel@tonic-gate { 1891*0Sstevel@tonic-gate int flags = (int)data; 1892*0Sstevel@tonic-gate const char *prop; 1893*0Sstevel@tonic-gate 1894*0Sstevel@tonic-gate if (flags & MARK_IMMEDIATE) { 1895*0Sstevel@tonic-gate prop = (flags & MARK_TEMPORARY) ? 1896*0Sstevel@tonic-gate SCF_PROPERTY_MAINT_ON_IMMTEMP : 1897*0Sstevel@tonic-gate SCF_PROPERTY_MAINT_ON_IMMEDIATE; 1898*0Sstevel@tonic-gate } else { 1899*0Sstevel@tonic-gate prop = (flags & MARK_TEMPORARY) ? 1900*0Sstevel@tonic-gate SCF_PROPERTY_MAINT_ON_TEMPORARY : 1901*0Sstevel@tonic-gate SCF_PROPERTY_MAINT_ON; 1902*0Sstevel@tonic-gate } 1903*0Sstevel@tonic-gate 1904*0Sstevel@tonic-gate set_inst_action(wip->fmri, wip->inst, prop); 1905*0Sstevel@tonic-gate 1906*0Sstevel@tonic-gate return (0); 1907*0Sstevel@tonic-gate } 1908*0Sstevel@tonic-gate 1909*0Sstevel@tonic-gate static void 1910*0Sstevel@tonic-gate set_milestone(const char *fmri, boolean_t temporary) 1911*0Sstevel@tonic-gate { 1912*0Sstevel@tonic-gate scf_instance_t *inst; 1913*0Sstevel@tonic-gate scf_propertygroup_t *pg; 1914*0Sstevel@tonic-gate int r; 1915*0Sstevel@tonic-gate 1916*0Sstevel@tonic-gate if (temporary) { 1917*0Sstevel@tonic-gate set_astring_prop(SCF_SERVICE_STARTD, SCF_PG_OPTIONS_OVR, 1918*0Sstevel@tonic-gate SCF_PG_OPTIONS_OVR_TYPE, SCF_PG_OPTIONS_OVR_FLAGS, 1919*0Sstevel@tonic-gate SCF_PROPERTY_MILESTONE, fmri); 1920*0Sstevel@tonic-gate return; 1921*0Sstevel@tonic-gate } 1922*0Sstevel@tonic-gate 1923*0Sstevel@tonic-gate if ((inst = scf_instance_create(h)) == NULL || 1924*0Sstevel@tonic-gate (pg = scf_pg_create(h)) == NULL) 1925*0Sstevel@tonic-gate scfdie(); 1926*0Sstevel@tonic-gate 1927*0Sstevel@tonic-gate if (get_inst(SCF_SERVICE_STARTD, inst) != 0) { 1928*0Sstevel@tonic-gate scf_instance_destroy(inst); 1929*0Sstevel@tonic-gate return; 1930*0Sstevel@tonic-gate } 1931*0Sstevel@tonic-gate 1932*0Sstevel@tonic-gate /* 1933*0Sstevel@tonic-gate * Set the persistent milestone before deleting the override so we don't 1934*0Sstevel@tonic-gate * glitch. 1935*0Sstevel@tonic-gate */ 1936*0Sstevel@tonic-gate set_astring_prop(SCF_SERVICE_STARTD, SCF_PG_OPTIONS, 1937*0Sstevel@tonic-gate SCF_PG_OPTIONS_TYPE, SCF_PG_OPTIONS_FLAGS, SCF_PROPERTY_MILESTONE, 1938*0Sstevel@tonic-gate fmri); 1939*0Sstevel@tonic-gate 1940*0Sstevel@tonic-gate if (scf_instance_get_pg(inst, SCF_PG_OPTIONS_OVR, pg) == 0) { 1941*0Sstevel@tonic-gate r = delete_prop(pg, SCF_PROPERTY_MILESTONE); 1942*0Sstevel@tonic-gate switch (r) { 1943*0Sstevel@tonic-gate case 0: 1944*0Sstevel@tonic-gate break; 1945*0Sstevel@tonic-gate 1946*0Sstevel@tonic-gate case ECANCELED: 1947*0Sstevel@tonic-gate uu_warn(emsg_no_service, fmri); 1948*0Sstevel@tonic-gate exit_status = 1; 1949*0Sstevel@tonic-gate goto out; 1950*0Sstevel@tonic-gate 1951*0Sstevel@tonic-gate case EPERM: 1952*0Sstevel@tonic-gate uu_warn(gettext("Could not delete %s/%s property of " 1953*0Sstevel@tonic-gate "%s: permission denied.\n"), SCF_PG_OPTIONS_OVR, 1954*0Sstevel@tonic-gate SCF_PROPERTY_MILESTONE, SCF_SERVICE_STARTD); 1955*0Sstevel@tonic-gate exit_status = 1; 1956*0Sstevel@tonic-gate goto out; 1957*0Sstevel@tonic-gate 1958*0Sstevel@tonic-gate case EACCES: 1959*0Sstevel@tonic-gate uu_warn(gettext("Could not delete %s/%s property of " 1960*0Sstevel@tonic-gate "%s: access denied.\n"), SCF_PG_OPTIONS_OVR, 1961*0Sstevel@tonic-gate SCF_PROPERTY_MILESTONE, SCF_SERVICE_STARTD); 1962*0Sstevel@tonic-gate exit_status = 1; 1963*0Sstevel@tonic-gate goto out; 1964*0Sstevel@tonic-gate 1965*0Sstevel@tonic-gate case EROFS: 1966*0Sstevel@tonic-gate uu_warn(gettext("Could not delete %s/%s property of " 1967*0Sstevel@tonic-gate "%s: backend read-only.\n"), SCF_PG_OPTIONS_OVR, 1968*0Sstevel@tonic-gate SCF_PROPERTY_MILESTONE, SCF_SERVICE_STARTD); 1969*0Sstevel@tonic-gate exit_status = 1; 1970*0Sstevel@tonic-gate goto out; 1971*0Sstevel@tonic-gate 1972*0Sstevel@tonic-gate default: 1973*0Sstevel@tonic-gate bad_error("delete_prop", r); 1974*0Sstevel@tonic-gate } 1975*0Sstevel@tonic-gate } else { 1976*0Sstevel@tonic-gate switch (scf_error()) { 1977*0Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 1978*0Sstevel@tonic-gate break; 1979*0Sstevel@tonic-gate 1980*0Sstevel@tonic-gate case SCF_ERROR_DELETED: 1981*0Sstevel@tonic-gate uu_warn(emsg_no_service, fmri); 1982*0Sstevel@tonic-gate exit_status = 1; 1983*0Sstevel@tonic-gate goto out; 1984*0Sstevel@tonic-gate 1985*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 1986*0Sstevel@tonic-gate case SCF_ERROR_HANDLE_MISMATCH: 1987*0Sstevel@tonic-gate case SCF_ERROR_NOT_BOUND: 1988*0Sstevel@tonic-gate case SCF_ERROR_INVALID_ARGUMENT: 1989*0Sstevel@tonic-gate case SCF_ERROR_NOT_SET: 1990*0Sstevel@tonic-gate default: 1991*0Sstevel@tonic-gate scfdie(); 1992*0Sstevel@tonic-gate } 1993*0Sstevel@tonic-gate } 1994*0Sstevel@tonic-gate 1995*0Sstevel@tonic-gate out: 1996*0Sstevel@tonic-gate scf_pg_destroy(pg); 1997*0Sstevel@tonic-gate scf_instance_destroy(inst); 1998*0Sstevel@tonic-gate } 1999*0Sstevel@tonic-gate 2000*0Sstevel@tonic-gate static char const *milestones[] = { 2001*0Sstevel@tonic-gate SCF_MILESTONE_SINGLE_USER, 2002*0Sstevel@tonic-gate SCF_MILESTONE_MULTI_USER, 2003*0Sstevel@tonic-gate SCF_MILESTONE_MULTI_USER_SERVER, 2004*0Sstevel@tonic-gate NULL 2005*0Sstevel@tonic-gate }; 2006*0Sstevel@tonic-gate 2007*0Sstevel@tonic-gate static void 2008*0Sstevel@tonic-gate usage_milestone() 2009*0Sstevel@tonic-gate { 2010*0Sstevel@tonic-gate const char **ms; 2011*0Sstevel@tonic-gate 2012*0Sstevel@tonic-gate (void) fprintf(stderr, gettext( 2013*0Sstevel@tonic-gate "Usage: svcadm milestone [-d] <milestone>\n\n" 2014*0Sstevel@tonic-gate "\t-d\tmake the specified milestone the default for system boot\n\n" 2015*0Sstevel@tonic-gate "\tMilestones can be specified using an FMRI or abbreviation.\n" 2016*0Sstevel@tonic-gate "\tThe major milestones are as follows:\n\n" 2017*0Sstevel@tonic-gate "\tall\n" 2018*0Sstevel@tonic-gate "\tnone\n")); 2019*0Sstevel@tonic-gate 2020*0Sstevel@tonic-gate for (ms = milestones; *ms != NULL; ms++) 2021*0Sstevel@tonic-gate (void) fprintf(stderr, "\t%s\n", *ms); 2022*0Sstevel@tonic-gate 2023*0Sstevel@tonic-gate exit(UU_EXIT_USAGE); 2024*0Sstevel@tonic-gate } 2025*0Sstevel@tonic-gate 2026*0Sstevel@tonic-gate static const char * 2027*0Sstevel@tonic-gate validate_milestone(const char *milestone) 2028*0Sstevel@tonic-gate { 2029*0Sstevel@tonic-gate const char **ms; 2030*0Sstevel@tonic-gate const char *tmp; 2031*0Sstevel@tonic-gate size_t len; 2032*0Sstevel@tonic-gate 2033*0Sstevel@tonic-gate if (strcmp(milestone, "all") == 0) 2034*0Sstevel@tonic-gate return (milestone); 2035*0Sstevel@tonic-gate 2036*0Sstevel@tonic-gate if (strcmp(milestone, "none") == 0) 2037*0Sstevel@tonic-gate return (milestone); 2038*0Sstevel@tonic-gate 2039*0Sstevel@tonic-gate /* 2040*0Sstevel@tonic-gate * Determine if this is a full or partial milestone 2041*0Sstevel@tonic-gate */ 2042*0Sstevel@tonic-gate for (ms = milestones; *ms != NULL; ms++) { 2043*0Sstevel@tonic-gate if ((tmp = strstr(*ms, milestone)) != NULL) { 2044*0Sstevel@tonic-gate len = strlen(milestone); 2045*0Sstevel@tonic-gate 2046*0Sstevel@tonic-gate /* 2047*0Sstevel@tonic-gate * The beginning of the string must align with the start 2048*0Sstevel@tonic-gate * of a milestone fmri, or on the boundary between 2049*0Sstevel@tonic-gate * elements. The end of the string must align with the 2050*0Sstevel@tonic-gate * end of the milestone, or at the instance boundary. 2051*0Sstevel@tonic-gate */ 2052*0Sstevel@tonic-gate if ((tmp == *ms || tmp[-1] == '/') && 2053*0Sstevel@tonic-gate (tmp[len] == '\0' || tmp[len] == ':')) 2054*0Sstevel@tonic-gate return (*ms); 2055*0Sstevel@tonic-gate } 2056*0Sstevel@tonic-gate } 2057*0Sstevel@tonic-gate 2058*0Sstevel@tonic-gate (void) fprintf(stderr, 2059*0Sstevel@tonic-gate gettext("\"%s\" is not a valid major milestone.\n"), milestone); 2060*0Sstevel@tonic-gate 2061*0Sstevel@tonic-gate usage_milestone(); 2062*0Sstevel@tonic-gate /* NOTREACHED */ 2063*0Sstevel@tonic-gate } 2064*0Sstevel@tonic-gate 2065*0Sstevel@tonic-gate /*ARGSUSED*/ 2066*0Sstevel@tonic-gate static void 2067*0Sstevel@tonic-gate quiet(const char *fmt, ...) 2068*0Sstevel@tonic-gate { 2069*0Sstevel@tonic-gate /* Do nothing */ 2070*0Sstevel@tonic-gate } 2071*0Sstevel@tonic-gate 2072*0Sstevel@tonic-gate int 2073*0Sstevel@tonic-gate main(int argc, char *argv[]) 2074*0Sstevel@tonic-gate { 2075*0Sstevel@tonic-gate int o; 2076*0Sstevel@tonic-gate int err; 2077*0Sstevel@tonic-gate 2078*0Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 2079*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 2080*0Sstevel@tonic-gate 2081*0Sstevel@tonic-gate (void) uu_setpname(argv[0]); 2082*0Sstevel@tonic-gate 2083*0Sstevel@tonic-gate if (argc < 2) 2084*0Sstevel@tonic-gate usage(); 2085*0Sstevel@tonic-gate 2086*0Sstevel@tonic-gate max_scf_fmri_sz = scf_limit(SCF_LIMIT_MAX_FMRI_LENGTH); 2087*0Sstevel@tonic-gate if (max_scf_fmri_sz < 0) 2088*0Sstevel@tonic-gate scfdie(); 2089*0Sstevel@tonic-gate ++max_scf_fmri_sz; 2090*0Sstevel@tonic-gate 2091*0Sstevel@tonic-gate scratch_fmri = malloc(max_scf_fmri_sz); 2092*0Sstevel@tonic-gate if (scratch_fmri == NULL) 2093*0Sstevel@tonic-gate uu_die(emsg_nomem); 2094*0Sstevel@tonic-gate 2095*0Sstevel@tonic-gate h = scf_handle_create(SCF_VERSION); 2096*0Sstevel@tonic-gate if (h == NULL) 2097*0Sstevel@tonic-gate scfdie(); 2098*0Sstevel@tonic-gate 2099*0Sstevel@tonic-gate if (scf_handle_bind(h) == -1) 2100*0Sstevel@tonic-gate uu_die(gettext("Couldn't bind to svc.configd.\n")); 2101*0Sstevel@tonic-gate 2102*0Sstevel@tonic-gate while ((o = getopt(argc, argv, "v")) != -1) { 2103*0Sstevel@tonic-gate if (o == 'v') 2104*0Sstevel@tonic-gate verbose = 1; 2105*0Sstevel@tonic-gate else 2106*0Sstevel@tonic-gate usage(); 2107*0Sstevel@tonic-gate } 2108*0Sstevel@tonic-gate 2109*0Sstevel@tonic-gate if (optind >= argc) 2110*0Sstevel@tonic-gate usage(); 2111*0Sstevel@tonic-gate 2112*0Sstevel@tonic-gate emsg_permission_denied = gettext("%s: Permission denied.\n"); 2113*0Sstevel@tonic-gate emsg_nomem = gettext("Out of memory.\n"); 2114*0Sstevel@tonic-gate emsg_create_pg_perm_denied = gettext("%s: Couldn't create \"%s\" " 2115*0Sstevel@tonic-gate "property group (permission denied).\n"); 2116*0Sstevel@tonic-gate emsg_pg_perm_denied = gettext("%s: Couldn't modify \"%s\" property " 2117*0Sstevel@tonic-gate "group (permission denied).\n"); 2118*0Sstevel@tonic-gate emsg_prop_perm_denied = gettext("%s: Couldn't modify \"%s/%s\" " 2119*0Sstevel@tonic-gate "property (permission denied).\n"); 2120*0Sstevel@tonic-gate emsg_no_service = gettext("No such service \"%s\".\n"); 2121*0Sstevel@tonic-gate 2122*0Sstevel@tonic-gate if (strcmp(argv[optind], "enable") == 0) { 2123*0Sstevel@tonic-gate int flags = SET_ENABLED; 2124*0Sstevel@tonic-gate int wait = 0; 2125*0Sstevel@tonic-gate int error = 0; 2126*0Sstevel@tonic-gate 2127*0Sstevel@tonic-gate ++optind; 2128*0Sstevel@tonic-gate 2129*0Sstevel@tonic-gate while ((o = getopt(argc, argv, "rst")) != -1) { 2130*0Sstevel@tonic-gate if (o == 'r') 2131*0Sstevel@tonic-gate flags |= SET_RECURSIVE; 2132*0Sstevel@tonic-gate else if (o == 't') 2133*0Sstevel@tonic-gate flags |= SET_TEMPORARY; 2134*0Sstevel@tonic-gate else if (o == 's') 2135*0Sstevel@tonic-gate wait = 1; 2136*0Sstevel@tonic-gate else if (o == '?') 2137*0Sstevel@tonic-gate usage(); 2138*0Sstevel@tonic-gate else { 2139*0Sstevel@tonic-gate assert(0); 2140*0Sstevel@tonic-gate abort(); 2141*0Sstevel@tonic-gate } 2142*0Sstevel@tonic-gate } 2143*0Sstevel@tonic-gate argc -= optind; 2144*0Sstevel@tonic-gate argv += optind; 2145*0Sstevel@tonic-gate 2146*0Sstevel@tonic-gate if (argc <= 0) 2147*0Sstevel@tonic-gate usage(); 2148*0Sstevel@tonic-gate 2149*0Sstevel@tonic-gate /* 2150*0Sstevel@tonic-gate * We want to continue with -s processing if we had 2151*0Sstevel@tonic-gate * invalid options, but not if an enable failed. We 2152*0Sstevel@tonic-gate * squelch output the second time we walk fmris; we saw 2153*0Sstevel@tonic-gate * the errors the first time. 2154*0Sstevel@tonic-gate */ 2155*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc, argv, 0, set_fmri_enabled, 2156*0Sstevel@tonic-gate (void *)flags, &error, uu_warn)) != 0) { 2157*0Sstevel@tonic-gate 2158*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2159*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2160*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2161*0Sstevel@tonic-gate 2162*0Sstevel@tonic-gate } else if (wait && exit_status == 0 && 2163*0Sstevel@tonic-gate (err = scf_walk_fmri(h, argc, argv, 0, wait_fmri_enabled, 2164*0Sstevel@tonic-gate (void *)flags, &error, quiet)) != 0) { 2165*0Sstevel@tonic-gate 2166*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2167*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2168*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2169*0Sstevel@tonic-gate } 2170*0Sstevel@tonic-gate 2171*0Sstevel@tonic-gate if (error > 0) 2172*0Sstevel@tonic-gate exit_status = error; 2173*0Sstevel@tonic-gate 2174*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "disable") == 0) { 2175*0Sstevel@tonic-gate int flags = 0; 2176*0Sstevel@tonic-gate int wait = 0; 2177*0Sstevel@tonic-gate int error = 0; 2178*0Sstevel@tonic-gate 2179*0Sstevel@tonic-gate ++optind; 2180*0Sstevel@tonic-gate 2181*0Sstevel@tonic-gate while ((o = getopt(argc, argv, "st")) != -1) { 2182*0Sstevel@tonic-gate if (o == 't') 2183*0Sstevel@tonic-gate flags |= SET_TEMPORARY; 2184*0Sstevel@tonic-gate else if (o == 's') 2185*0Sstevel@tonic-gate wait = 1; 2186*0Sstevel@tonic-gate else if (o == '?') 2187*0Sstevel@tonic-gate usage(); 2188*0Sstevel@tonic-gate else { 2189*0Sstevel@tonic-gate assert(0); 2190*0Sstevel@tonic-gate abort(); 2191*0Sstevel@tonic-gate } 2192*0Sstevel@tonic-gate } 2193*0Sstevel@tonic-gate argc -= optind; 2194*0Sstevel@tonic-gate argv += optind; 2195*0Sstevel@tonic-gate 2196*0Sstevel@tonic-gate if (argc <= 0) 2197*0Sstevel@tonic-gate usage(); 2198*0Sstevel@tonic-gate 2199*0Sstevel@tonic-gate /* 2200*0Sstevel@tonic-gate * We want to continue with -s processing if we had 2201*0Sstevel@tonic-gate * invalid options, but not if a disable failed. We 2202*0Sstevel@tonic-gate * squelch output the second time we walk fmris; we saw 2203*0Sstevel@tonic-gate * the errors the first time. 2204*0Sstevel@tonic-gate */ 2205*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc, argv, 0, set_fmri_enabled, 2206*0Sstevel@tonic-gate (void *)flags, &exit_status, uu_warn)) != 0) { 2207*0Sstevel@tonic-gate 2208*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2209*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2210*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2211*0Sstevel@tonic-gate 2212*0Sstevel@tonic-gate } else if (wait && exit_status == 0 && 2213*0Sstevel@tonic-gate (err = scf_walk_fmri(h, argc, argv, 0, wait_fmri_disabled, 2214*0Sstevel@tonic-gate (void *)flags, &error, quiet)) != 0) { 2215*0Sstevel@tonic-gate 2216*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2217*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2218*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2219*0Sstevel@tonic-gate } 2220*0Sstevel@tonic-gate 2221*0Sstevel@tonic-gate if (error > 0) 2222*0Sstevel@tonic-gate exit_status = error; 2223*0Sstevel@tonic-gate 2224*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "restart") == 0) { 2225*0Sstevel@tonic-gate ++optind; 2226*0Sstevel@tonic-gate 2227*0Sstevel@tonic-gate if (optind >= argc) 2228*0Sstevel@tonic-gate usage(); 2229*0Sstevel@tonic-gate 2230*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc - optind, argv + optind, 0, 2231*0Sstevel@tonic-gate set_fmri_action, (void *)SCF_PROPERTY_RESTART, 2232*0Sstevel@tonic-gate &exit_status, uu_warn)) != 0) { 2233*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2234*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2235*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2236*0Sstevel@tonic-gate } 2237*0Sstevel@tonic-gate 2238*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "refresh") == 0) { 2239*0Sstevel@tonic-gate ++optind; 2240*0Sstevel@tonic-gate 2241*0Sstevel@tonic-gate if (optind >= argc) 2242*0Sstevel@tonic-gate usage(); 2243*0Sstevel@tonic-gate 2244*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc - optind, argv + optind, 0, 2245*0Sstevel@tonic-gate set_fmri_action, (void *)SCF_PROPERTY_REFRESH, 2246*0Sstevel@tonic-gate &exit_status, uu_warn)) != 0) { 2247*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2248*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(scf_error())); 2249*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2250*0Sstevel@tonic-gate } 2251*0Sstevel@tonic-gate 2252*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "mark") == 0) { 2253*0Sstevel@tonic-gate int flags = 0; 2254*0Sstevel@tonic-gate scf_walk_callback callback; 2255*0Sstevel@tonic-gate 2256*0Sstevel@tonic-gate ++optind; 2257*0Sstevel@tonic-gate 2258*0Sstevel@tonic-gate while ((o = getopt(argc, argv, "It")) != -1) { 2259*0Sstevel@tonic-gate if (o == 'I') 2260*0Sstevel@tonic-gate flags |= MARK_IMMEDIATE; 2261*0Sstevel@tonic-gate else if (o == 't') 2262*0Sstevel@tonic-gate flags |= MARK_TEMPORARY; 2263*0Sstevel@tonic-gate else if (o == '?') 2264*0Sstevel@tonic-gate usage(); 2265*0Sstevel@tonic-gate else { 2266*0Sstevel@tonic-gate assert(0); 2267*0Sstevel@tonic-gate abort(); 2268*0Sstevel@tonic-gate } 2269*0Sstevel@tonic-gate } 2270*0Sstevel@tonic-gate 2271*0Sstevel@tonic-gate if (argc - optind < 2) 2272*0Sstevel@tonic-gate usage(); 2273*0Sstevel@tonic-gate 2274*0Sstevel@tonic-gate if (strcmp(argv[optind], "degraded") == 0) { 2275*0Sstevel@tonic-gate if (flags & MARK_TEMPORARY) 2276*0Sstevel@tonic-gate uu_xdie(UU_EXIT_USAGE, gettext("-t may not be " 2277*0Sstevel@tonic-gate "used with degraded.\n")); 2278*0Sstevel@tonic-gate callback = force_degraded; 2279*0Sstevel@tonic-gate 2280*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "maintenance") == 0) { 2281*0Sstevel@tonic-gate callback = force_maintenance; 2282*0Sstevel@tonic-gate } else { 2283*0Sstevel@tonic-gate usage(); 2284*0Sstevel@tonic-gate } 2285*0Sstevel@tonic-gate 2286*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc - optind - 1, 2287*0Sstevel@tonic-gate argv + optind + 1, 0, callback, NULL, &exit_status, 2288*0Sstevel@tonic-gate uu_warn)) != 0) { 2289*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2290*0Sstevel@tonic-gate "instances: %s\n"), 2291*0Sstevel@tonic-gate scf_strerror(err)); 2292*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2293*0Sstevel@tonic-gate } 2294*0Sstevel@tonic-gate 2295*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "clear") == 0) { 2296*0Sstevel@tonic-gate ++optind; 2297*0Sstevel@tonic-gate 2298*0Sstevel@tonic-gate if (optind >= argc) 2299*0Sstevel@tonic-gate usage(); 2300*0Sstevel@tonic-gate 2301*0Sstevel@tonic-gate if ((err = scf_walk_fmri(h, argc - optind, argv + optind, 0, 2302*0Sstevel@tonic-gate clear_instance, NULL, &exit_status, uu_warn)) != 0) { 2303*0Sstevel@tonic-gate uu_warn(gettext("failed to iterate over " 2304*0Sstevel@tonic-gate "instances: %s\n"), scf_strerror(err)); 2305*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2306*0Sstevel@tonic-gate } 2307*0Sstevel@tonic-gate 2308*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "milestone") == 0) { 2309*0Sstevel@tonic-gate boolean_t temporary = B_TRUE; 2310*0Sstevel@tonic-gate const char *milestone; 2311*0Sstevel@tonic-gate 2312*0Sstevel@tonic-gate ++optind; 2313*0Sstevel@tonic-gate 2314*0Sstevel@tonic-gate while ((o = getopt(argc, argv, "d")) != -1) { 2315*0Sstevel@tonic-gate if (o == 'd') 2316*0Sstevel@tonic-gate temporary = B_FALSE; 2317*0Sstevel@tonic-gate else if (o == '?') 2318*0Sstevel@tonic-gate usage_milestone(); 2319*0Sstevel@tonic-gate else { 2320*0Sstevel@tonic-gate assert(0); 2321*0Sstevel@tonic-gate abort(); 2322*0Sstevel@tonic-gate } 2323*0Sstevel@tonic-gate } 2324*0Sstevel@tonic-gate 2325*0Sstevel@tonic-gate if (optind >= argc) 2326*0Sstevel@tonic-gate usage_milestone(); 2327*0Sstevel@tonic-gate 2328*0Sstevel@tonic-gate milestone = validate_milestone(argv[optind]); 2329*0Sstevel@tonic-gate 2330*0Sstevel@tonic-gate set_milestone(milestone, temporary); 2331*0Sstevel@tonic-gate } else if (strcmp(argv[optind], "_smf_backup") == 0) { 2332*0Sstevel@tonic-gate const char *reason = NULL; 2333*0Sstevel@tonic-gate 2334*0Sstevel@tonic-gate ++optind; 2335*0Sstevel@tonic-gate 2336*0Sstevel@tonic-gate if (optind != argc - 1) 2337*0Sstevel@tonic-gate usage(); 2338*0Sstevel@tonic-gate 2339*0Sstevel@tonic-gate if ((err = _scf_request_backup(h, argv[optind])) != 2340*0Sstevel@tonic-gate SCF_SUCCESS) { 2341*0Sstevel@tonic-gate switch (scf_error()) { 2342*0Sstevel@tonic-gate case SCF_ERROR_NOT_BOUND: 2343*0Sstevel@tonic-gate case SCF_ERROR_CONNECTION_BROKEN: 2344*0Sstevel@tonic-gate case SCF_ERROR_BACKEND_READONLY: 2345*0Sstevel@tonic-gate scfdie(); 2346*0Sstevel@tonic-gate break; 2347*0Sstevel@tonic-gate 2348*0Sstevel@tonic-gate case SCF_ERROR_PERMISSION_DENIED: 2349*0Sstevel@tonic-gate case SCF_ERROR_INVALID_ARGUMENT: 2350*0Sstevel@tonic-gate reason = scf_strerror(scf_error()); 2351*0Sstevel@tonic-gate break; 2352*0Sstevel@tonic-gate 2353*0Sstevel@tonic-gate case SCF_ERROR_INTERNAL: 2354*0Sstevel@tonic-gate reason = 2355*0Sstevel@tonic-gate "unknown error (see console for details)"; 2356*0Sstevel@tonic-gate break; 2357*0Sstevel@tonic-gate } 2358*0Sstevel@tonic-gate uu_warn("failed to backup repository: %s\n", reason); 2359*0Sstevel@tonic-gate exit_status = UU_EXIT_FATAL; 2360*0Sstevel@tonic-gate } 2361*0Sstevel@tonic-gate } else { 2362*0Sstevel@tonic-gate usage(); 2363*0Sstevel@tonic-gate } 2364*0Sstevel@tonic-gate 2365*0Sstevel@tonic-gate if (scf_handle_unbind(h) == -1) 2366*0Sstevel@tonic-gate scfdie(); 2367*0Sstevel@tonic-gate scf_handle_destroy(h); 2368*0Sstevel@tonic-gate 2369*0Sstevel@tonic-gate return (exit_status); 2370*0Sstevel@tonic-gate } 2371