Print this page
12721 would like svcadm disable -c

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/svc/svcs/explain.c
          +++ new/usr/src/cmd/svc/svcs/explain.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  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 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25      - * Copyright (c) 2015, Joyent, Inc. All rights reserved.
       25 + * Copyright 2020 Joyent, Inc.
  26   26   */
  27   27  
  28   28  /*
  29   29   * Service state explanation.  For select services, display a description, the
  30   30   * state, and possibly why the service is in that state, what's causing it to
  31   31   * be in that state, and what other services it is keeping offline (impact).
  32   32   *
  33   33   * Explaining states other than offline is easy.  For maintenance and
  34   34   * degraded, we just use the auxiliary state.  For offline, we must determine
  35   35   * which dependencies are unsatisfied and recurse.  If a causal service is not
↓ open down ↓ 90 lines elided ↑ open up ↑
 126  126          struct timeval stime;
 127  127          const char *aux_state;
 128  128          const char *aux_fmri;
 129  129          int64_t start_method_waitstatus;
 130  130  
 131  131          uint8_t enabled;
 132  132          int temporary;
 133  133          const char *restarter;
 134  134          uu_list_t *dependencies;        /* list of dependency_group's */
 135  135  
      136 +        char comment[SCF_COMMENT_MAX_LENGTH];
      137 +
 136  138          int active;                     /* In use?  (cycle detection) */
 137  139          int restarter_bad;
 138  140          const char *summary;
 139  141          uu_list_t *baddeps;             /* list of dependency's */
 140  142          uu_list_t *causes;              /* list of svcptrs */
 141  143          uu_list_t *impact_dependents;   /* list of svcptrs */
 142  144          uu_list_t *impact;              /* list of svcptrs */
 143  145  
 144  146          uu_list_node_t node;
 145  147  } inst_t;
