Print this page
7711 SMF: Finish implementing support for degraded state

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/svc/svcs/explain.c
          +++ new/usr/src/cmd/svc/svcs/explain.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 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   * Copyright (c) 2015, Joyent, Inc. All rights reserved.
       26 + * Copyright 2017 RackTop Systems.
  26   27   */
  27   28  
  28   29  /*
  29   30   * Service state explanation.  For select services, display a description, the
  30   31   * state, and possibly why the service is in that state, what's causing it to
  31   32   * be in that state, and what other services it is keeping offline (impact).
  32   33   *
  33   34   * Explaining states other than offline is easy.  For maintenance and
  34   35   * degraded, we just use the auxiliary state.  For offline, we must determine
  35   36   * which dependencies are unsatisfied and recurse.  If a causal service is not
↓ open down ↓ 1153 lines elided ↑ open up ↑
1189 1190          if (svcp->causes == NULL || svcp->baddeps == NULL)
1190 1191                  uu_die(emsg_nomem);
1191 1192  
1192 1193          if (inst_running(svcp) ||
1193 1194              strcmp(svcp->state, SCF_STATE_STRING_UNINIT) == 0) {
1194 1195                  /*
1195 1196                   * If we're running, add a self-pointer in case we're
1196 1197                   * excluding another service.
1197 1198                   */
1198 1199                  add_svcptr(svcp->causes, svcp);
     1200 +                if (strcmp(svcp->state, SCF_STATE_STRING_DEGRADED) == 0)
     1201 +                        add_svcptr(g_causes, svcp);
     1202 +
1199 1203                  return (UU_WALK_NEXT);
1200 1204          }
1201 1205  
1202 1206          if (strcmp(svcp->state, SCF_STATE_STRING_MAINT) == 0) {
1203 1207                  add_svcptr(svcp->causes, svcp);
1204 1208                  add_svcptr(g_causes, svcp);
1205 1209                  return (UU_WALK_NEXT);
1206 1210          }
1207 1211  
1208 1212          if (strcmp(svcp->state, SCF_STATE_STRING_DISABLED) == 0) {
↓ open down ↓ 272 lines elided ↑ open up ↑
1481 1485          if (stat != 0) {
1482 1486                  if (WIFEXITED(stat)) {
1483 1487                          if (WEXITSTATUS(stat) == SMF_EXIT_ERR_CONFIG) {
1484 1488                                  (void) strlcpy(buf, gettext(
1485 1489                                      "exited with $SMF_EXIT_ERR_CONFIG"),
1486 1490                                      sizeof (buf));
1487 1491                          } else if (WEXITSTATUS(stat) == SMF_EXIT_ERR_FATAL) {
1488 1492                                  (void) strlcpy(buf, gettext(
1489 1493                                      "exited with $SMF_EXIT_ERR_FATAL"),
1490 1494                                      sizeof (buf));
     1495 +                        } else if (WEXITSTATUS(stat) == SMF_EXIT_MON_DEGRADE) {
     1496 +                                (void) strlcpy(buf, gettext(
     1497 +                                    "exited with $SMF_EXIT_MON_DEGRADE"),
     1498 +                                    sizeof (buf));
1491 1499                          } else {
1492 1500                                  (void) snprintf(buf, sizeof (buf),
1493 1501                                      gettext("exited with status %d"),
1494 1502                                      WEXITSTATUS(stat));
1495 1503                          }
1496 1504                  } else if (WIFSIGNALED(stat)) {
1497 1505                          if (WCOREDUMP(stat)) {
1498 1506                                  if (strsignal(WTERMSIG(stat)) != NULL)
1499 1507                                          (void) snprintf(buf, sizeof (buf),
1500 1508                                              gettext("dumped core on %s (%d)"),
↓ open down ↓ 300 lines elided ↑ open up ↑
1801 1809                          /* Function prints diagcodes. */
1802 1810                          return;
1803 1811                  } else {
1804 1812                          (void) printf(gettext(
1805 1813                              "Reason: Transitioning to state %s.\n"),
1806 1814                              svcp->next_state);
1807 1815                          dc = DC_TRANSITION;
1808 1816                  }
1809 1817  
1810 1818          } else if (strcmp(svcp->state, SCF_STATE_STRING_DEGRADED) == 0) {
1811      -                (void) puts(gettext("Reason: Degraded by an administrator."));
1812      -                dc = DC_ADMINDEGR;
     1819 +                if (strcmp(svcp->aux_state, "administrative_request") == 0) {
     1820 +                        (void) puts(gettext("Reason: Degraded by an "
     1821 +                            "administrator."));
     1822 +                        dc = DC_ADMINDEGR;
     1823 +                } else if (strcmp(svcp->aux_state, "service_request") == 0) {
     1824 +                        if (svcp->aux_fmri) {
     1825 +                                (void) printf(gettext("Reason: Degraded by "
     1826 +                                    "\"%s\"\n"), svcp->aux_fmri);
     1827 +                                print_aux_fmri_logs(svcp->aux_fmri);
     1828 +                        } else {
     1829 +                                (void) puts(gettext("Reason: Degraded by "
     1830 +                                    "another service."));
     1831 +                        }
     1832 +                } else if (strcmp(svcp->aux_state, "method_failed") == 0) {
     1833 +                        print_method_failure(svcp, &dc);
     1834 +                } else {
     1835 +                        (void) puts(gettext("Reason: Unknown."));
     1836 +                        dc = DC_UNKNOWN;
     1837 +                }
1813 1838  
1814 1839          } else {
1815 1840                  (void) printf(gettext("Reason: Not in valid state (%s).\n"),
1816 1841                      svcp->state);
1817 1842                  dc = DC_INVALIDSTATE;
1818 1843          }
1819 1844  
1820 1845  diagcode:
1821      -        if (g_msgbase != NULL)
     1846 +        if (g_msgbase != NULL && dc != NULL)
1822 1847                  (void) printf(gettext("   See: %s%s\n"), g_msgbase, dc);
1823 1848  }
1824 1849  
1825 1850  static void
1826 1851  print_manpage(int verbose)
1827 1852  {
1828 1853          static char *title = NULL;
1829 1854          static char *section = NULL;
1830 1855  
1831 1856          if (title == NULL) {
↓ open down ↓ 328 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX