xref: /titanic_53/usr/src/cmd/svc/startd/wait.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * wait.c - asynchronous monitoring of "wait registered" start methods
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * Use event ports to poll on the set of fds representing the /proc/[pid]/psinfo
33*7c478bd9Sstevel@tonic-gate  * files.  If one of these fds returns an event, then we inform the restarter
34*7c478bd9Sstevel@tonic-gate  * that it has stopped.
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  * The wait_info_list holds the series of processes currently being monitored
37*7c478bd9Sstevel@tonic-gate  * for exit.  The wi_fd member, which contains the file descriptor of the psinfo
38*7c478bd9Sstevel@tonic-gate  * file being polled upon ("event ported upon"), will be set to -1 if the file
39*7c478bd9Sstevel@tonic-gate  * descriptor is inactive (already closed or not yet opened).
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #ifdef _FILE_OFFSET_BITS
43*7c478bd9Sstevel@tonic-gate #undef _FILE_OFFSET_BITS
44*7c478bd9Sstevel@tonic-gate #endif /* _FILE_OFFSET_BITS */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #include <sys/resource.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/uio.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #include <assert.h>
53*7c478bd9Sstevel@tonic-gate #include <errno.h>
54*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
55*7c478bd9Sstevel@tonic-gate #include <libuutil.h>
56*7c478bd9Sstevel@tonic-gate #include <poll.h>
57*7c478bd9Sstevel@tonic-gate #include <port.h>
58*7c478bd9Sstevel@tonic-gate #include <pthread.h>
59*7c478bd9Sstevel@tonic-gate #include <procfs.h>
60*7c478bd9Sstevel@tonic-gate #include <string.h>
61*7c478bd9Sstevel@tonic-gate #include <stropts.h>
62*7c478bd9Sstevel@tonic-gate #include <unistd.h>
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #include "startd.h"
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #define	WAIT_FILES	262144		/* reasonably high maximum */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate static int port_fd;
69*7c478bd9Sstevel@tonic-gate static scf_handle_t *wait_hndl;
70*7c478bd9Sstevel@tonic-gate static struct rlimit init_fd_rlimit;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate static uu_list_pool_t *wait_info_pool;
73*7c478bd9Sstevel@tonic-gate static uu_list_t *wait_info_list;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate static pthread_mutex_t wait_info_lock;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * void wait_remove(wait_info_t *, int)
79*7c478bd9Sstevel@tonic-gate  *   Remove the given wait_info structure from our list, performing various
80*7c478bd9Sstevel@tonic-gate  *   cleanup operations along the way.  If the direct flag is false (meaning
81*7c478bd9Sstevel@tonic-gate  *   that we are being called with from restarter instance list context), then
82*7c478bd9Sstevel@tonic-gate  *   notify the restarter that the associated instance has exited.
83*7c478bd9Sstevel@tonic-gate  *
84*7c478bd9Sstevel@tonic-gate  *   Since we may no longer be the startd that started this process, we only are
85*7c478bd9Sstevel@tonic-gate  *   concerned with a waitpid(3C) failure if the wi_parent field is non-zero.
86*7c478bd9Sstevel@tonic-gate  */
87*7c478bd9Sstevel@tonic-gate static void
88*7c478bd9Sstevel@tonic-gate wait_remove(wait_info_t *wi, int direct)
89*7c478bd9Sstevel@tonic-gate {
90*7c478bd9Sstevel@tonic-gate 	int status;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	if (waitpid(wi->wi_pid, &status, 0) == -1) {
93*7c478bd9Sstevel@tonic-gate 		if (wi->wi_parent)
94*7c478bd9Sstevel@tonic-gate 			log_framework(LOG_INFO,
95*7c478bd9Sstevel@tonic-gate 			    "instance %s waitpid failure: %s\n", wi->wi_fmri,
96*7c478bd9Sstevel@tonic-gate 			    strerror(errno));
97*7c478bd9Sstevel@tonic-gate 	} else {
98*7c478bd9Sstevel@tonic-gate 		if (WEXITSTATUS(status) != 0) {
99*7c478bd9Sstevel@tonic-gate 			log_framework(LOG_NOTICE,
100*7c478bd9Sstevel@tonic-gate 			    "instance %s exited with status %d\n", wi->wi_fmri,
101*7c478bd9Sstevel@tonic-gate 			    WEXITSTATUS(status));
102*7c478bd9Sstevel@tonic-gate 		}
103*7c478bd9Sstevel@tonic-gate 	}
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
106*7c478bd9Sstevel@tonic-gate 	uu_list_remove(wait_info_list, wi);
107*7c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	/*
110*7c478bd9Sstevel@tonic-gate 	 * Make an attempt to clear out any utmpx record associated with this
111*7c478bd9Sstevel@tonic-gate 	 * PID.
112*7c478bd9Sstevel@tonic-gate 	 */
113*7c478bd9Sstevel@tonic-gate 	utmpx_mark_dead(wi->wi_pid, status, B_FALSE);
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	if (!direct) {
116*7c478bd9Sstevel@tonic-gate 		/*
117*7c478bd9Sstevel@tonic-gate 		 * Bind wait_hndl lazily.
118*7c478bd9Sstevel@tonic-gate 		 */
119*7c478bd9Sstevel@tonic-gate 		if (wait_hndl == NULL) {
120*7c478bd9Sstevel@tonic-gate 			for (wait_hndl =
121*7c478bd9Sstevel@tonic-gate 			    libscf_handle_create_bound(SCF_VERSION);
122*7c478bd9Sstevel@tonic-gate 			    wait_hndl == NULL;
123*7c478bd9Sstevel@tonic-gate 			    wait_hndl =
124*7c478bd9Sstevel@tonic-gate 			    libscf_handle_create_bound(SCF_VERSION)) {
125*7c478bd9Sstevel@tonic-gate 				log_error(LOG_INFO, "[wait_remove] Unable to "
126*7c478bd9Sstevel@tonic-gate 				    "bind a new repository handle: %s\n",
127*7c478bd9Sstevel@tonic-gate 				    scf_strerror(scf_error()));
128*7c478bd9Sstevel@tonic-gate 				(void) sleep(2);
129*7c478bd9Sstevel@tonic-gate 			}
130*7c478bd9Sstevel@tonic-gate 		}
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 		log_framework(LOG_DEBUG,
133*7c478bd9Sstevel@tonic-gate 		    "wait_remove requesting stop of %s\n", wi->wi_fmri);
134*7c478bd9Sstevel@tonic-gate 		(void) stop_instance_fmri(wait_hndl, wi->wi_fmri, RSTOP_EXIT);
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	uu_list_node_fini(wi, &wi->wi_link, wait_info_pool);
138*7c478bd9Sstevel@tonic-gate 	startd_free(wi, sizeof (wait_info_t));
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * int wait_register(pid_t, char *, int, int)
143*7c478bd9Sstevel@tonic-gate  *   wait_register is called after we have called fork(2), and know which pid we
144*7c478bd9Sstevel@tonic-gate  *   wish to monitor.  However, since the child may have already exited by the
145*7c478bd9Sstevel@tonic-gate  *   time we are called, we must handle the error cases from open(2)
146*7c478bd9Sstevel@tonic-gate  *   appropriately.  The am_parent flag is recorded to handle waitpid(2)
147*7c478bd9Sstevel@tonic-gate  *   behaviour on removal; similarly, the direct flag is passed through to a
148*7c478bd9Sstevel@tonic-gate  *   potential call to wait_remove() to govern its behaviour in different
149*7c478bd9Sstevel@tonic-gate  *   contexts.
150*7c478bd9Sstevel@tonic-gate  *
151*7c478bd9Sstevel@tonic-gate  *   Returns 0 if registration successful, 1 if child pid did not exist, and -1
152*7c478bd9Sstevel@tonic-gate  *   if a different error occurred.
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate int
155*7c478bd9Sstevel@tonic-gate wait_register(pid_t pid, const char *inst_fmri, int am_parent, int direct)
156*7c478bd9Sstevel@tonic-gate {
157*7c478bd9Sstevel@tonic-gate 	char *fname = uu_msprintf("/proc/%ld/psinfo", pid);
158*7c478bd9Sstevel@tonic-gate 	int fd;
159*7c478bd9Sstevel@tonic-gate 	wait_info_t *wi;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	assert(pid != 0);
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 	if (fname == NULL)
164*7c478bd9Sstevel@tonic-gate 		return (-1);
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	wi = startd_alloc(sizeof (wait_info_t));
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	uu_list_node_init(wi, &wi->wi_link, wait_info_pool);
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	wi->wi_fd = -1;
171*7c478bd9Sstevel@tonic-gate 	wi->wi_pid = pid;
172*7c478bd9Sstevel@tonic-gate 	wi->wi_fmri = inst_fmri;
173*7c478bd9Sstevel@tonic-gate 	wi->wi_parent = am_parent;
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
176*7c478bd9Sstevel@tonic-gate 	(void) uu_list_insert_before(wait_info_list, NULL, wi);
177*7c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	if ((fd = open(fname, O_RDONLY)) == -1) {
180*7c478bd9Sstevel@tonic-gate 		if (errno == ENOENT) {
181*7c478bd9Sstevel@tonic-gate 			/*
182*7c478bd9Sstevel@tonic-gate 			 * Child has already exited.
183*7c478bd9Sstevel@tonic-gate 			 */
184*7c478bd9Sstevel@tonic-gate 			wait_remove(wi, direct);
185*7c478bd9Sstevel@tonic-gate 			uu_free(fname);
186*7c478bd9Sstevel@tonic-gate 			return (1);
187*7c478bd9Sstevel@tonic-gate 		} else {
188*7c478bd9Sstevel@tonic-gate 			log_error(LOG_WARNING,
189*7c478bd9Sstevel@tonic-gate 			    "open %s failed; not monitoring %s: %s\n", fname,
190*7c478bd9Sstevel@tonic-gate 			    inst_fmri, strerror(errno));
191*7c478bd9Sstevel@tonic-gate 			uu_free(fname);
192*7c478bd9Sstevel@tonic-gate 			return (-1);
193*7c478bd9Sstevel@tonic-gate 		}
194*7c478bd9Sstevel@tonic-gate 	}
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 	uu_free(fname);
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 	wi->wi_fd = fd;
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 	if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi)) {
201*7c478bd9Sstevel@tonic-gate 		log_error(LOG_WARNING,
202*7c478bd9Sstevel@tonic-gate 		    "initial port_association of %d / %s failed: %s\n", fd,
203*7c478bd9Sstevel@tonic-gate 		    inst_fmri, strerror(errno));
204*7c478bd9Sstevel@tonic-gate 		return (-1);
205*7c478bd9Sstevel@tonic-gate 	}
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 	log_framework(LOG_DEBUG, "monitoring PID %ld on fd %d (%s)\n", pid, fd,
208*7c478bd9Sstevel@tonic-gate 	    inst_fmri);
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	return (0);
211*7c478bd9Sstevel@tonic-gate }
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
214*7c478bd9Sstevel@tonic-gate void *
215*7c478bd9Sstevel@tonic-gate wait_thread(void *args)
216*7c478bd9Sstevel@tonic-gate {
217*7c478bd9Sstevel@tonic-gate 	for (;;) {
218*7c478bd9Sstevel@tonic-gate 		port_event_t pe;
219*7c478bd9Sstevel@tonic-gate 		int fd;
220*7c478bd9Sstevel@tonic-gate 		wait_info_t *wi;
221*7c478bd9Sstevel@tonic-gate 		struct timespec ts;
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate 		ts.tv_sec = 1;
224*7c478bd9Sstevel@tonic-gate 		ts.tv_nsec = 0;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 		if (port_get(port_fd, &pe, &ts) == -1)
227*7c478bd9Sstevel@tonic-gate 			if (errno == EINTR || errno == ETIME)
228*7c478bd9Sstevel@tonic-gate 				continue;
229*7c478bd9Sstevel@tonic-gate 			else
230*7c478bd9Sstevel@tonic-gate 				log_error(LOG_WARNING,
231*7c478bd9Sstevel@tonic-gate 				    "port_get returned %s\n", strerror(errno));
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 		fd = pe.portev_object;
234*7c478bd9Sstevel@tonic-gate 		wi = pe.portev_user;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 		if ((pe.portev_events & POLLHUP) == POLLHUP) {
237*7c478bd9Sstevel@tonic-gate 			psinfo_t psi;
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 			if (lseek(fd, 0, SEEK_SET) != 0 ||
240*7c478bd9Sstevel@tonic-gate 			    read(fd, &psi, sizeof (psinfo_t)) !=
241*7c478bd9Sstevel@tonic-gate 			    sizeof (psinfo_t)) {
242*7c478bd9Sstevel@tonic-gate 				log_framework(LOG_WARNING,
243*7c478bd9Sstevel@tonic-gate 				    "couldn't get psinfo data for %s (%s); "
244*7c478bd9Sstevel@tonic-gate 				    "assuming failed\n", wi->wi_fmri,
245*7c478bd9Sstevel@tonic-gate 				    strerror(errno));
246*7c478bd9Sstevel@tonic-gate 				    goto err_remove;
247*7c478bd9Sstevel@tonic-gate 			}
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate 			if (psi.pr_nlwp != 0 ||
250*7c478bd9Sstevel@tonic-gate 			    psi.pr_nzomb != 0 ||
251*7c478bd9Sstevel@tonic-gate 			    psi.pr_lwp.pr_lwpid != 0) {
252*7c478bd9Sstevel@tonic-gate 				/*
253*7c478bd9Sstevel@tonic-gate 				 * We have determined, in accordance with the
254*7c478bd9Sstevel@tonic-gate 				 * definition in proc(4), this process is not a
255*7c478bd9Sstevel@tonic-gate 				 * zombie.  Reassociate.
256*7c478bd9Sstevel@tonic-gate 				 */
257*7c478bd9Sstevel@tonic-gate 				if (port_associate(port_fd, PORT_SOURCE_FD, fd,
258*7c478bd9Sstevel@tonic-gate 					0, wi))
259*7c478bd9Sstevel@tonic-gate 					log_error(LOG_WARNING,
260*7c478bd9Sstevel@tonic-gate 					    "port_association of %d / %s "
261*7c478bd9Sstevel@tonic-gate 					    "failed\n", fd, wi->wi_fmri);
262*7c478bd9Sstevel@tonic-gate 				continue;
263*7c478bd9Sstevel@tonic-gate 			}
264*7c478bd9Sstevel@tonic-gate 		} else if (
265*7c478bd9Sstevel@tonic-gate 		    (pe.portev_events & POLLERR) == 0) {
266*7c478bd9Sstevel@tonic-gate 			if (port_associate(port_fd, PORT_SOURCE_FD, fd, 0, wi))
267*7c478bd9Sstevel@tonic-gate 				log_error(LOG_WARNING,
268*7c478bd9Sstevel@tonic-gate 				    "port_association of %d / %s "
269*7c478bd9Sstevel@tonic-gate 				    "failed\n", fd, wi->wi_fmri);
270*7c478bd9Sstevel@tonic-gate 			continue;
271*7c478bd9Sstevel@tonic-gate 		}
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate err_remove:
274*7c478bd9Sstevel@tonic-gate 		startd_close(fd);
275*7c478bd9Sstevel@tonic-gate 		wi->wi_fd = -1;
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 		wait_remove(wi, 0);
278*7c478bd9Sstevel@tonic-gate 	}
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 	/*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate void
284*7c478bd9Sstevel@tonic-gate wait_prefork()
285*7c478bd9Sstevel@tonic-gate {
286*7c478bd9Sstevel@tonic-gate 	MUTEX_LOCK(&wait_info_lock);
287*7c478bd9Sstevel@tonic-gate }
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate void
290*7c478bd9Sstevel@tonic-gate wait_postfork(pid_t pid)
291*7c478bd9Sstevel@tonic-gate {
292*7c478bd9Sstevel@tonic-gate 	wait_info_t *wi;
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 	MUTEX_UNLOCK(&wait_info_lock);
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	if (pid != 0)
297*7c478bd9Sstevel@tonic-gate 		return;
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 	/*
300*7c478bd9Sstevel@tonic-gate 	 * Close all of the child's wait-related fds.  The wait_thread() is
301*7c478bd9Sstevel@tonic-gate 	 * gone, so no need to worry about returning events.  We always exec(2)
302*7c478bd9Sstevel@tonic-gate 	 * after a fork request, so we needn't free the list elements
303*7c478bd9Sstevel@tonic-gate 	 * themselves.
304*7c478bd9Sstevel@tonic-gate 	 */
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 	for (wi = uu_list_first(wait_info_list);
307*7c478bd9Sstevel@tonic-gate 	    wi != NULL;
308*7c478bd9Sstevel@tonic-gate 	    wi = uu_list_next(wait_info_list, wi)) {
309*7c478bd9Sstevel@tonic-gate 		if (wi->wi_fd != -1)
310*7c478bd9Sstevel@tonic-gate 			startd_close(wi->wi_fd);
311*7c478bd9Sstevel@tonic-gate 	}
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	startd_close(port_fd);
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 	(void) setrlimit(RLIMIT_NOFILE, &init_fd_rlimit);
316*7c478bd9Sstevel@tonic-gate }
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate void
319*7c478bd9Sstevel@tonic-gate wait_init()
320*7c478bd9Sstevel@tonic-gate {
321*7c478bd9Sstevel@tonic-gate 	struct rlimit fd_new;
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 	(void) getrlimit(RLIMIT_NOFILE, &init_fd_rlimit);
324*7c478bd9Sstevel@tonic-gate 	(void) getrlimit(RLIMIT_NOFILE, &fd_new);
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 	fd_new.rlim_max = fd_new.rlim_cur = WAIT_FILES;
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	(void) setrlimit(RLIMIT_NOFILE, &fd_new);
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	if ((port_fd = port_create()) == -1)
331*7c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't port_create");
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	wait_info_pool = uu_list_pool_create("wait_info", sizeof (wait_info_t),
334*7c478bd9Sstevel@tonic-gate 	    offsetof(wait_info_t, wi_link), NULL, UU_LIST_POOL_DEBUG);
335*7c478bd9Sstevel@tonic-gate 	if (wait_info_pool == NULL)
336*7c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't create wait_info_pool");
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	wait_info_list = uu_list_create(wait_info_pool, wait_info_list, 0);
339*7c478bd9Sstevel@tonic-gate 	if (wait_info_list == NULL)
340*7c478bd9Sstevel@tonic-gate 		uu_die("wait_init couldn't create wait_info_list");
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&wait_info_lock, &mutex_attrs);
343*7c478bd9Sstevel@tonic-gate }
344