Print this page
12721 would like svcadm disable -c

@@ -21,10 +21,11 @@
 
 /*
  * 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,11 +517,12 @@
 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_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,11 +534,12 @@
 
         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)
+            (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,11 +602,11 @@
 set:
         do {
                 if (scf_transaction_start(tx, gpg) == -1)
                         goto out;
 
-                if (transaction_property_set(tx, ent, SCF_PROPERTY_ENABLED,
+                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,13 +620,23 @@
                                     scf_error());
                         }
                 }
 
                 scf_value_set_boolean(v, desired);
-                if (scf_entry_add_value(ent, v) == -1)
+                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,11 +649,12 @@
 
         ret = 0;
 
 out:
         scf_value_destroy(v);
-        scf_entry_destroy(ent);
+        scf_entry_destroy(ent1);
+        scf_entry_destroy(ent2);
         scf_transaction_destroy(tx);
         scf_property_destroy(eprop);
         scf_pg_destroy(gpg);
 
         return (ret);

@@ -648,11 +662,12 @@
 
 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_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,22 +674,37 @@
         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)
+            (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 ||
-                    scf_transaction_property_delete(tx, ent,
-                    SCF_PROPERTY_ENABLED) == -1 ||
-                    (committed = scf_transaction_commit(tx)) == -1)
+                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,11 +719,12 @@
                 /* success */
                 ret = 0;
         }
 
 out:
-        scf_entry_destroy(ent);
+        scf_entry_destroy(ent1);
+        scf_entry_destroy(ent2);
         scf_transaction_destroy(tx);
         scf_pg_destroy(gpg);
 
         return (ret);
 }