xref: /titanic_53/usr/src/cmd/svc/startd/wait.c (revision e39bb43de49ac848a58d7658501abd59bbbd3280)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*e39bb43dSrm88369  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * wait.c - asynchronous monitoring of "wait registered" start methods
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * Use event ports to poll on the set of fds representing the /proc/[pid]/psinfo
337c478bd9Sstevel@tonic-gate  * files.  If one of these fds returns an event, then we inform the restarter
347c478bd9Sstevel@tonic-gate  * that it has stopped.
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * The wait_info_list holds the series of processes currently being monitored
377c478bd9Sstevel@tonic-gate  * for exit.  The wi_fd member, which contains the file descriptor of the psinfo
387c478bd9Sstevel@tonic-gate  * file being polled upon ("event ported upon"), will be set to -1 if the file
397c478bd9Sstevel@tonic-gate  * descriptor is inactive (already closed or not yet opened).
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef _FILE_OFFSET_BITS
437c478bd9Sstevel@tonic-gate #undef _FILE_OFFSET_BITS
447c478bd9Sstevel@tonic-gate #endif /* _FILE_OFFSET_BITS */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <sys/resource.h>
477c478bd9Sstevel@tonic-gate #include <sys/stat.h>
487c478bd9Sstevel@tonic-gate #include <sys/types.h>
497c478bd9Sstevel@tonic-gate #include <sys/uio.h>
507c478bd9Sstevel@tonic-gate #include <sys/wait.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <assert.h>
537c478bd9Sstevel@tonic-gate #include <errno.h>
547c478bd9Sstevel@tonic-gate #include <fcntl.h>
557c478bd9Sstevel@tonic-gate #include <libuutil.h>
567c478bd9Sstevel@tonic-gate #include <poll.h>
577c478bd9Sstevel@tonic-gate #include <port.h>
587c478bd9Sstevel@tonic-gate #include <pthread.h>
597c478bd9Sstevel@tonic-gate #include <procfs.h>
607c478bd9Sstevel@tonic-gate #include <string.h>
617c478bd9Sstevel@tonic-gate #include <stropts.h>
627c478bd9Sstevel@tonic-gate #include <unistd.h>
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #include "startd.h"
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	WAIT_FILES	262144		/* reasonably high maximum */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate static int port_fd;
697c478bd9Sstevel@tonic-gate static scf_handle_t *wait_hndl;
707c478bd9Sstevel@tonic-gate static struct rlimit init_fd_rlimit;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate static uu_list_pool_t *wait_info_pool;
737c478bd9Sstevel@tonic-gate static uu_list_t *wait_info_list;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static pthread_mutex_t wait_info_lock;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * void wait_remove(wait_info_t *, int)
797c478bd9Sstevel@tonic-gate  *   Remove the given wait_info structure from our list, performing various
807c478bd9Sstevel@tonic-gate  *   cleanup operations along the way.  If the direct flag is false (meaning
817c478bd9Sstevel@tonic-gate  *   that we are being called with from restarter instance list context), then
827c478bd9Sstevel@tonic-gate  *   notify the restarter that the associated instance has exited.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  *   Since we may no longer be the startd that started this process, we only are
857c478bd9Sstevel@tonic-gate  *   concerned with a waitpid(3C) failure if the wi_parent field is non-zero.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate static void
887c478bd9Sstevel@tonic-gate wait_remove(wait_info_t *wi, int direct)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	int status;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (waitpid(wi->wi_pid, &status, 0) == -1) {
937c478bd9Sstevel@tonic-gate 		if (wi->wi_parent)
947c478bd9Sstevel@tonic-gate 			log_framework(LOG_INFO,
957c478bd9Sstevel@tonic-gate 			    "instance %s waitpid failure: %s\n", wi->wi_fmri,
967c478bd9Sstevel@tonic-gate 			    strerror(errno));
977c478bd9Sstevel@tonic-gate 	} else {
987c478bd9Sstevel@tonic-gate 		if (WEXITSTATUS(status) != 0) {
997c478bd9Sstevel@tonic-gate 			log_framework(LOG_NOTICE,
1007c478bd9Sstevel@tonic-gate 			    "instance %s exited with status %d\n", wi->wi_fmri,
1017c478bd9Sstevel@tonic-gate 			    WEXITSTATUS(status));
1027c478bd9Sstevel@tonic-gate 		}
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
106*e39bb43dSrm88369 	if (wi->wi_fd != -1) {
107*e39bb43dSrm88369 		startd_close(wi->wi_fd);
108*e39bb43dSrm88369 		wi->wi_fd = -1;
109*e39bb43dSrm88369 	}
1107c478bd9Sstevel@tonic-gate 	uu_list_remove(wait_info_list, wi);
1117c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	/*
1147c478bd9Sstevel@tonic-gate 	 * Make an attempt to clear out any utmpx record associated with this
1157c478bd9Sstevel@tonic-gate 	 * PID.
1167c478bd9Sstevel@tonic-gate 	 */
1177c478bd9Sstevel@tonic-gate 	utmpx_mark_dead(wi->wi_pid, status, B_FALSE);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	if (!direct) {
1207c478bd9Sstevel@tonic-gate 		/*
1217c478bd9Sstevel@tonic-gate 		 * Bind wait_hndl lazily.
1227c478bd9Sstevel@tonic-gate 		 */
1237c478bd9Sstevel@tonic-gate 		if (wait_hndl == NULL) {
1247c478bd9Sstevel@tonic-gate 			for (wait_hndl =
1257c478bd9Sstevel@tonic-gate 			    libscf_handle_create_bound(SCF_VERSION);
1267c478bd9Sstevel@tonic-gate 			    wait_hndl == NULL;
1277c478bd9Sstevel@tonic-gate 			    wait_hndl =
1287c478bd9Sstevel@tonic-gate 			    libscf_handle_create_bound(SCF_VERSION)) {
1297c478bd9Sstevel@tonic-gate 				log_error(LOG_INFO, "[wait_remove] Unable to "
1307c478bd9Sstevel@tonic-gate 				    "bind a new repository handle: %s\n",
1317c478bd9Sstevel@tonic-gate 				    scf_strerror(scf_error()));
1327c478bd9Sstevel@tonic-gate 				(void) sleep(2);
1337c478bd9Sstevel@tonic-gate 			}
1347c478bd9Sstevel@tonic-gate 		}
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 		log_framework(LOG_DEBUG,
1377c478bd9Sstevel@tonic-gate 		    "wait_remove requesting stop of %s\n", wi->wi_fmri);
1387c478bd9Sstevel@tonic-gate 		(void) stop_instance_fmri(wait_hndl, wi->wi_fmri, RSTOP_EXIT);
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	uu_list_node_fini(wi, &wi->wi_link, wait_info_pool);
1427c478bd9Sstevel@tonic-gate 	startd_free(wi, sizeof (wait_info_t));
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate  * int wait_register(pid_t, char *, int, int)
1477c478bd9Sstevel@tonic-gate  *   wait_register is called after we have called fork(2), and know which pid we
1487c478bd9Sstevel@tonic-gate  *   wish to monitor.  However, since the child may have already exited by the
1497c478bd9Sstevel@tonic-gate  *   time we are called, we must handle the error cases from open(2)
1507c478bd9Sstevel@tonic-gate  *   appropriately.  The am_parent flag is recorded to handle waitpid(2)
1517c478bd9Sstevel@tonic-gate  *   behaviour on removal; similarly, the direct flag is passed through to a
1527c478bd9Sstevel@tonic-gate  *   potential call to wait_remove() to govern its behaviour in different
1537c478bd9Sstevel@tonic-gate  *   contexts.
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  *   Returns 0 if registration successful, 1 if child pid did not exist, and -1
1567c478bd9Sstevel@tonic-gate  *   if a different error occurred.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate int
1597c478bd9Sstevel@tonic-gate wait_register(pid_t pid, const char *inst_fmri, int am_parent, int direct)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	char *fname = uu_msprintf("/proc/%ld/psinfo", pid);
1627c478bd9Sstevel@tonic-gate 	int fd;
1637c478bd9Sstevel@tonic-gate 	wait_info_t *wi;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	assert(pid != 0);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (fname == NULL)
1687c478bd9Sstevel@tonic-gate 		return (-1);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	wi = startd_alloc(sizeof (wait_info_t));
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	uu_list_node_init(wi, &wi->wi_link, wait_info_pool);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	wi->wi_fd = -1;
1757c478bd9Sstevel@tonic-gate 	wi->wi_pid = pid;
1767c478bd9Sstevel@tonic-gate 	wi->wi_fmri = inst_fmri;
1777c478bd9Sstevel@tonic-gate 	wi->wi_parent = am_parent;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
1807c478bd9Sstevel@tonic-gate 	(void) uu_list_insert_before(wait_info_list, NULL, wi);
1817c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	if ((fd = open(fname, O_RDONLY)) == -1) {
1847c478bd9Sstevel@tonic-gate 		if (errno == ENOENT) {
1857c478bd9Sstevel@tonic-gate 			/*
1867c478bd9Sstevel@tonic-gate 			 * Child has already exited.
1877c478bd9Sstevel@tonic-gate 			 */
1887c478bd9Sstevel@tonic-gate 			wait_remove(wi, direct);
1897c478bd9Sstevel@tonic-gate 			uu_free(fname);
1907c478bd9Sstevel@tonic-gate 			return (1);
1917c478bd9Sstevel@tonic-gate 		} else {
1927c478bd9Sstevel@tonic-gate 			log_error(LOG_WARNING,
1937c478bd9Sstevel@tonic-gate 			    "open %s failed; not monitoring %s: %s\n", fname,
1947c478bd9Sstevel@tonic-gate 			    inst_fmri, strerror(errno));
1957c478bd9Sstevel@tonic-gate 			uu_free(fname);
1967c478bd9Sstevel@tonic-gate 			return (-1);
1977c478bd9Sstevel@tonic-gate 		}
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	uu_free(fname);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	wi->wi_fd = fd;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi)) {
2057c478bd9Sstevel@tonic-gate 		log_error(LOG_WARNING,
2067c478bd9Sstevel@tonic-gate 		    "initial port_association of %d / %s failed: %s\n", fd,
2077c478bd9Sstevel@tonic-gate 		    inst_fmri, strerror(errno));
2087c478bd9Sstevel@tonic-gate 		return (-1);
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	log_framework(LOG_DEBUG, "monitoring PID %ld on fd %d (%s)\n", pid, fd,
2127c478bd9Sstevel@tonic-gate 	    inst_fmri);
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	return (0);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2187c478bd9Sstevel@tonic-gate void *
2197c478bd9Sstevel@tonic-gate wait_thread(void *args)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	for (;;) {
2227c478bd9Sstevel@tonic-gate 		port_event_t pe;
2237c478bd9Sstevel@tonic-gate 		int fd;
2247c478bd9Sstevel@tonic-gate 		wait_info_t *wi;
2257c478bd9Sstevel@tonic-gate 
226*e39bb43dSrm88369 		if (port_get(port_fd, &pe, NULL) != 0) {
227*e39bb43dSrm88369 			if (errno == EINTR)
2287c478bd9Sstevel@tonic-gate 				continue;
229*e39bb43dSrm88369 			else {
2307c478bd9Sstevel@tonic-gate 				log_error(LOG_WARNING,
231*e39bb43dSrm88369 				    "port_get() failed with %s\n",
232*e39bb43dSrm88369 				    strerror(errno));
233*e39bb43dSrm88369 				bad_error("port_get", errno);
234*e39bb43dSrm88369 			}
235*e39bb43dSrm88369 		}
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 		fd = pe.portev_object;
2387c478bd9Sstevel@tonic-gate 		wi = pe.portev_user;
239*e39bb43dSrm88369 		assert(wi != NULL);
240*e39bb43dSrm88369 		assert(fd == wi->wi_fd);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 		if ((pe.portev_events & POLLHUP) == POLLHUP) {
2437c478bd9Sstevel@tonic-gate 			psinfo_t psi;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 			if (lseek(fd, 0, SEEK_SET) != 0 ||
2467c478bd9Sstevel@tonic-gate 			    read(fd, &psi, sizeof (psinfo_t)) !=
2477c478bd9Sstevel@tonic-gate 			    sizeof (psinfo_t)) {
2487c478bd9Sstevel@tonic-gate 				log_framework(LOG_WARNING,
2497c478bd9Sstevel@tonic-gate 				    "couldn't get psinfo data for %s (%s); "
2507c478bd9Sstevel@tonic-gate 				    "assuming failed\n", wi->wi_fmri,
2517c478bd9Sstevel@tonic-gate 				    strerror(errno));
2527c478bd9Sstevel@tonic-gate 				    goto err_remove;
2537c478bd9Sstevel@tonic-gate 			}
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 			if (psi.pr_nlwp != 0 ||
2567c478bd9Sstevel@tonic-gate 			    psi.pr_nzomb != 0 ||
2577c478bd9Sstevel@tonic-gate 			    psi.pr_lwp.pr_lwpid != 0) {
2587c478bd9Sstevel@tonic-gate 				/*
2597c478bd9Sstevel@tonic-gate 				 * We have determined, in accordance with the
2607c478bd9Sstevel@tonic-gate 				 * definition in proc(4), this process is not a
2617c478bd9Sstevel@tonic-gate 				 * zombie.  Reassociate.
2627c478bd9Sstevel@tonic-gate 				 */
2637c478bd9Sstevel@tonic-gate 				if (port_associate(port_fd, PORT_SOURCE_FD, fd,
2647c478bd9Sstevel@tonic-gate 					0, wi))
2657c478bd9Sstevel@tonic-gate 					log_error(LOG_WARNING,
2667c478bd9Sstevel@tonic-gate 					    "port_association of %d / %s "
2677c478bd9Sstevel@tonic-gate 					    "failed\n", fd, wi->wi_fmri);
2687c478bd9Sstevel@tonic-gate 				continue;
2697c478bd9Sstevel@tonic-gate 			}
2707c478bd9Sstevel@tonic-gate 		} else if (
2717c478bd9Sstevel@tonic-gate 		    (pe.portev_events & POLLERR) == 0) {
2727c478bd9Sstevel@tonic-gate 			if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi))
2737c478bd9Sstevel@tonic-gate 				log_error(LOG_WARNING,
2747c478bd9Sstevel@tonic-gate 				    "port_association of %d / %s "
2757c478bd9Sstevel@tonic-gate 				    "failed\n", fd, wi->wi_fmri);
2767c478bd9Sstevel@tonic-gate 			continue;
2777c478bd9Sstevel@tonic-gate 		}
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate err_remove:
2807c478bd9Sstevel@tonic-gate 		wait_remove(wi, 0);
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	/*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate void
2877c478bd9Sstevel@tonic-gate wait_prefork()
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate void
2937c478bd9Sstevel@tonic-gate wait_postfork(pid_t pid)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate 	wait_info_t *wi;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (pid != 0)
3007c478bd9Sstevel@tonic-gate 		return;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/*
3037c478bd9Sstevel@tonic-gate 	 * Close all of the child's wait-related fds.  The wait_thread() is
3047c478bd9Sstevel@tonic-gate 	 * gone, so no need to worry about returning events.  We always exec(2)
3057c478bd9Sstevel@tonic-gate 	 * after a fork request, so we needn't free the list elements
3067c478bd9Sstevel@tonic-gate 	 * themselves.
3077c478bd9Sstevel@tonic-gate 	 */
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	for (wi = uu_list_first(wait_info_list);
3107c478bd9Sstevel@tonic-gate 	    wi != NULL;
3117c478bd9Sstevel@tonic-gate 	    wi = uu_list_next(wait_info_list, wi)) {
3127c478bd9Sstevel@tonic-gate 		if (wi->wi_fd != -1)
3137c478bd9Sstevel@tonic-gate 			startd_close(wi->wi_fd);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	startd_close(port_fd);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	(void) setrlimit(RLIMIT_NOFILE, &init_fd_rlimit);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate void
3227c478bd9Sstevel@tonic-gate wait_init()
3237c478bd9Sstevel@tonic-gate {
3247c478bd9Sstevel@tonic-gate 	struct rlimit fd_new;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	(void) getrlimit(RLIMIT_NOFILE, &init_fd_rlimit);
3277c478bd9Sstevel@tonic-gate 	(void) getrlimit(RLIMIT_NOFILE, &fd_new);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	fd_new.rlim_max = fd_new.rlim_cur = WAIT_FILES;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	(void) setrlimit(RLIMIT_NOFILE, &fd_new);
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	if ((port_fd = port_create()) == -1)
3347c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't port_create");
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	wait_info_pool = uu_list_pool_create("wait_info", sizeof (wait_info_t),
3377c478bd9Sstevel@tonic-gate 	    offsetof(wait_info_t, wi_link), NULL, UU_LIST_POOL_DEBUG);
3387c478bd9Sstevel@tonic-gate 	if (wait_info_pool == NULL)
3397c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't create wait_info_pool");
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	wait_info_list = uu_list_create(wait_info_pool, wait_info_list, 0);
3427c478bd9Sstevel@tonic-gate 	if (wait_info_list == NULL)
3437c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't create wait_info_list");
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&wait_info_lock, &mutex_attrs);
3467c478bd9Sstevel@tonic-gate }
347