↓ open down ↓ 250 lines elided ↑ open up ↑
 396  398          }
 397  399  
 398  400          return (0);
 399  401  }
 400  402  
 401  403  static void
 402  404  add_instance(const char *svcname, const char *instname, scf_instance_t *inst)
 403  405  {
 404  406          inst_t *instp;
 405  407          svc_t *svcp;
 406      -        int have_enabled = 0;
      408 +        int ovr_set = 0;
 407  409          uint8_t i;
 408  410          uint32_t h;
 409  411          int r;
 410  412  
 411  413          h = hash_name(svcname) & SVC_HASH_MASK;
 412  414          for (svcp = services[h]; svcp != NULL; svcp = svcp->next) {
 413  415                  if (strcmp(svcp->svcname, svcname) == 0)
 414  416                          break;
 415  417          }
 416  418  
↓ open down ↓ 55 lines elided ↑ open up ↑
 472  474              SCF_TYPE_INTEGER, &instp->start_method_waitstatus, 0, 0);
 473  475  
 474  476          /* Get the optional auxiliary_fmri */
 475  477          if (pg_get_single_val(g_pg, SCF_PROPERTY_AUX_FMRI, SCF_TYPE_ASTRING,
 476  478              g_fmri, g_fmri_sz, 0) == 0)
 477  479                  instp->aux_fmri = safe_strdup(g_fmri);
 478  480  
 479  481          if (scf_instance_get_pg(inst, SCF_PG_GENERAL_OVR, g_pg) == 0) {
 480  482                  if (pg_get_single_val(g_pg, SCF_PROPERTY_ENABLED,
 481  483                      SCF_TYPE_BOOLEAN, &instp->enabled, 0, 0) == 0)
 482      -                        have_enabled = 1;
      484 +                        ovr_set = 1;
      485 +                (void) pg_get_single_val(g_pg, SCF_PROPERTY_COMMENT,
      486 +                    SCF_TYPE_ASTRING, instp->comment,
      487 +                    sizeof (instp->comment), EMPTY_OK);
 483  488          } else {
 484  489                  switch (scf_error()) {
 485  490                  case SCF_ERROR_NOT_FOUND:
 486  491                          break;
 487  492  
 488  493                  case SCF_ERROR_DELETED:
 489  494                          return;
 490  495  
 491  496                  default:
 492  497                          scfdie();
↓ open down ↓ 8 lines elided ↑ open up ↑
 501  506                          return;
 502  507  
 503  508                  default:
 504  509                          scfdie();
 505  510                  }
 506  511          }
 507  512  
 508  513          if (pg_get_single_val(g_pg, SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN,
 509  514              &i, 0, 0) != 0)
 510  515                  return;
 511      -        if (!have_enabled) {
      516 +
      517 +        if (ovr_set) {
      518 +                instp->temporary = (instp->enabled != i);
      519 +        } else {
 512  520                  instp->enabled = i;
 513  521                  instp->temporary = 0;
 514      -        } else {
 515      -                instp->temporary = (instp->enabled != i);
 516  522          }
 517  523  
      524 +        if (!instp->temporary) {
      525 +                (void) pg_get_single_val(g_pg, SCF_PROPERTY_COMMENT,
      526 +                    SCF_TYPE_ASTRING, instp->comment,
      527 +                    sizeof (instp->comment), EMPTY_OK);
      528 +        }
      529 +
 518  530          if (pg_get_single_val(g_pg, SCF_PROPERTY_RESTARTER, SCF_TYPE_ASTRING,
 519  531              g_fmri, g_fmri_sz, 0) == 0)
 520  532                  instp->restarter = safe_strdup(g_fmri);
 521  533          else
 522  534                  instp->restarter = SCF_SERVICE_STARTD;
 523  535  
 524  536          if (strcmp(instp->state, SCF_STATE_STRING_OFFLINE) == 0 &&
 525  537              load_dependencies(instp, inst) != 0)
 526  538                  return;
 527  539  
↓ open down ↓ 1201 lines elided ↑ open up ↑
1729 1741                          dc = DC_UNINIT;
1730 1742                  } else {
1731 1743                          (void) printf(gettext(
1732 1744                              "Reason: Restarter %s is not running.\n"),
1733 1745                              svcp->restarter);
1734 1746                          dc = DC_RSTRDEAD;
1735 1747                  }
1736 1748  
1737 1749          } else if (strcmp(svcp->state, SCF_STATE_STRING_DISABLED) == 0) {
1738 1750                  if (!svcp->temporary) {
1739      -                        (void) puts(gettext(
1740      -                            "Reason: Disabled by an administrator."));
     1751 +                        if (svcp->comment[0] != '\0') {
     1752 +                                (void) printf(gettext("Reason: Disabled by "
     1753 +                                    "an administrator: %s\n"), svcp->comment);
     1754 +                        } else {
     1755 +                                (void) printf(gettext("Reason: Disabled by "
     1756 +                                    "an administrator.\n"));
     1757 +                        }
1741 1758                          dc = DC_DISABLED;
1742 1759                  } else {
1743      -                        (void) puts(gettext("Reason: "
1744      -                            "Temporarily disabled by an administrator."));
     1760 +                        if (svcp->comment[0] != '\0') {
     1761 +                                (void) printf(gettext("Reason: Temporarily "
     1762 +                                    "disabled by an administrator: %s\n"),
     1763 +                                    svcp->comment);
     1764 +                        } else {
     1765 +                                (void) printf(gettext("Reason: Temporarily "
     1766 +                                    "disabled by an administrator.\n"));
     1767 +                        }
1745 1768                          dc = DC_TEMPDISABLED;
1746 1769                  }
1747 1770  
1748 1771          } else if (strcmp(svcp->state, SCF_STATE_STRING_MAINT) == 0) {
1749 1772                  if (strcmp(svcp->aux_state, "administrative_request") == 0) {
1750 1773                          (void) puts(gettext("Reason: "
1751 1774                              "Maintenance requested by an administrator."));
1752 1775                          dc = DC_ADMINMAINT;
1753 1776                  } else if (strcmp(svcp->aux_state, "dependency_cycle") == 0) {
1754 1777                          (void) puts(gettext(
↓ open down ↓ 405 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX