Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/svc/startd/restarter.c
          +++ new/usr/src/cmd/svc/startd/restarter.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright (c) 2013, Joyent, Inc. All rights reserved.
       24 + * Copyright 2018 Joyent, Inc.
  25   25   */
  26   26  
  27   27  /*
  28   28   * restarter.c - service manipulation
  29   29   *
  30   30   * This component manages services whose restarter is svc.startd, the standard
  31   31   * restarter.  It translates restarter protocol events from the graph engine
  32   32   * into actions on processes, as a delegated restarter would do.
  33   33   *
  34   34   * The master restarter manages a number of always-running threads:
↓ open down ↓ 952 lines elided ↑ open up ↑
 987  987          MUTEX_UNLOCK(&instance_list.ril_lock);
 988  988  }
 989  989  
 990  990  /* ARGSUSED */
 991  991  void *
 992  992  restarter_post_fsminimal_thread(void *unused)
 993  993  {
 994  994          scf_handle_t *h;
 995  995          int r;
 996  996  
      997 +        (void) pthread_setname_np(pthread_self(), "restarter_post_fsmin");
      998 +
 997  999          h = libscf_handle_create_bound_loop();
 998 1000  
 999 1001          for (;;) {
1000 1002                  r = libscf_create_self(h);
1001 1003                  if (r == 0)
1002 1004                          break;
1003 1005  
1004 1006                  assert(r == ECONNABORTED);
1005 1007                  libscf_handle_rebind(h);
1006 1008          }
↓ open down ↓ 757 lines elided ↑ open up ↑
1764 1766   */
1765 1767  static void *
1766 1768  restarter_process_events(void *arg)
1767 1769  {
1768 1770          scf_handle_t *h;
1769 1771          restarter_instance_qentry_t *event;
1770 1772          restarter_inst_t *rip;
1771 1773          char *fmri = (char *)arg;
1772 1774          struct timespec to;
1773 1775  
     1776 +        (void) pthread_setname_np(pthread_self(), "restarter_process_events");
     1777 +
1774 1778          assert(fmri != NULL);
1775 1779  
1776 1780          h = libscf_handle_create_bound_loop();
1777 1781  
1778 1782          /* grab the queue lock */
1779 1783          rip = inst_lookup_queue(fmri);
1780 1784          if (rip == NULL)
1781 1785                  goto out;
1782 1786  
1783 1787  again:
↓ open down ↓ 148 lines elided ↑ open up ↑
1932 1936          MUTEX_UNLOCK(&rip->ri_queue_lock);
1933 1937  
1934 1938  out:
1935 1939          (void) scf_handle_unbind(h);
1936 1940          scf_handle_destroy(h);
1937 1941          free(fmri);
1938 1942          return (NULL);
1939 1943  }
1940 1944  
1941 1945  static int
1942      -is_admin_event(restarter_event_type_t t) {
1943      -
     1946 +is_admin_event(restarter_event_type_t t)
     1947 +{
1944 1948          switch (t) {
1945 1949          case RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON:
1946 1950          case RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON_IMMEDIATE:
1947 1951          case RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF:
1948 1952          case RESTARTER_EVENT_TYPE_ADMIN_REFRESH:
1949 1953          case RESTARTER_EVENT_TYPE_ADMIN_DEGRADED:
1950 1954          case RESTARTER_EVENT_TYPE_ADMIN_RESTART:
1951 1955                  return (1);
1952 1956          default:
1953 1957                  return (0);
↓ open down ↓ 24 lines elided ↑ open up ↑
1978 1982   *  Handle incoming graph events by placing them on a per-instance
1979 1983   *  queue.  We can't lock the main part of the instance structure, so
1980 1984   *  just modify the seprarately locked event queue portion.
1981 1985   */
1982 1986  /*ARGSUSED*/
1983 1987  static void *
1984 1988  restarter_event_thread(void *unused)
1985 1989  {
1986 1990          scf_handle_t *h;
1987 1991  
     1992 +        (void) pthread_setname_np(pthread_self(), "restarter_event");
     1993 +
1988 1994          /*
1989 1995           * This is a new thread, and thus, gets its own handle
1990 1996           * to the repository.
1991 1997           */
1992 1998          h = libscf_handle_create_bound_loop();
1993 1999  
1994 2000          MUTEX_LOCK(&ru->restarter_update_lock);
1995 2001  
1996 2002          /*CONSTCOND*/
1997 2003          while (1) {
↓ open down ↓ 191 lines elided ↑ open up ↑
2189 2195   *   Listens to the process contract bundle for critical events, taking action
2190 2196   *   on events from contracts we know we are responsible for.
2191 2197   */
2192 2198  /*ARGSUSED*/
2193 2199  static void *
2194 2200  restarter_contracts_event_thread(void *unused)
2195 2201  {
2196 2202          int fd, err;
2197 2203          scf_handle_t *local_handle;
2198 2204  
     2205 +        (void) pthread_setname_np(pthread_self(), "restarter_contracts_event");
     2206 +
2199 2207          /*
2200 2208           * Await graph load completion.  That is, stop here, until we've scanned
2201 2209           * the repository for contract - instance associations.
2202 2210           */
2203 2211          MUTEX_LOCK(&st->st_load_lock);
2204 2212          while (!(st->st_load_complete && st->st_load_instances == 0))
2205 2213                  (void) pthread_cond_wait(&st->st_load_cv, &st->st_load_lock);
2206 2214          MUTEX_UNLOCK(&st->st_load_lock);
2207 2215  
2208 2216          /*
↓ open down ↓ 329 lines elided ↑ open up ↑
2538 2546  static void *
2539 2547  restarter_timeouts_event_thread(void *unused)
2540 2548  {
2541 2549          /*
2542 2550           * Timeouts are entered on a priority queue, which is processed by
2543 2551           * this thread.  As timeouts are specified in seconds, we'll do
2544 2552           * the necessary processing every second, as long as the queue
2545 2553           * is not empty.
2546 2554           */
2547 2555  
     2556 +        (void) pthread_setname_np(pthread_self(), "restarter_timeouts_event");
     2557 +
2548 2558          /*CONSTCOND*/
2549 2559          while (1) {
2550 2560                  /*
2551 2561                   * As long as the timeout list isn't empty, process it
2552 2562                   * every second.
2553 2563                   */
2554 2564                  if (timeout_now() == 0) {
2555 2565                          (void) sleep(1);
2556 2566                          continue;
2557 2567                  }
↓ open down ↓ 49 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX