Print this page
12721 would like svcadm disable -c

*** 21,30 **** --- 21,31 ---- /* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2013 Nexenta Systems, Inc. All rights reserved. * Copyright 2018 RackTop Systems. + * Copyright 2020 Joyent, Inc. */ #include "libscf_impl.h" #include <assert.h>
*** 516,526 **** static int set_inst_enabled(const scf_instance_t *inst, uint8_t desired, const char *pgname, uint32_t pgflags) { scf_transaction_t *tx = NULL; ! scf_transaction_entry_t *ent = NULL; scf_propertygroup_t *gpg = NULL; scf_property_t *eprop = NULL; scf_value_t *v = NULL; scf_handle_t *h = NULL; int ret = -1; --- 517,528 ---- static int set_inst_enabled(const scf_instance_t *inst, uint8_t desired, const char *pgname, uint32_t pgflags) { scf_transaction_t *tx = NULL; ! scf_transaction_entry_t *ent1 = NULL; ! scf_transaction_entry_t *ent2 = NULL; scf_propertygroup_t *gpg = NULL; scf_property_t *eprop = NULL; scf_value_t *v = NULL; scf_handle_t *h = NULL; int ret = -1;
*** 532,542 **** if ((gpg = scf_pg_create(h)) == NULL || (eprop = scf_property_create(h)) == NULL || (v = scf_value_create(h)) == NULL || (tx = scf_transaction_create(h)) == NULL || ! (ent = scf_entry_create(h)) == NULL) goto out; general_pg_get: if (scf_instance_get_pg(inst, SCF_PG_GENERAL, gpg) == -1) { if (scf_error() != SCF_ERROR_NOT_FOUND) --- 534,545 ---- if ((gpg = scf_pg_create(h)) == NULL || (eprop = scf_property_create(h)) == NULL || (v = scf_value_create(h)) == NULL || (tx = scf_transaction_create(h)) == NULL || ! (ent1 = scf_entry_create(h)) == NULL || ! (ent2 = scf_entry_create(h)) == NULL) goto out; general_pg_get: if (scf_instance_get_pg(inst, SCF_PG_GENERAL, gpg) == -1) { if (scf_error() != SCF_ERROR_NOT_FOUND)
*** 599,609 **** set: do { if (scf_transaction_start(tx, gpg) == -1) goto out; ! if (transaction_property_set(tx, ent, SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN) != 0) { switch (scf_error()) { case SCF_ERROR_CONNECTION_BROKEN: case SCF_ERROR_DELETED: default: --- 602,612 ---- set: do { if (scf_transaction_start(tx, gpg) == -1) goto out; ! if (transaction_property_set(tx, ent1, SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN) != 0) { switch (scf_error()) { case SCF_ERROR_CONNECTION_BROKEN: case SCF_ERROR_DELETED: default:
*** 617,629 **** scf_error()); } } scf_value_set_boolean(v, desired); ! if (scf_entry_add_value(ent, v) == -1) goto out; committed = scf_transaction_commit(tx); if (committed == -1) goto out; scf_transaction_reset(tx); --- 620,642 ---- scf_error()); } } scf_value_set_boolean(v, desired); ! if (scf_entry_add_value(ent1, v) == -1) goto out; + /* If we're enabling, clear out any disabled comment. */ + if (desired) { + ret = scf_transaction_property_delete(tx, ent2, + SCF_PROPERTY_COMMENT); + + if (ret == -1 && scf_error() != SCF_ERROR_DELETED && + scf_error() != SCF_ERROR_NOT_FOUND) + goto out; + } + committed = scf_transaction_commit(tx); if (committed == -1) goto out; scf_transaction_reset(tx);
*** 636,646 **** ret = 0; out: scf_value_destroy(v); ! scf_entry_destroy(ent); scf_transaction_destroy(tx); scf_property_destroy(eprop); scf_pg_destroy(gpg); return (ret); --- 649,660 ---- ret = 0; out: scf_value_destroy(v); ! scf_entry_destroy(ent1); ! scf_entry_destroy(ent2); scf_transaction_destroy(tx); scf_property_destroy(eprop); scf_pg_destroy(gpg); return (ret);
*** 648,658 **** static int delete_inst_enabled(const scf_instance_t *inst, const char *pgname) { scf_transaction_t *tx = NULL; ! scf_transaction_entry_t *ent = NULL; scf_propertygroup_t *gpg = NULL; scf_handle_t *h = NULL; int ret = -1; int committed; --- 662,673 ---- static int delete_inst_enabled(const scf_instance_t *inst, const char *pgname) { scf_transaction_t *tx = NULL; ! scf_transaction_entry_t *ent1 = NULL; ! scf_transaction_entry_t *ent2 = NULL; scf_propertygroup_t *gpg = NULL; scf_handle_t *h = NULL; int ret = -1; int committed;
*** 659,680 **** if ((h = scf_instance_handle(inst)) == NULL) return (-1); if ((gpg = scf_pg_create(h)) == NULL || (tx = scf_transaction_create(h)) == NULL || ! (ent = scf_entry_create(h)) == NULL) goto out; if (scf_instance_get_pg(inst, pgname, gpg) != 0) goto error; do { ! if (scf_transaction_start(tx, gpg) == -1 || ! scf_transaction_property_delete(tx, ent, ! SCF_PROPERTY_ENABLED) == -1 || ! (committed = scf_transaction_commit(tx)) == -1) goto error; scf_transaction_reset(tx); if (committed == 0 && scf_pg_update(gpg) == -1) goto error; } while (committed == 0); --- 674,710 ---- if ((h = scf_instance_handle(inst)) == NULL) return (-1); if ((gpg = scf_pg_create(h)) == NULL || (tx = scf_transaction_create(h)) == NULL || ! (ent1 = scf_entry_create(h)) == NULL || ! (ent2 = scf_entry_create(h)) == NULL) goto out; if (scf_instance_get_pg(inst, pgname, gpg) != 0) goto error; do { ! if (scf_transaction_start(tx, gpg) == -1) goto error; + ret = scf_transaction_property_delete(tx, ent1, + SCF_PROPERTY_ENABLED); + + if (ret == -1 && scf_error() != SCF_ERROR_DELETED && + scf_error() != SCF_ERROR_NOT_FOUND) + goto error; + + ret = scf_transaction_property_delete(tx, ent2, + SCF_PROPERTY_COMMENT); + + if (ret == -1 && scf_error() != SCF_ERROR_DELETED && + scf_error() != SCF_ERROR_NOT_FOUND) + goto error; + + if ((committed = scf_transaction_commit(tx)) == -1) + goto error; + scf_transaction_reset(tx); if (committed == 0 && scf_pg_update(gpg) == -1) goto error; } while (committed == 0);
*** 689,699 **** /* success */ ret = 0; } out: ! scf_entry_destroy(ent); scf_transaction_destroy(tx); scf_pg_destroy(gpg); return (ret); } --- 719,730 ---- /* success */ ret = 0; } out: ! scf_entry_destroy(ent1); ! scf_entry_destroy(ent2); scf_transaction_destroy(tx); scf_pg_destroy(gpg); return (ret); }