xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.lib/inetd/wait.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * This file contains a set of routines used to perform wait based method
31*0Sstevel@tonic-gate  * reaping.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <wait.h>
35*0Sstevel@tonic-gate #include <sys/param.h>
36*0Sstevel@tonic-gate #include <fcntl.h>
37*0Sstevel@tonic-gate #include <libcontract.h>
38*0Sstevel@tonic-gate #include <errno.h>
39*0Sstevel@tonic-gate #include <libintl.h>
40*0Sstevel@tonic-gate #include <unistd.h>
41*0Sstevel@tonic-gate #include <stdlib.h>
42*0Sstevel@tonic-gate #include <string.h>
43*0Sstevel@tonic-gate #include <sys/resource.h>
44*0Sstevel@tonic-gate #include "inetd_impl.h"
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /* inetd's open file limit, set in method_init() */
47*0Sstevel@tonic-gate #define	INETD_NOFILE_LIMIT RLIM_INFINITY
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /* structure used to represent an active method process */
50*0Sstevel@tonic-gate typedef struct {
51*0Sstevel@tonic-gate 	int			fd;	/* fd of process's /proc psinfo file */
52*0Sstevel@tonic-gate 	/* associated contract id if known, else -1 */
53*0Sstevel@tonic-gate 	ctid_t			cid;
54*0Sstevel@tonic-gate 	pid_t			pid;
55*0Sstevel@tonic-gate 	instance_t		*inst;	/* pointer to associated instance */
56*0Sstevel@tonic-gate 	instance_method_t	method;	/* the method type running */
57*0Sstevel@tonic-gate 	uu_list_node_t		link;
58*0Sstevel@tonic-gate } method_el_t;
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate static void unregister_method(method_el_t *);
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /* list of currently executing method processes */
65*0Sstevel@tonic-gate static uu_list_pool_t		*method_pool = NULL;
66*0Sstevel@tonic-gate static uu_list_t		*method_list = NULL;
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * File limit saved during initialization before modification, so that it can
70*0Sstevel@tonic-gate  * be reverted back to for inetd's exec'd methods.
71*0Sstevel@tonic-gate  */
72*0Sstevel@tonic-gate static struct rlimit		saved_file_limit;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate  * Setup structures used for method termination monitoring.
76*0Sstevel@tonic-gate  * Returns -1 if an allocation failure occurred, else 0.
77*0Sstevel@tonic-gate  */
78*0Sstevel@tonic-gate int
79*0Sstevel@tonic-gate method_init(void)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate 	struct rlimit rl;
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 	debug_msg("Entering method_init");
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 	/*
86*0Sstevel@tonic-gate 	 * Save aside the old file limit and impose one large enough to support
87*0Sstevel@tonic-gate 	 * all the /proc file handles we could have open.
88*0Sstevel@tonic-gate 	 */
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	(void) getrlimit(RLIMIT_NOFILE, &saved_file_limit);
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	rl.rlim_cur = rl.rlim_max = INETD_NOFILE_LIMIT;
93*0Sstevel@tonic-gate 	if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
94*0Sstevel@tonic-gate 		error_msg("Failed to set file limit: %s", strerror(errno));
95*0Sstevel@tonic-gate 		return (-1);
96*0Sstevel@tonic-gate 	}
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 	if ((method_pool = uu_list_pool_create("method_pool",
99*0Sstevel@tonic-gate 	    sizeof (method_el_t), offsetof(method_el_t, link), NULL,
100*0Sstevel@tonic-gate 	    UU_LIST_POOL_DEBUG)) == NULL) {
101*0Sstevel@tonic-gate 		error_msg("%s: %s", gettext("Failed to create method pool"),
102*0Sstevel@tonic-gate 		    uu_strerror(uu_error()));
103*0Sstevel@tonic-gate 		return (-1);
104*0Sstevel@tonic-gate 	}
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate 	if ((method_list = uu_list_create(method_pool, NULL, 0)) == NULL) {
107*0Sstevel@tonic-gate 		error_msg("%s: %s",
108*0Sstevel@tonic-gate 		    gettext("Failed to create method list"),
109*0Sstevel@tonic-gate 		    uu_strerror(uu_error()));
110*0Sstevel@tonic-gate 		/* let method_fini() clean-up */
111*0Sstevel@tonic-gate 		return (-1);
112*0Sstevel@tonic-gate 	}
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate 	return (0);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate /*
118*0Sstevel@tonic-gate  * Tear-down structures created in method_init().
119*0Sstevel@tonic-gate  */
120*0Sstevel@tonic-gate void
121*0Sstevel@tonic-gate method_fini(void)
122*0Sstevel@tonic-gate {
123*0Sstevel@tonic-gate 	debug_msg("Entering method_fini");
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 	if (method_list != NULL) {
126*0Sstevel@tonic-gate 		method_el_t *me;
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 		while ((me = uu_list_first(method_list)) != NULL)
129*0Sstevel@tonic-gate 			unregister_method(me);
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 		(void) uu_list_destroy(method_list);
132*0Sstevel@tonic-gate 		method_list = NULL;
133*0Sstevel@tonic-gate 	}
134*0Sstevel@tonic-gate 	if (method_pool != NULL) {
135*0Sstevel@tonic-gate 		(void) uu_list_pool_destroy(method_pool);
136*0Sstevel@tonic-gate 		method_pool = NULL;
137*0Sstevel@tonic-gate 	}
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate 	/* revert file limit */
140*0Sstevel@tonic-gate 	method_preexec();
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate /*
144*0Sstevel@tonic-gate  * Revert file limit back to pre-initialization one. This shouldn't fail as
145*0Sstevel@tonic-gate  * long as its called *after* descriptor cleanup.
146*0Sstevel@tonic-gate  */
147*0Sstevel@tonic-gate void
148*0Sstevel@tonic-gate method_preexec(void)
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate 	(void) setrlimit(RLIMIT_NOFILE, &saved_file_limit);
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate  * Callback function that handles the timeout of an instance's method.
156*0Sstevel@tonic-gate  * 'arg' points at the method_el_t representing the method.
157*0Sstevel@tonic-gate  */
158*0Sstevel@tonic-gate /* ARGSUSED0 */
159*0Sstevel@tonic-gate static void
160*0Sstevel@tonic-gate method_timeout(iu_tq_t *tq, void *arg)
161*0Sstevel@tonic-gate {
162*0Sstevel@tonic-gate 	method_el_t *mp = arg;
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate 	error_msg(gettext("The %s method of instance %s timed-out"),
165*0Sstevel@tonic-gate 	    methods[mp->method].name, mp->inst->fmri);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 	mp->inst->timer_id = -1;
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	if (mp->method == IM_START) {
170*0Sstevel@tonic-gate 		process_start_term(mp->inst);
171*0Sstevel@tonic-gate 	} else {
172*0Sstevel@tonic-gate 		process_non_start_term(mp->inst, IMRET_FAILURE);
173*0Sstevel@tonic-gate 	}
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	unregister_method(mp);
176*0Sstevel@tonic-gate }
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate /*
179*0Sstevel@tonic-gate  * Registers the attributes of a running method passed as arguments so that
180*0Sstevel@tonic-gate  * the method's termination is noticed and any further processing of the
181*0Sstevel@tonic-gate  * associated instance is carried out. The function also sets up any
182*0Sstevel@tonic-gate  * necessary timers so we can detect hung methods.
183*0Sstevel@tonic-gate  * Returns -1 if either it failed to open the /proc psinfo file which is used
184*0Sstevel@tonic-gate  * to monitor the method process, it failed to setup a required timer or
185*0Sstevel@tonic-gate  * memory allocation failed; else 0.
186*0Sstevel@tonic-gate  */
187*0Sstevel@tonic-gate int
188*0Sstevel@tonic-gate register_method(instance_t *ins, pid_t pid, ctid_t cid, instance_method_t mthd)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate 	char		path[MAXPATHLEN];
191*0Sstevel@tonic-gate 	int		fd;
192*0Sstevel@tonic-gate 	method_el_t	*me;
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 	debug_msg("Entering register_method: inst: %s, pid: %d, mthd: %s",
195*0Sstevel@tonic-gate 	    ins->fmri, pid, methods[mthd].name);
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	/* open /proc psinfo file of process to listen for POLLHUP events on */
198*0Sstevel@tonic-gate 	(void) snprintf(path, sizeof (path), "/proc/%u/psinfo", pid);
199*0Sstevel@tonic-gate 	for (;;) {
200*0Sstevel@tonic-gate 		if ((fd = open(path, O_RDONLY)) >= 0) {
201*0Sstevel@tonic-gate 			break;
202*0Sstevel@tonic-gate 		} else if (errno != EINTR) {
203*0Sstevel@tonic-gate 			/*
204*0Sstevel@tonic-gate 			 * Don't output an error for ENOENT; we get this
205*0Sstevel@tonic-gate 			 * if a method has gone away whilst we were stopped,
206*0Sstevel@tonic-gate 			 * and we're now trying to re-listen for it.
207*0Sstevel@tonic-gate 			 */
208*0Sstevel@tonic-gate 			if (errno != ENOENT) {
209*0Sstevel@tonic-gate 				error_msg(gettext("Failed to open %s: %s"),
210*0Sstevel@tonic-gate 				    path, strerror(errno));
211*0Sstevel@tonic-gate 			}
212*0Sstevel@tonic-gate 			return (-1);
213*0Sstevel@tonic-gate 		}
214*0Sstevel@tonic-gate 	}
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate 	/* add method record to in-memory list */
217*0Sstevel@tonic-gate 	if ((me = calloc(1, sizeof (method_el_t))) == NULL) {
218*0Sstevel@tonic-gate 		error_msg(strerror(errno));
219*0Sstevel@tonic-gate 		(void) close(fd);
220*0Sstevel@tonic-gate 		return (-1);
221*0Sstevel@tonic-gate 	}
222*0Sstevel@tonic-gate 	me->fd = fd;
223*0Sstevel@tonic-gate 	me->inst = (instance_t *)ins;
224*0Sstevel@tonic-gate 	me->method = mthd;
225*0Sstevel@tonic-gate 	me->pid = pid;
226*0Sstevel@tonic-gate 	me->cid = cid;
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 	/* register a timeout for the method, if required */
229*0Sstevel@tonic-gate 	if (mthd != IM_START) {
230*0Sstevel@tonic-gate 		method_info_t *mi = ins->config->methods[mthd];
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate 		if (mi->timeout > 0) {
233*0Sstevel@tonic-gate 			assert(ins->timer_id == -1);
234*0Sstevel@tonic-gate 			ins->timer_id = iu_schedule_timer(timer_queue,
235*0Sstevel@tonic-gate 			    mi->timeout, method_timeout, me);
236*0Sstevel@tonic-gate 			if (ins->timer_id == -1) {
237*0Sstevel@tonic-gate 				error_msg(gettext(
238*0Sstevel@tonic-gate 				    "Failed to schedule method timeout"));
239*0Sstevel@tonic-gate 				free(me);
240*0Sstevel@tonic-gate 				(void) close(fd);
241*0Sstevel@tonic-gate 				return (-1);
242*0Sstevel@tonic-gate 			}
243*0Sstevel@tonic-gate 		}
244*0Sstevel@tonic-gate 	}
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	/*
247*0Sstevel@tonic-gate 	 * Add fd of psinfo file to poll set, but pass 0 for events to
248*0Sstevel@tonic-gate 	 * poll for, so we should only get a POLLHUP event on the fd.
249*0Sstevel@tonic-gate 	 */
250*0Sstevel@tonic-gate 	if (set_pollfd(fd, 0) == -1) {
251*0Sstevel@tonic-gate 		cancel_inst_timer(ins);
252*0Sstevel@tonic-gate 		free(me);
253*0Sstevel@tonic-gate 		(void) close(fd);
254*0Sstevel@tonic-gate 		return (-1);
255*0Sstevel@tonic-gate 	}
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate 	uu_list_node_init(me, &me->link, method_pool);
258*0Sstevel@tonic-gate 	(void) uu_list_insert_after(method_list, NULL, me);
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate 	return (0);
261*0Sstevel@tonic-gate }
262*0Sstevel@tonic-gate 
263*0Sstevel@tonic-gate /*
264*0Sstevel@tonic-gate  * A counterpart to register_method(), this function stops the monitoring of a
265*0Sstevel@tonic-gate  * method process for its termination.
266*0Sstevel@tonic-gate  */
267*0Sstevel@tonic-gate static void
268*0Sstevel@tonic-gate unregister_method(method_el_t *me)
269*0Sstevel@tonic-gate {
270*0Sstevel@tonic-gate 	debug_msg("Entering unregister_method: inst: %s, pid: %d, mthd: %s",
271*0Sstevel@tonic-gate 	    me->inst->fmri, me->pid, methods[me->method].name);
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate 	/* cancel any timer associated with the method */
274*0Sstevel@tonic-gate 	if (me->inst->timer_id != -1)
275*0Sstevel@tonic-gate 		cancel_inst_timer(me->inst);
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 	/* stop polling on the psinfo file fd */
278*0Sstevel@tonic-gate 	clear_pollfd(me->fd);
279*0Sstevel@tonic-gate 	(void) close(me->fd);
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 	/* remove method record from list */
282*0Sstevel@tonic-gate 	uu_list_remove(method_list, me);
283*0Sstevel@tonic-gate 
284*0Sstevel@tonic-gate 	free(me);
285*0Sstevel@tonic-gate }
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate /*
288*0Sstevel@tonic-gate  * Unregister all methods associated with instance 'inst'.
289*0Sstevel@tonic-gate  */
290*0Sstevel@tonic-gate void
291*0Sstevel@tonic-gate unregister_instance_methods(const instance_t *inst)
292*0Sstevel@tonic-gate {
293*0Sstevel@tonic-gate 	method_el_t *me = uu_list_first(method_list);
294*0Sstevel@tonic-gate 
295*0Sstevel@tonic-gate 	while (me != NULL) {
296*0Sstevel@tonic-gate 		if (me->inst == inst) {
297*0Sstevel@tonic-gate 			method_el_t *tmp = me;
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 			me = uu_list_next(method_list, me);
300*0Sstevel@tonic-gate 			unregister_method(tmp);
301*0Sstevel@tonic-gate 		} else  {
302*0Sstevel@tonic-gate 			me = uu_list_next(method_list, me);
303*0Sstevel@tonic-gate 		}
304*0Sstevel@tonic-gate 	}
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate /*
308*0Sstevel@tonic-gate  * Process any terminated methods. For each method determined to have
309*0Sstevel@tonic-gate  * terminated, the function determines its return value and calls the
310*0Sstevel@tonic-gate  * appropriate handling function, depending on the type of the method.
311*0Sstevel@tonic-gate  */
312*0Sstevel@tonic-gate void
313*0Sstevel@tonic-gate process_terminated_methods(void)
314*0Sstevel@tonic-gate {
315*0Sstevel@tonic-gate 	method_el_t	*me = uu_list_first(method_list);
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	debug_msg("Entering process_terminated_methods");
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate 	while (me != NULL) {
320*0Sstevel@tonic-gate 		struct pollfd	*pfd;
321*0Sstevel@tonic-gate 		pid_t		pid;
322*0Sstevel@tonic-gate 		int		status;
323*0Sstevel@tonic-gate 		int		ret;
324*0Sstevel@tonic-gate 		method_el_t	*tmp;
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate 		pfd = find_pollfd(me->fd);
327*0Sstevel@tonic-gate 
328*0Sstevel@tonic-gate 		/*
329*0Sstevel@tonic-gate 		 * We expect to get a POLLHUP back on the fd of the process's
330*0Sstevel@tonic-gate 		 * open psinfo file from /proc when the method terminates.
331*0Sstevel@tonic-gate 		 * A POLLERR could(?) mask a POLLHUP, so handle this
332*0Sstevel@tonic-gate 		 * also.
333*0Sstevel@tonic-gate 		 */
334*0Sstevel@tonic-gate 		if ((pfd->revents & (POLLHUP|POLLERR)) == 0) {
335*0Sstevel@tonic-gate 			me = uu_list_next(method_list, me);
336*0Sstevel@tonic-gate 			continue;
337*0Sstevel@tonic-gate 		}
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 		/* get the method's exit code (no need to loop for EINTR) */
340*0Sstevel@tonic-gate 		pid = waitpid(me->pid, &status, WNOHANG);
341*0Sstevel@tonic-gate 
342*0Sstevel@tonic-gate 		switch (pid) {
343*0Sstevel@tonic-gate 		case 0:					/* child still around */
344*0Sstevel@tonic-gate 			/*
345*0Sstevel@tonic-gate 			 * Either poll() is sending us invalid POLLHUP events
346*0Sstevel@tonic-gate 			 * or is flagging a POLLERR on the fd. Neither should
347*0Sstevel@tonic-gate 			 * happen, but in the event they do, ignore this fd
348*0Sstevel@tonic-gate 			 * this time around and wait out the termination
349*0Sstevel@tonic-gate 			 * of its associated method. This may result in
350*0Sstevel@tonic-gate 			 * inetd swiftly looping in event_loop(), but means
351*0Sstevel@tonic-gate 			 * we don't miss the termination of a method.
352*0Sstevel@tonic-gate 			 */
353*0Sstevel@tonic-gate 			me = uu_list_next(method_list, me);
354*0Sstevel@tonic-gate 			continue;
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate 		case -1:				/* non-existent child */
357*0Sstevel@tonic-gate 			assert(errno == ECHILD);
358*0Sstevel@tonic-gate 			/*
359*0Sstevel@tonic-gate 			 * the method must not be owned by inetd due to it
360*0Sstevel@tonic-gate 			 * persisting over an inetd restart. Let's assume the
361*0Sstevel@tonic-gate 			 * best, that it was successful.
362*0Sstevel@tonic-gate 			 */
363*0Sstevel@tonic-gate 			ret = IMRET_SUCCESS;
364*0Sstevel@tonic-gate 			break;
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 		default:				/* child terminated */
367*0Sstevel@tonic-gate 			if (WIFEXITED(status)) {
368*0Sstevel@tonic-gate 				ret = WEXITSTATUS(status);
369*0Sstevel@tonic-gate 				debug_msg("process %d of instance %s returned "
370*0Sstevel@tonic-gate 				    "%d", pid, me->inst->fmri, ret);
371*0Sstevel@tonic-gate 			} else if (WIFSIGNALED(status)) {
372*0Sstevel@tonic-gate 				/*
373*0Sstevel@tonic-gate 				 * Terminated by signal.  This may be due
374*0Sstevel@tonic-gate 				 * to a kill that we sent from a disable or
375*0Sstevel@tonic-gate 				 * offline event. We flag it as a failure, but
376*0Sstevel@tonic-gate 				 * this flagged failure will only be processed
377*0Sstevel@tonic-gate 				 * in the case of non-start methods, or when
378*0Sstevel@tonic-gate 				 * the instance is still enabled.
379*0Sstevel@tonic-gate 				 */
380*0Sstevel@tonic-gate 				debug_msg("process %d of instance %s exited "
381*0Sstevel@tonic-gate 				    "due to signal %d", pid, me->inst->fmri,
382*0Sstevel@tonic-gate 				    WTERMSIG(status));
383*0Sstevel@tonic-gate 				ret = IMRET_FAILURE;
384*0Sstevel@tonic-gate 			} else {
385*0Sstevel@tonic-gate 				/*
386*0Sstevel@tonic-gate 				 * Can we actually get here?  Don't think so.
387*0Sstevel@tonic-gate 				 * Treat it as a failure, anyway.
388*0Sstevel@tonic-gate 				 */
389*0Sstevel@tonic-gate 				debug_msg("waitpid() for %s method of "
390*0Sstevel@tonic-gate 				    "instance %s returned %d",
391*0Sstevel@tonic-gate 				    methods[me->method].name, me->inst->fmri,
392*0Sstevel@tonic-gate 				    status);
393*0Sstevel@tonic-gate 				ret = IMRET_FAILURE;
394*0Sstevel@tonic-gate 			}
395*0Sstevel@tonic-gate 		}
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate 		remove_method_ids(me->inst, me->pid, me->cid, me->method);
398*0Sstevel@tonic-gate 
399*0Sstevel@tonic-gate 		/* continue state transition processing of the instance */
400*0Sstevel@tonic-gate 		if (me->method != IM_START) {
401*0Sstevel@tonic-gate 			process_non_start_term(me->inst, ret);
402*0Sstevel@tonic-gate 		} else {
403*0Sstevel@tonic-gate 			process_start_term(me->inst);
404*0Sstevel@tonic-gate 		}
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate 		if (me->cid != -1)
407*0Sstevel@tonic-gate 			(void) abandon_contract(me->cid);
408*0Sstevel@tonic-gate 
409*0Sstevel@tonic-gate 		tmp = me;
410*0Sstevel@tonic-gate 		me = uu_list_next(method_list, me);
411*0Sstevel@tonic-gate 		unregister_method(tmp);
412*0Sstevel@tonic-gate 	}
413*0Sstevel@tonic-gate }
414