Print this page
12721 would like svcadm disable -c

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libscf/common/midlevel.c
          +++ new/usr/src/lib/libscf/common/midlevel.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  25   25   * Copyright 2018 RackTop Systems.
       26 + * Copyright 2020 Joyent, Inc.
  26   27   */
  27   28  
  28   29  #include "libscf_impl.h"
  29   30  
  30   31  #include <assert.h>
  31   32  #include <libuutil.h>
  32   33  #include <stdio.h>
  33   34  #include <string.h>
  34   35  #include <stdlib.h>
  35   36  #include <sys/param.h>
↓ open down ↓ 475 lines elided ↑ open up ↑
 511  512   * set_inst_enabled() is a "master" enable/disable call that takes the
 512  513   * instance and the desired state for the enabled bit in the instance's
 513  514   * named property group.  If the group doesn't exist, it's created with the
 514  515   * given flags.  Called by smf_{dis,en}able_instance().
 515  516   */
 516  517  static int
 517  518  set_inst_enabled(const scf_instance_t *inst, uint8_t desired,
 518  519      const char *pgname, uint32_t pgflags)
 519  520  {
 520  521          scf_transaction_t       *tx = NULL;
 521      -        scf_transaction_entry_t *ent = NULL;
      522 +        scf_transaction_entry_t *ent1 = NULL;
      523 +        scf_transaction_entry_t *ent2 = NULL;
 522  524          scf_propertygroup_t     *gpg = NULL;
 523  525          scf_property_t          *eprop = NULL;
 524  526          scf_value_t             *v = NULL;
 525  527          scf_handle_t            *h = NULL;
 526  528          int                     ret = -1;
 527  529          int                     committed;
 528  530          uint8_t                 b;
 529  531  
 530  532          if ((h = scf_instance_handle(inst)) == NULL)
 531  533                  return (-1);
 532  534  
 533  535          if ((gpg = scf_pg_create(h)) == NULL ||
 534  536              (eprop = scf_property_create(h)) == NULL ||
 535  537              (v = scf_value_create(h)) == NULL ||
 536  538              (tx = scf_transaction_create(h)) == NULL ||
 537      -            (ent = scf_entry_create(h)) == NULL)
      539 +            (ent1 = scf_entry_create(h)) == NULL ||
      540 +            (ent2 = scf_entry_create(h)) == NULL)
 538  541                  goto out;
 539  542  
 540  543  general_pg_get:
 541  544          if (scf_instance_get_pg(inst, SCF_PG_GENERAL, gpg) == -1) {
 542  545                  if (scf_error() != SCF_ERROR_NOT_FOUND)
 543  546                          goto out;
 544  547  
 545  548                  if (scf_instance_add_pg(inst, SCF_PG_GENERAL,
 546  549                      SCF_GROUP_FRAMEWORK, SCF_PG_GENERAL_FLAGS, gpg) == -1) {
 547  550                          if (scf_error() != SCF_ERROR_EXISTS)
↓ open down ↓ 46 lines elided ↑ open up ↑
 594  597          if (b == desired) {
 595  598                  ret = 0;
 596  599                  goto out;
 597  600          }
 598  601  
 599  602  set:
 600  603          do {
 601  604                  if (scf_transaction_start(tx, gpg) == -1)
 602  605                          goto out;
 603  606  
 604      -                if (transaction_property_set(tx, ent, SCF_PROPERTY_ENABLED,
      607 +                if (transaction_property_set(tx, ent1, SCF_PROPERTY_ENABLED,
 605  608                      SCF_TYPE_BOOLEAN) != 0) {
 606  609                          switch (scf_error()) {
 607  610                          case SCF_ERROR_CONNECTION_BROKEN:
 608  611                          case SCF_ERROR_DELETED:
 609  612                          default:
 610  613                                  goto out;
 611  614  
 612  615                          case SCF_ERROR_HANDLE_MISMATCH:
 613  616                          case SCF_ERROR_INVALID_ARGUMENT:
 614  617                          case SCF_ERROR_NOT_BOUND:
 615  618                          case SCF_ERROR_NOT_SET:
 616  619                                  bad_error("transaction_property_set",
 617  620                                      scf_error());
 618  621                          }
 619  622                  }
 620  623  
 621  624                  scf_value_set_boolean(v, desired);
 622      -                if (scf_entry_add_value(ent, v) == -1)
      625 +                if (scf_entry_add_value(ent1, v) == -1)
 623  626                          goto out;
 624  627  
      628 +                /* If we're enabling, clear out any disabled comment. */
      629 +                if (desired) {
      630 +                        ret = scf_transaction_property_delete(tx, ent2,
      631 +                            SCF_PROPERTY_COMMENT);
      632 +
      633 +                        if (ret == -1 && scf_error() != SCF_ERROR_DELETED &&
      634 +                            scf_error() != SCF_ERROR_NOT_FOUND)
      635 +                                goto out;
      636 +                }
      637 +
 625  638                  committed = scf_transaction_commit(tx);
 626  639                  if (committed == -1)
 627  640                          goto out;
 628  641  
 629  642                  scf_transaction_reset(tx);
 630  643  
 631  644                  if (committed == 0) { /* out-of-sync */
 632  645                          if (scf_pg_update(gpg) == -1)
 633  646                                  goto out;
 634  647                  }
 635  648          } while (committed == 0);
 636  649  
 637  650          ret = 0;
 638  651  
 639  652  out:
 640  653          scf_value_destroy(v);
 641      -        scf_entry_destroy(ent);
      654 +        scf_entry_destroy(ent1);
      655 +        scf_entry_destroy(ent2);
 642  656          scf_transaction_destroy(tx);
 643  657          scf_property_destroy(eprop);
 644  658          scf_pg_destroy(gpg);
 645  659  
 646  660          return (ret);
 647  661  }
 648  662  
 649  663  static int
 650  664  delete_inst_enabled(const scf_instance_t *inst, const char *pgname)
 651  665  {
 652  666          scf_transaction_t       *tx = NULL;
 653      -        scf_transaction_entry_t *ent = NULL;
      667 +        scf_transaction_entry_t *ent1 = NULL;
      668 +        scf_transaction_entry_t *ent2 = NULL;
 654  669          scf_propertygroup_t     *gpg = NULL;
 655  670          scf_handle_t            *h = NULL;
 656  671          int                     ret = -1;
 657  672          int                     committed;
 658  673  
 659  674          if ((h = scf_instance_handle(inst)) == NULL)
 660  675                  return (-1);
 661  676  
 662  677          if ((gpg = scf_pg_create(h)) == NULL ||
 663  678              (tx = scf_transaction_create(h)) == NULL ||
 664      -            (ent = scf_entry_create(h)) == NULL)
      679 +            (ent1 = scf_entry_create(h)) == NULL ||
      680 +            (ent2 = scf_entry_create(h)) == NULL)
 665  681                  goto out;
 666  682  
 667  683          if (scf_instance_get_pg(inst, pgname, gpg) != 0)
 668  684                  goto error;
 669  685          do {
 670      -                if (scf_transaction_start(tx, gpg) == -1 ||
 671      -                    scf_transaction_property_delete(tx, ent,
 672      -                    SCF_PROPERTY_ENABLED) == -1 ||
 673      -                    (committed = scf_transaction_commit(tx)) == -1)
      686 +                if (scf_transaction_start(tx, gpg) == -1)
 674  687                          goto error;
 675  688  
      689 +                ret = scf_transaction_property_delete(tx, ent1,
      690 +                    SCF_PROPERTY_ENABLED);
      691 +
      692 +                if (ret == -1 && scf_error() != SCF_ERROR_DELETED &&
      693 +                    scf_error() != SCF_ERROR_NOT_FOUND)
      694 +                        goto error;
      695 +
      696 +                ret = scf_transaction_property_delete(tx, ent2,
      697 +                    SCF_PROPERTY_COMMENT);
      698 +
      699 +                if (ret == -1 && scf_error() != SCF_ERROR_DELETED &&
      700 +                    scf_error() != SCF_ERROR_NOT_FOUND)
      701 +                        goto error;
      702 +
      703 +                if ((committed = scf_transaction_commit(tx)) == -1)
      704 +                        goto error;
      705 +
 676  706                  scf_transaction_reset(tx);
 677  707  
 678  708                  if (committed == 0 && scf_pg_update(gpg) == -1)
 679  709                          goto error;
 680  710          } while (committed == 0);
 681  711  
 682  712          ret = 0;
 683  713          goto out;
 684  714  
 685  715  error:
 686  716          switch (scf_error()) {
 687  717          case SCF_ERROR_DELETED:
 688  718          case SCF_ERROR_NOT_FOUND:
 689  719                  /* success */
 690  720                  ret = 0;
 691  721          }
 692  722  
 693  723  out:
 694      -        scf_entry_destroy(ent);
      724 +        scf_entry_destroy(ent1);
      725 +        scf_entry_destroy(ent2);
 695  726          scf_transaction_destroy(tx);
 696  727          scf_pg_destroy(gpg);
 697  728  
 698  729          return (ret);
 699  730  }
 700  731  
 701  732  /*
 702  733   * Returns 0 on success or -1 on failure.  On failure leaves scf_error() set to
 703  734   *   SCF_ERROR_HANDLE_DESTROYED - inst's handle has been destroyed
 704  735   *   SCF_ERROR_NOT_BOUND - inst's handle is not bound
↓ open down ↓ 2448 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX