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


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2012, Joyent, Inc.  All rights reserved.

  25  */
  26 
  27 /*
  28  * wait.c - asynchronous monitoring of "wait registered" start methods
  29  *
  30  * Use event ports to poll on the set of fds representing the /proc/[pid]/psinfo
  31  * files.  If one of these fds returns an event, then we inform the restarter
  32  * that it has stopped.
  33  *
  34  * The wait_info_list holds the series of processes currently being monitored
  35  * for exit.  The wi_fd member, which contains the file descriptor of the psinfo
  36  * file being polled upon ("event ported upon"), will be set to -1 if the file
  37  * descriptor is inactive (already closed or not yet opened).
  38  */
  39 
  40 #ifdef _FILE_OFFSET_BITS
  41 #undef _FILE_OFFSET_BITS
  42 #endif /* _FILE_OFFSET_BITS */
  43 
  44 #include <sys/resource.h>


 235 
 236         wi->wi_fd = fd;
 237 
 238         if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi)) {
 239                 log_error(LOG_WARNING,
 240                     "initial port_association of %d / %s failed: %s\n", fd,
 241                     inst_fmri, strerror(errno));
 242                 return (-1);
 243         }
 244 
 245         log_framework(LOG_DEBUG, "monitoring PID %ld on fd %d (%s)\n", pid, fd,
 246             inst_fmri);
 247 
 248         return (0);
 249 }
 250 
 251 /*ARGSUSED*/
 252 void *
 253 wait_thread(void *args)
 254 {


 255         for (;;) {
 256                 port_event_t pe;
 257                 int fd;
 258                 wait_info_t *wi;
 259 
 260                 if (port_get(port_fd, &pe, NULL) != 0) {
 261                         if (errno == EINTR)
 262                                 continue;
 263                         else {
 264                                 log_error(LOG_WARNING,
 265                                     "port_get() failed with %s\n",
 266                                     strerror(errno));
 267                                 bad_error("port_get", errno);
 268                         }
 269                 }
 270 
 271                 fd = pe.portev_object;
 272                 wi = pe.portev_user;
 273                 assert(wi != NULL);
 274                 assert(fd == wi->wi_fd);




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 /*
  29  * wait.c - asynchronous monitoring of "wait registered" start methods
  30  *
  31  * Use event ports to poll on the set of fds representing the /proc/[pid]/psinfo
  32  * files.  If one of these fds returns an event, then we inform the restarter
  33  * that it has stopped.
  34  *
  35  * The wait_info_list holds the series of processes currently being monitored
  36  * for exit.  The wi_fd member, which contains the file descriptor of the psinfo
  37  * file being polled upon ("event ported upon"), will be set to -1 if the file
  38  * descriptor is inactive (already closed or not yet opened).
  39  */
  40 
  41 #ifdef _FILE_OFFSET_BITS
  42 #undef _FILE_OFFSET_BITS
  43 #endif /* _FILE_OFFSET_BITS */
  44 
  45 #include <sys/resource.h>


 236 
 237         wi->wi_fd = fd;
 238 
 239         if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi)) {
 240                 log_error(LOG_WARNING,
 241                     "initial port_association of %d / %s failed: %s\n", fd,
 242                     inst_fmri, strerror(errno));
 243                 return (-1);
 244         }
 245 
 246         log_framework(LOG_DEBUG, "monitoring PID %ld on fd %d (%s)\n", pid, fd,
 247             inst_fmri);
 248 
 249         return (0);
 250 }
 251 
 252 /*ARGSUSED*/
 253 void *
 254 wait_thread(void *args)
 255 {
 256         (void) pthread_setname_np(pthread_self(), "wait");
 257 
 258         for (;;) {
 259                 port_event_t pe;
 260                 int fd;
 261                 wait_info_t *wi;
 262 
 263                 if (port_get(port_fd, &pe, NULL) != 0) {
 264                         if (errno == EINTR)
 265                                 continue;
 266                         else {
 267                                 log_error(LOG_WARNING,
 268                                     "port_get() failed with %s\n",
 269                                     strerror(errno));
 270                                 bad_error("port_get", errno);
 271                         }
 272                 }
 273 
 274                 fd = pe.portev_object;
 275                 wi = pe.portev_user;
 276                 assert(wi != NULL);
 277                 assert(fd == wi->wi_fd);