Print this page
OS-4818 contract template disappears on exec
OS-4460 exec brands processes that still have multiple threads
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4151 setbrand hooks should be sane during fork
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4144 panic in lx_freelwp during zone shutdown
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-4129 lxbrand should not abuse p_brand_data for storing exit signal
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-3820 lxbrand ptrace(2): the next generation
OS-3685 lxbrand PTRACE_O_TRACEFORK race condition
OS-3834 lxbrand 64-bit strace(1) reports 64-bit process as using x32 ABI
OS-3794 lxbrand panic on init signal death
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3140 In LX zone 'ps fax' does not show all processes
OS-3429 Expose zone's init exit status
OS-3149 lx brand always sends SIGCHLD to parent processes, regardless of how clone was invoked
OS-2887 lxbrand add WALL, WCLONE, WNOTHREAD support to waitid
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/os/exit.c
+++ new/usr/src/uts/common/os/exit.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ 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) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright (c) 2011, Joyent, Inc. All rights reserved.
24 + * Copyright 2014 Joyent, Inc. All rights reserved.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28
29 29 #include <sys/types.h>
30 30 #include <sys/param.h>
31 31 #include <sys/sysmacros.h>
32 32 #include <sys/systm.h>
33 33 #include <sys/cred.h>
34 34 #include <sys/user.h>
35 35 #include <sys/errno.h>
36 36 #include <sys/proc.h>
37 37 #include <sys/ucontext.h>
38 38 #include <sys/procfs.h>
39 39 #include <sys/vnode.h>
40 40 #include <sys/acct.h>
41 41 #include <sys/var.h>
42 42 #include <sys/cmn_err.h>
43 43 #include <sys/debug.h>
44 44 #include <sys/wait.h>
45 45 #include <sys/siginfo.h>
46 46 #include <sys/procset.h>
47 47 #include <sys/class.h>
48 48 #include <sys/file.h>
49 49 #include <sys/session.h>
50 50 #include <sys/kmem.h>
51 51 #include <sys/vtrace.h>
52 52 #include <sys/prsystm.h>
53 53 #include <sys/ipc.h>
54 54 #include <sys/sem_impl.h>
55 55 #include <c2/audit.h>
56 56 #include <sys/aio_impl.h>
57 57 #include <vm/as.h>
58 58 #include <sys/poll.h>
59 59 #include <sys/door.h>
60 60 #include <sys/lwpchan_impl.h>
61 61 #include <sys/utrap.h>
62 62 #include <sys/task.h>
63 63 #include <sys/exacct.h>
64 64 #include <sys/cyclic.h>
65 65 #include <sys/schedctl.h>
66 66 #include <sys/rctl.h>
67 67 #include <sys/contract_impl.h>
68 68 #include <sys/contract/process_impl.h>
69 69 #include <sys/list.h>
70 70 #include <sys/dtrace.h>
71 71 #include <sys/pool.h>
72 72 #include <sys/sdt.h>
73 73 #include <sys/corectl.h>
74 74 #include <sys/brand.h>
75 75 #include <sys/libc_kernel.h>
76 76
77 77 /*
78 78 * convert code/data pair into old style wait status
79 79 */
80 80 int
81 81 wstat(int code, int data)
82 82 {
83 83 int stat = (data & 0377);
84 84
85 85 switch (code) {
86 86 case CLD_EXITED:
87 87 stat <<= 8;
88 88 break;
89 89 case CLD_DUMPED:
90 90 stat |= WCOREFLG;
91 91 break;
92 92 case CLD_KILLED:
93 93 break;
94 94 case CLD_TRAPPED:
95 95 case CLD_STOPPED:
96 96 stat <<= 8;
97 97 stat |= WSTOPFLG;
98 98 break;
99 99 case CLD_CONTINUED:
100 100 stat = WCONTFLG;
101 101 break;
102 102 default:
103 103 cmn_err(CE_PANIC, "wstat: bad code");
104 104 /* NOTREACHED */
105 105 }
106 106 return (stat);
107 107 }
108 108
109 109 static char *
110 110 exit_reason(char *buf, size_t bufsz, int what, int why)
111 111 {
112 112 switch (why) {
113 113 case CLD_EXITED:
114 114 (void) snprintf(buf, bufsz, "exited with status %d", what);
115 115 break;
116 116 case CLD_KILLED:
117 117 (void) snprintf(buf, bufsz, "exited on fatal signal %d", what);
118 118 break;
119 119 case CLD_DUMPED:
120 120 (void) snprintf(buf, bufsz, "core dumped on signal %d", what);
121 121 break;
122 122 default:
123 123 (void) snprintf(buf, bufsz, "encountered unknown error "
124 124 "(%d, %d)", why, what);
125 125 break;
126 126 }
127 127
128 128 return (buf);
129 129 }
130 130
131 131 /*
132 132 * exit system call: pass back caller's arg.
133 133 */
134 134 void
135 135 rexit(int rval)
136 136 {
137 137 exit(CLD_EXITED, rval);
138 138 }
139 139
140 140 /*
141 141 * Called by proc_exit() when a zone's init exits, presumably because
142 142 * it failed. As long as the given zone is still in the "running"
143 143 * state, we will re-exec() init, but first we need to reset things
144 144 * which are usually inherited across exec() but will break init's
145 145 * assumption that it is being exec()'d from a virgin process. Most
146 146 * importantly this includes closing all file descriptors (exec only
147 147 * closes those marked close-on-exec) and resetting signals (exec only
148 148 * resets handled signals, and we need to clear any signals which
149 149 * killed init). Anything else that exec(2) says would be inherited,
150 150 * but would affect the execution of init, needs to be reset.
151 151 */
152 152 static int
153 153 restart_init(int what, int why)
154 154 {
155 155 kthread_t *t = curthread;
156 156 klwp_t *lwp = ttolwp(t);
157 157 proc_t *p = ttoproc(t);
158 158 user_t *up = PTOU(p);
159 159
160 160 vnode_t *oldcd, *oldrd;
161 161 int i, err;
162 162 char reason_buf[64];
163 163
164 164 /*
165 165 * Let zone admin (and global zone admin if this is for a non-global
166 166 * zone) know that init has failed and will be restarted.
167 167 */
168 168 zcmn_err(p->p_zone->zone_id, CE_WARN,
169 169 "init(1M) %s: restarting automatically",
170 170 exit_reason(reason_buf, sizeof (reason_buf), what, why));
171 171
172 172 if (!INGLOBALZONE(p)) {
173 173 cmn_err(CE_WARN, "init(1M) for zone %s (pid %d) %s: "
174 174 "restarting automatically",
175 175 p->p_zone->zone_name, p->p_pid, reason_buf);
176 176 }
177 177
178 178 /*
179 179 * Remove any fpollinfo_t's for this (last) thread from our file
180 180 * descriptors so closeall() can ASSERT() that they're all gone.
181 181 * Then close all open file descriptors in the process.
182 182 */
183 183 pollcleanup();
184 184 closeall(P_FINFO(p));
185 185
186 186 /*
187 187 * Grab p_lock and begin clearing miscellaneous global process
188 188 * state that needs to be reset before we exec the new init(1M).
189 189 */
190 190
191 191 mutex_enter(&p->p_lock);
192 192 prbarrier(p);
193 193
194 194 p->p_flag &= ~(SKILLED | SEXTKILLED | SEXITING | SDOCORE);
195 195 up->u_cmask = CMASK;
196 196
197 197 sigemptyset(&t->t_hold);
198 198 sigemptyset(&t->t_sig);
199 199 sigemptyset(&t->t_extsig);
200 200
201 201 sigemptyset(&p->p_sig);
202 202 sigemptyset(&p->p_extsig);
203 203
204 204 sigdelq(p, t, 0);
205 205 sigdelq(p, NULL, 0);
206 206
207 207 if (p->p_killsqp) {
208 208 siginfofree(p->p_killsqp);
209 209 p->p_killsqp = NULL;
210 210 }
211 211
212 212 /*
213 213 * Reset any signals that are ignored back to the default disposition.
214 214 * Other u_signal members will be cleared when exec calls sigdefault().
215 215 */
216 216 for (i = 1; i < NSIG; i++) {
217 217 if (up->u_signal[i - 1] == SIG_IGN) {
218 218 up->u_signal[i - 1] = SIG_DFL;
219 219 sigemptyset(&up->u_sigmask[i - 1]);
220 220 }
221 221 }
222 222
|
↓ open down ↓ |
188 lines elided |
↑ open up ↑ |
223 223 /*
224 224 * Clear the current signal, any signal info associated with it, and
225 225 * any signal information from contracts and/or contract templates.
226 226 */
227 227 lwp->lwp_cursig = 0;
228 228 lwp->lwp_extsig = 0;
229 229 if (lwp->lwp_curinfo != NULL) {
230 230 siginfofree(lwp->lwp_curinfo);
231 231 lwp->lwp_curinfo = NULL;
232 232 }
233 - lwp_ctmpl_clear(lwp);
233 + lwp_ctmpl_clear(lwp, B_FALSE);
234 234
235 235 /*
236 236 * Reset both the process root directory and the current working
237 237 * directory to the root of the zone just as we do during boot.
238 238 */
239 239 VN_HOLD(p->p_zone->zone_rootvp);
240 240 oldrd = up->u_rdir;
241 241 up->u_rdir = p->p_zone->zone_rootvp;
242 242
243 243 VN_HOLD(p->p_zone->zone_rootvp);
244 244 oldcd = up->u_cdir;
245 245 up->u_cdir = p->p_zone->zone_rootvp;
246 246
247 247 if (up->u_cwd != NULL) {
248 248 refstr_rele(up->u_cwd);
249 249 up->u_cwd = NULL;
250 250 }
251 251
252 252 mutex_exit(&p->p_lock);
253 253
254 254 if (oldrd != NULL)
255 255 VN_RELE(oldrd);
256 256 if (oldcd != NULL)
257 257 VN_RELE(oldcd);
258 258
259 259 /* Free the controlling tty. (freectty() always assumes curproc.) */
260 260 ASSERT(p == curproc);
261 261 (void) freectty(B_TRUE);
262 262
263 263 /*
264 264 * Now exec() the new init(1M) on top of the current process. If we
265 265 * succeed, the caller will treat this like a successful system call.
266 266 * If we fail, we issue messages and the caller will proceed with exit.
267 267 */
268 268 err = exec_init(p->p_zone->zone_initname, NULL);
269 269
270 270 if (err == 0)
271 271 return (0);
272 272
273 273 zcmn_err(p->p_zone->zone_id, CE_WARN,
274 274 "failed to restart init(1M) (err=%d): system reboot required", err);
275 275
276 276 if (!INGLOBALZONE(p)) {
277 277 cmn_err(CE_WARN, "failed to restart init(1M) for zone %s "
278 278 "(pid %d, err=%d): zoneadm(1M) boot required",
279 279 p->p_zone->zone_name, p->p_pid, err);
280 280 }
281 281
282 282 return (-1);
283 283 }
284 284
285 285 /*
286 286 * Release resources.
287 287 * Enter zombie state.
288 288 * Wake up parent and init processes,
289 289 * and dispose of children.
290 290 */
291 291 void
292 292 exit(int why, int what)
293 293 {
294 294 /*
295 295 * If proc_exit() fails, then some other lwp in the process
296 296 * got there first. We just have to call lwp_exit() to allow
297 297 * the other lwp to finish exiting the process. Otherwise we're
298 298 * restarting init, and should return.
299 299 */
300 300 if (proc_exit(why, what) != 0) {
301 301 mutex_enter(&curproc->p_lock);
302 302 ASSERT(curproc->p_flag & SEXITLWPS);
303 303 lwp_exit();
304 304 /* NOTREACHED */
305 305 }
306 306 }
307 307
308 308 /*
309 309 * Set the SEXITING flag on the process, after making sure /proc does
310 310 * not have it locked. This is done in more places than proc_exit(),
311 311 * so it is a separate function.
312 312 */
313 313 void
314 314 proc_is_exiting(proc_t *p)
315 315 {
316 316 mutex_enter(&p->p_lock);
317 317 prbarrier(p);
318 318 p->p_flag |= SEXITING;
319 319 mutex_exit(&p->p_lock);
320 320 }
321 321
322 322 /*
323 323 * Return value:
324 324 * 1 - exitlwps() failed, call (or continue) lwp_exit()
325 325 * 0 - restarting init. Return through system call path
326 326 */
327 327 int
328 328 proc_exit(int why, int what)
329 329 {
330 330 kthread_t *t = curthread;
331 331 klwp_t *lwp = ttolwp(t);
332 332 proc_t *p = ttoproc(t);
333 333 zone_t *z = p->p_zone;
334 334 timeout_id_t tmp_id;
335 335 int rv;
336 336 proc_t *q;
337 337 task_t *tk;
338 338 vnode_t *exec_vp, *execdir_vp, *cdir, *rdir;
339 339 sigqueue_t *sqp;
340 340 lwpdir_t *lwpdir;
341 341 uint_t lwpdir_sz;
342 342 tidhash_t *tidhash;
343 343 uint_t tidhash_sz;
344 344 ret_tidhash_t *ret_tidhash;
345 345 refstr_t *cwd;
346 346 hrtime_t hrutime, hrstime;
347 347 int evaporate;
348 348
349 349 /*
350 350 * Stop and discard the process's lwps except for the current one,
351 351 * unless some other lwp beat us to it. If exitlwps() fails then
352 352 * return and the calling lwp will call (or continue in) lwp_exit().
353 353 */
354 354 proc_is_exiting(p);
355 355 if (exitlwps(0) != 0)
356 356 return (1);
357 357
358 358 mutex_enter(&p->p_lock);
|
↓ open down ↓ |
115 lines elided |
↑ open up ↑ |
359 359 if (p->p_ttime > 0) {
360 360 /*
361 361 * Account any remaining ticks charged to this process
362 362 * on its way out.
363 363 */
364 364 (void) task_cpu_time_incr(p->p_task, p->p_ttime);
365 365 p->p_ttime = 0;
366 366 }
367 367 mutex_exit(&p->p_lock);
368 368
369 - DTRACE_PROC(lwp__exit);
370 - DTRACE_PROC1(exit, int, why);
371 -
372 369 /*
373 - * Will perform any brand specific proc exit processing, since this
374 - * is always the last lwp, will also perform lwp_exit and free brand
375 - * data
376 - */
377 - if (PROC_IS_BRANDED(p)) {
378 - lwp_detach_brand_hdlrs(lwp);
379 - brand_clearbrand(p, B_FALSE);
380 - }
381 -
382 - /*
383 370 * Don't let init exit unless zone_start_init() failed its exec, or
384 371 * we are shutting down the zone or the machine.
385 372 *
386 373 * Since we are single threaded, we don't need to lock the
387 374 * following accesses to zone_proc_initpid.
388 375 */
389 376 if (p->p_pid == z->zone_proc_initpid) {
390 377 if (z->zone_boot_err == 0 &&
391 378 zone_status_get(z) < ZONE_IS_SHUTTING_DOWN &&
392 379 zone_status_get(global_zone) < ZONE_IS_SHUTTING_DOWN) {
393 - if (z->zone_restart_init == B_TRUE) {
394 - if (restart_init(what, why) == 0)
395 - return (0);
380 +
381 + /*
382 + * If the init process should be restarted, the
383 + * "zone_restart_init" member will be set. Some init
384 + * programs in branded zones do not tolerate a restart
385 + * in the traditional manner; setting the
386 + * "zone_reboot_on_init_exit" member will cause the
387 + * entire zone to be rebooted instead. If neither of
388 + * these flags is set the zone will shut down.
389 + */
390 + if (z->zone_reboot_on_init_exit == B_TRUE &&
391 + z->zone_restart_init == B_TRUE) {
392 + /*
393 + * Trigger a zone reboot and continue
394 + * with exit processing.
395 + */
396 + z->zone_init_status = wstat(why, what);
397 + (void) zone_kadmin(A_REBOOT, 0, NULL,
398 + zone_kcred());
399 +
396 400 } else {
401 + if (z->zone_restart_init == B_TRUE) {
402 + if (restart_init(what, why) == 0)
403 + return (0);
404 + }
405 +
406 + z->zone_init_status = wstat(why, what);
397 407 (void) zone_kadmin(A_SHUTDOWN, AD_HALT, NULL,
398 - CRED());
408 + zone_kcred());
399 409 }
400 410 }
401 411
402 412 /*
403 413 * Since we didn't or couldn't restart init, we clear
404 414 * the zone's init state and proceed with exit
405 415 * processing.
406 416 */
407 417 z->zone_proc_initpid = -1;
408 418 }
409 419
420 + /*
421 + * Delay firing probes (and performing brand cleanup) until after the
422 + * zone_proc_initpid check. Cases which result in zone shutdown or
423 + * restart via zone_kadmin eventually result in a call back to
424 + * proc_exit.
425 + */
426 + DTRACE_PROC(lwp__exit);
427 + DTRACE_PROC1(exit, int, why);
428 +
429 + /*
430 + * Will perform any brand specific proc exit processing. Since this
431 + * is always the last lwp, will also perform lwp exit/free and proc
432 + * exit. Brand data will be freed when the process is reaped.
433 + */
434 + if (PROC_IS_BRANDED(p)) {
435 + BROP(p)->b_lwpexit(lwp);
436 + BROP(p)->b_proc_exit(p);
437 + /*
438 + * To ensure that b_proc_exit has access to brand-specific data
439 + * contained by the one remaining lwp, call the freelwp hook as
440 + * the last part of this clean-up process.
441 + */
442 + BROP(p)->b_freelwp(lwp);
443 + lwp_detach_brand_hdlrs(lwp);
444 + }
445 +
410 446 lwp_pcb_exit();
411 447
412 448 /*
413 449 * Allocate a sigqueue now, before we grab locks.
414 450 * It will be given to sigcld(), below.
415 451 * Special case: If we will be making the process disappear
416 452 * without a trace because it is either:
417 453 * * an exiting SSYS process, or
418 454 * * a posix_spawn() vfork child who requests it,
419 455 * we don't bother to allocate a useless sigqueue.
420 456 */
421 457 evaporate = (p->p_flag & SSYS) || ((p->p_flag & SVFORK) &&
422 458 why == CLD_EXITED && what == _EVAPORATE);
423 459 if (!evaporate)
424 460 sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);
425 461
426 462 /*
427 463 * revoke any doors created by the process.
428 464 */
429 465 if (p->p_door_list)
430 466 door_exit();
431 467
432 468 /*
433 469 * Release schedctl data structures.
434 470 */
435 471 if (p->p_pagep)
436 472 schedctl_proc_cleanup();
437 473
438 474 /*
439 475 * make sure all pending kaio has completed.
440 476 */
441 477 if (p->p_aio)
442 478 aio_cleanup_exit();
443 479
444 480 /*
445 481 * discard the lwpchan cache.
446 482 */
447 483 if (p->p_lcp != NULL)
448 484 lwpchan_destroy_cache(0);
449 485
450 486 /*
451 487 * Clean up any DTrace helper actions or probes for the process.
452 488 */
453 489 if (p->p_dtrace_helpers != NULL) {
454 490 ASSERT(dtrace_helpers_cleanup != NULL);
455 491 (*dtrace_helpers_cleanup)();
456 492 }
457 493
458 494 /*
459 495 * Clean up any signalfd state for the process.
460 496 */
461 497 if (p->p_sigfd != NULL) {
462 498 VERIFY(sigfd_exit_helper != NULL);
463 499 (*sigfd_exit_helper)();
464 500 }
465 501
466 502 /* untimeout the realtime timers */
467 503 if (p->p_itimer != NULL)
468 504 timer_exit();
469 505
470 506 if ((tmp_id = p->p_alarmid) != 0) {
471 507 p->p_alarmid = 0;
472 508 (void) untimeout(tmp_id);
473 509 }
474 510
475 511 /*
476 512 * Remove any fpollinfo_t's for this (last) thread from our file
477 513 * descriptors so closeall() can ASSERT() that they're all gone.
478 514 */
479 515 pollcleanup();
480 516
481 517 if (p->p_rprof_cyclic != CYCLIC_NONE) {
482 518 mutex_enter(&cpu_lock);
483 519 cyclic_remove(p->p_rprof_cyclic);
484 520 mutex_exit(&cpu_lock);
485 521 }
486 522
487 523 mutex_enter(&p->p_lock);
488 524
489 525 /*
490 526 * Clean up any DTrace probes associated with this process.
491 527 */
492 528 if (p->p_dtrace_probes) {
493 529 ASSERT(dtrace_fasttrap_exit_ptr != NULL);
494 530 dtrace_fasttrap_exit_ptr(p);
495 531 }
496 532
497 533 while ((tmp_id = p->p_itimerid) != 0) {
498 534 p->p_itimerid = 0;
499 535 mutex_exit(&p->p_lock);
500 536 (void) untimeout(tmp_id);
501 537 mutex_enter(&p->p_lock);
502 538 }
503 539
504 540 lwp_cleanup();
505 541
506 542 /*
507 543 * We are about to exit; prevent our resource associations from
508 544 * being changed.
509 545 */
510 546 pool_barrier_enter();
511 547
512 548 /*
513 549 * Block the process against /proc now that we have really
514 550 * acquired p->p_lock (to manipulate p_tlist at least).
515 551 */
516 552 prbarrier(p);
517 553
518 554 sigfillset(&p->p_ignore);
519 555 sigemptyset(&p->p_siginfo);
520 556 sigemptyset(&p->p_sig);
521 557 sigemptyset(&p->p_extsig);
522 558 sigemptyset(&t->t_sig);
523 559 sigemptyset(&t->t_extsig);
524 560 sigemptyset(&p->p_sigmask);
525 561 sigdelq(p, t, 0);
526 562 lwp->lwp_cursig = 0;
527 563 lwp->lwp_extsig = 0;
528 564 p->p_flag &= ~(SKILLED | SEXTKILLED);
529 565 if (lwp->lwp_curinfo) {
530 566 siginfofree(lwp->lwp_curinfo);
531 567 lwp->lwp_curinfo = NULL;
532 568 }
533 569
534 570 t->t_proc_flag |= TP_LWPEXIT;
535 571 ASSERT(p->p_lwpcnt == 1 && p->p_zombcnt == 0);
536 572 prlwpexit(t); /* notify /proc */
537 573 lwp_hash_out(p, t->t_tid);
538 574 prexit(p);
539 575
540 576 p->p_lwpcnt = 0;
541 577 p->p_tlist = NULL;
542 578 sigqfree(p);
543 579 term_mstate(t);
544 580 p->p_mterm = gethrtime();
545 581
546 582 exec_vp = p->p_exec;
547 583 execdir_vp = p->p_execdir;
548 584 p->p_exec = NULLVP;
549 585 p->p_execdir = NULLVP;
550 586 mutex_exit(&p->p_lock);
551 587
552 588 pr_free_watched_pages(p);
553 589
554 590 closeall(P_FINFO(p));
555 591
556 592 /* Free the controlling tty. (freectty() always assumes curproc.) */
557 593 ASSERT(p == curproc);
558 594 (void) freectty(B_TRUE);
559 595
560 596 #if defined(__sparc)
561 597 if (p->p_utraps != NULL)
562 598 utrap_free(p);
563 599 #endif
564 600 if (p->p_semacct) /* IPC semaphore exit */
565 601 semexit(p);
566 602 rv = wstat(why, what);
567 603
568 604 acct(rv & 0xff);
569 605 exacct_commit_proc(p, rv);
570 606
571 607 /*
572 608 * Release any resources associated with C2 auditing
573 609 */
574 610 if (AU_AUDITING()) {
575 611 /*
576 612 * audit exit system call
577 613 */
578 614 audit_exit(why, what);
579 615 }
580 616
581 617 /*
582 618 * Free address space.
583 619 */
584 620 relvm();
585 621
586 622 if (exec_vp) {
587 623 /*
588 624 * Close this executable which has been opened when the process
589 625 * was created by getproc().
590 626 */
591 627 (void) VOP_CLOSE(exec_vp, FREAD, 1, (offset_t)0, CRED(), NULL);
592 628 VN_RELE(exec_vp);
593 629 }
594 630 if (execdir_vp)
595 631 VN_RELE(execdir_vp);
596 632
597 633 /*
598 634 * Release held contracts.
599 635 */
600 636 contract_exit(p);
601 637
602 638 /*
603 639 * Depart our encapsulating process contract.
604 640 */
605 641 if ((p->p_flag & SSYS) == 0) {
606 642 ASSERT(p->p_ct_process);
607 643 contract_process_exit(p->p_ct_process, p, rv);
608 644 }
609 645
610 646 /*
611 647 * Remove pool association, and block if requested by pool_do_bind.
612 648 */
613 649 mutex_enter(&p->p_lock);
614 650 ASSERT(p->p_pool->pool_ref > 0);
615 651 atomic_dec_32(&p->p_pool->pool_ref);
616 652 p->p_pool = pool_default;
617 653 /*
618 654 * Now that our address space has been freed and all other threads
619 655 * in this process have exited, set the PEXITED pool flag. This
620 656 * tells the pools subsystems to ignore this process if it was
621 657 * requested to rebind this process to a new pool.
622 658 */
623 659 p->p_poolflag |= PEXITED;
624 660 pool_barrier_exit();
625 661 mutex_exit(&p->p_lock);
626 662
627 663 mutex_enter(&pidlock);
628 664
629 665 /*
630 666 * Delete this process from the newstate list of its parent. We
631 667 * will put it in the right place in the sigcld in the end.
632 668 */
633 669 delete_ns(p->p_parent, p);
634 670
635 671 /*
636 672 * Reassign the orphans to the next of kin.
637 673 * Don't rearrange init's orphanage.
638 674 */
639 675 if ((q = p->p_orphan) != NULL && p != proc_init) {
640 676
641 677 proc_t *nokp = p->p_nextofkin;
642 678
643 679 for (;;) {
644 680 q->p_nextofkin = nokp;
645 681 if (q->p_nextorph == NULL)
646 682 break;
647 683 q = q->p_nextorph;
648 684 }
649 685 q->p_nextorph = nokp->p_orphan;
650 686 nokp->p_orphan = p->p_orphan;
|
↓ open down ↓ |
231 lines elided |
↑ open up ↑ |
651 687 p->p_orphan = NULL;
652 688 }
653 689
654 690 /*
655 691 * Reassign the children to init.
656 692 * Don't try to assign init's children to init.
657 693 */
658 694 if ((q = p->p_child) != NULL && p != proc_init) {
659 695 struct proc *np;
660 696 struct proc *initp = proc_init;
697 + pid_t zone_initpid = 1;
698 + struct proc *zoneinitp = NULL;
661 699 boolean_t setzonetop = B_FALSE;
662 700
663 - if (!INGLOBALZONE(curproc))
664 - setzonetop = B_TRUE;
701 + if (!INGLOBALZONE(curproc)) {
702 + zone_initpid = curproc->p_zone->zone_proc_initpid;
665 703
704 + ASSERT(MUTEX_HELD(&pidlock));
705 + zoneinitp = prfind(zone_initpid);
706 + if (zoneinitp != NULL) {
707 + initp = zoneinitp;
708 + } else {
709 + zone_initpid = 1;
710 + setzonetop = B_TRUE;
711 + }
712 + }
713 +
666 714 pgdetach(p);
667 715
668 716 do {
669 717 np = q->p_sibling;
670 718 /*
671 719 * Delete it from its current parent new state
672 720 * list and add it to init new state list
673 721 */
674 722 delete_ns(q->p_parent, q);
675 723
676 - q->p_ppid = 1;
724 + q->p_ppid = zone_initpid;
725 +
677 726 q->p_pidflag &= ~(CLDNOSIGCHLD | CLDWAITPID);
678 727 if (setzonetop) {
679 728 mutex_enter(&q->p_lock);
680 729 q->p_flag |= SZONETOP;
681 730 mutex_exit(&q->p_lock);
682 731 }
683 732 q->p_parent = initp;
684 733
685 734 /*
686 735 * Since q will be the first child,
687 736 * it will not have a previous sibling.
688 737 */
689 738 q->p_psibling = NULL;
690 739 if (initp->p_child) {
691 740 initp->p_child->p_psibling = q;
692 741 }
693 742 q->p_sibling = initp->p_child;
694 743 initp->p_child = q;
695 744 if (q->p_proc_flag & P_PR_PTRACE) {
696 745 mutex_enter(&q->p_lock);
697 746 sigtoproc(q, NULL, SIGKILL);
698 747 mutex_exit(&q->p_lock);
699 748 }
700 749 /*
701 750 * sigcld() will add the child to parents
702 751 * newstate list.
703 752 */
704 753 if (q->p_stat == SZOMB)
705 754 sigcld(q, NULL);
706 755 } while ((q = np) != NULL);
707 756
708 757 p->p_child = NULL;
709 758 ASSERT(p->p_child_ns == NULL);
710 759 }
711 760
712 761 TRACE_1(TR_FAC_PROC, TR_PROC_EXIT, "proc_exit: %p", p);
713 762
714 763 mutex_enter(&p->p_lock);
715 764 CL_EXIT(curthread); /* tell the scheduler that curthread is exiting */
716 765
717 766 /*
718 767 * Have our task accummulate our resource usage data before they
719 768 * become contaminated by p_cacct etc., and before we renounce
720 769 * membership of the task.
721 770 *
722 771 * We do this regardless of whether or not task accounting is active.
723 772 * This is to avoid having nonsense data reported for this task if
724 773 * task accounting is subsequently enabled. The overhead is minimal;
725 774 * by this point, this process has accounted for the usage of all its
726 775 * LWPs. We nonetheless do the work here, and under the protection of
727 776 * pidlock, so that the movement of the process's usage to the task
728 777 * happens at the same time as the removal of the process from the
729 778 * task, from the point of view of exacct_snapshot_task_usage().
730 779 */
731 780 exacct_update_task_mstate(p);
732 781
733 782 hrutime = mstate_aggr_state(p, LMS_USER);
734 783 hrstime = mstate_aggr_state(p, LMS_SYSTEM);
735 784 p->p_utime = (clock_t)NSEC_TO_TICK(hrutime) + p->p_cutime;
736 785 p->p_stime = (clock_t)NSEC_TO_TICK(hrstime) + p->p_cstime;
737 786
738 787 p->p_acct[LMS_USER] += p->p_cacct[LMS_USER];
739 788 p->p_acct[LMS_SYSTEM] += p->p_cacct[LMS_SYSTEM];
740 789 p->p_acct[LMS_TRAP] += p->p_cacct[LMS_TRAP];
741 790 p->p_acct[LMS_TFAULT] += p->p_cacct[LMS_TFAULT];
742 791 p->p_acct[LMS_DFAULT] += p->p_cacct[LMS_DFAULT];
743 792 p->p_acct[LMS_KFAULT] += p->p_cacct[LMS_KFAULT];
744 793 p->p_acct[LMS_USER_LOCK] += p->p_cacct[LMS_USER_LOCK];
745 794 p->p_acct[LMS_SLEEP] += p->p_cacct[LMS_SLEEP];
746 795 p->p_acct[LMS_WAIT_CPU] += p->p_cacct[LMS_WAIT_CPU];
747 796 p->p_acct[LMS_STOPPED] += p->p_cacct[LMS_STOPPED];
748 797
749 798 p->p_ru.minflt += p->p_cru.minflt;
750 799 p->p_ru.majflt += p->p_cru.majflt;
751 800 p->p_ru.nswap += p->p_cru.nswap;
752 801 p->p_ru.inblock += p->p_cru.inblock;
753 802 p->p_ru.oublock += p->p_cru.oublock;
754 803 p->p_ru.msgsnd += p->p_cru.msgsnd;
755 804 p->p_ru.msgrcv += p->p_cru.msgrcv;
756 805 p->p_ru.nsignals += p->p_cru.nsignals;
757 806 p->p_ru.nvcsw += p->p_cru.nvcsw;
758 807 p->p_ru.nivcsw += p->p_cru.nivcsw;
759 808 p->p_ru.sysc += p->p_cru.sysc;
760 809 p->p_ru.ioch += p->p_cru.ioch;
761 810
762 811 p->p_stat = SZOMB;
763 812 p->p_proc_flag &= ~P_PR_PTRACE;
764 813 p->p_wdata = what;
765 814 p->p_wcode = (char)why;
766 815
767 816 cdir = PTOU(p)->u_cdir;
768 817 rdir = PTOU(p)->u_rdir;
769 818 cwd = PTOU(p)->u_cwd;
770 819
771 820 ASSERT(cdir != NULL || p->p_parent == &p0);
772 821
773 822 /*
774 823 * Release resource controls, as they are no longer enforceable.
775 824 */
776 825 rctl_set_free(p->p_rctls);
777 826
778 827 /*
779 828 * Decrement tk_nlwps counter for our task.max-lwps resource control.
780 829 * An extended accounting record, if that facility is active, is
781 830 * scheduled to be written. We cannot give up task and project
782 831 * membership at this point because that would allow zombies to escape
783 832 * from the max-processes resource controls. Zombies stay in their
784 833 * current task and project until the process table slot is released
785 834 * in freeproc().
786 835 */
787 836 tk = p->p_task;
788 837
789 838 mutex_enter(&p->p_zone->zone_nlwps_lock);
790 839 tk->tk_nlwps--;
791 840 tk->tk_proj->kpj_nlwps--;
792 841 p->p_zone->zone_nlwps--;
793 842 mutex_exit(&p->p_zone->zone_nlwps_lock);
794 843
795 844 /*
796 845 * Clear the lwp directory and the lwpid hash table
797 846 * now that /proc can't bother us any more.
798 847 * We free the memory below, after dropping p->p_lock.
799 848 */
800 849 lwpdir = p->p_lwpdir;
801 850 lwpdir_sz = p->p_lwpdir_sz;
802 851 tidhash = p->p_tidhash;
803 852 tidhash_sz = p->p_tidhash_sz;
804 853 ret_tidhash = p->p_ret_tidhash;
805 854 p->p_lwpdir = NULL;
806 855 p->p_lwpfree = NULL;
807 856 p->p_lwpdir_sz = 0;
808 857 p->p_tidhash = NULL;
809 858 p->p_tidhash_sz = 0;
810 859 p->p_ret_tidhash = NULL;
811 860
812 861 /*
813 862 * If the process has context ops installed, call the exit routine
814 863 * on behalf of this last remaining thread. Normally exitpctx() is
815 864 * called during thread_exit() or lwp_exit(), but because this is the
816 865 * last thread in the process, we must call it here. By the time
817 866 * thread_exit() is called (below), the association with the relevant
818 867 * process has been lost.
819 868 *
820 869 * We also free the context here.
821 870 */
822 871 if (p->p_pctx) {
823 872 kpreempt_disable();
824 873 exitpctx(p);
825 874 kpreempt_enable();
826 875
827 876 freepctx(p, 0);
828 877 }
829 878
830 879 /*
831 880 * curthread's proc pointer is changed to point to the 'sched'
832 881 * process for the corresponding zone, except in the case when
833 882 * the exiting process is in fact a zsched instance, in which
834 883 * case the proc pointer is set to p0. We do so, so that the
835 884 * process still points at the right zone when we call the VN_RELE()
836 885 * below.
837 886 *
838 887 * This is because curthread's original proc pointer can be freed as
839 888 * soon as the child sends a SIGCLD to its parent. We use zsched so
|
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
840 889 * that for user processes, even in the final moments of death, the
841 890 * process is still associated with its zone.
842 891 */
843 892 if (p != t->t_procp->p_zone->zone_zsched)
844 893 t->t_procp = t->t_procp->p_zone->zone_zsched;
845 894 else
846 895 t->t_procp = &p0;
847 896
848 897 mutex_exit(&p->p_lock);
849 898 if (!evaporate) {
850 - p->p_pidflag &= ~CLDPEND;
851 - sigcld(p, sqp);
899 + /*
900 + * The brand specific code only happens when the brand has a
901 + * function to call in place of sigcld and the parent of the
902 + * exiting process is not the global zone init. If the parent
903 + * is the global zone init, then the process was reparented,
904 + * and we don't want brand code delivering possibly strange
905 + * signals to init. Also, init is not branded, so any brand
906 + * specific exit data will not be picked up by init anyway.
907 + */
908 + if (PROC_IS_BRANDED(p) &&
909 + BROP(p)->b_exit_with_sig != NULL &&
910 + p->p_ppid != 1) {
911 + /*
912 + * The code for _fini that could unload the brand_t
913 + * blocks until the count of zones using the module
914 + * reaches zero. Zones decrement the refcount on their
915 + * brands only after all user tasks in that zone have
916 + * exited and been waited on. The decrement on the
917 + * brand's refcount happen in zone_destroy(). That
918 + * depends on zone_shutdown() having been completed.
919 + * zone_shutdown() includes a call to zone_empty(),
920 + * where the zone waits for itself to reach the state
921 + * ZONE_IS_EMPTY. This state is only set in either
922 + * zone_shutdown(), when there are no user processes as
923 + * the zone enters this function, or in
924 + * zone_task_rele(). zone_task_rele() is called from
925 + * code triggered by waiting on processes, not by the
926 + * processes exiting through proc_exit(). This means
927 + * all the branded processes that could exist for a
928 + * specific brand_t must exit and get reaped before the
929 + * refcount on the brand_t can reach 0. _fini will
930 + * never unload the corresponding brand module before
931 + * proc_exit finishes execution for all processes
932 + * branded with a particular brand_t, which makes the
933 + * operation below safe to do. Brands that wish to use
934 + * this mechanism must wait in _fini as described
935 + * above.
936 + */
937 + BROP(p)->b_exit_with_sig(p, sqp);
938 + } else {
939 + p->p_pidflag &= ~CLDPEND;
940 + sigcld(p, sqp);
941 + }
942 +
852 943 } else {
853 944 /*
854 945 * Do what sigcld() would do if the disposition
855 946 * of the SIGCHLD signal were set to be ignored.
856 947 */
857 948 cv_broadcast(&p->p_srwchan_cv);
858 949 freeproc(p);
859 950 }
860 951 mutex_exit(&pidlock);
861 952
862 953 /*
863 954 * We don't release u_cdir and u_rdir until SZOMB is set.
864 955 * This protects us against dofusers().
865 956 */
866 957 if (cdir)
867 958 VN_RELE(cdir);
868 959 if (rdir)
869 960 VN_RELE(rdir);
870 961 if (cwd)
871 962 refstr_rele(cwd);
872 963
873 964 /*
874 965 * task_rele() may ultimately cause the zone to go away (or
875 966 * may cause the last user process in a zone to go away, which
876 967 * signals zsched to go away). So prior to this call, we must
877 968 * no longer point at zsched.
878 969 */
879 970 t->t_procp = &p0;
880 971
881 972 kmem_free(lwpdir, lwpdir_sz * sizeof (lwpdir_t));
882 973 kmem_free(tidhash, tidhash_sz * sizeof (tidhash_t));
883 974 while (ret_tidhash != NULL) {
884 975 ret_tidhash_t *next = ret_tidhash->rth_next;
885 976 kmem_free(ret_tidhash->rth_tidhash,
886 977 ret_tidhash->rth_tidhash_sz * sizeof (tidhash_t));
887 978 kmem_free(ret_tidhash, sizeof (*ret_tidhash));
888 979 ret_tidhash = next;
889 980 }
890 981
891 982 thread_exit();
892 983 /* NOTREACHED */
893 984 }
894 985
895 986 /*
896 987 * Format siginfo structure for wait system calls.
897 988 */
898 989 void
899 990 winfo(proc_t *pp, k_siginfo_t *ip, int waitflag)
900 991 {
901 992 ASSERT(MUTEX_HELD(&pidlock));
902 993
903 994 bzero(ip, sizeof (k_siginfo_t));
904 995 ip->si_signo = SIGCLD;
905 996 ip->si_code = pp->p_wcode;
906 997 ip->si_pid = pp->p_pid;
907 998 ip->si_ctid = PRCTID(pp);
908 999 ip->si_zoneid = pp->p_zone->zone_id;
909 1000 ip->si_status = pp->p_wdata;
910 1001 ip->si_stime = pp->p_stime;
911 1002 ip->si_utime = pp->p_utime;
912 1003
913 1004 if (waitflag) {
914 1005 pp->p_wcode = 0;
915 1006 pp->p_wdata = 0;
916 1007 pp->p_pidflag &= ~CLDPEND;
917 1008 }
918 1009 }
919 1010
|
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
920 1011 /*
921 1012 * Wait system call.
922 1013 * Search for a terminated (zombie) child,
923 1014 * finally lay it to rest, and collect its status.
924 1015 * Look also for stopped children,
925 1016 * and pass back status from them.
926 1017 */
927 1018 int
928 1019 waitid(idtype_t idtype, id_t id, k_siginfo_t *ip, int options)
929 1020 {
930 - int found;
931 1021 proc_t *cp, *pp;
932 - int proc_gone;
933 1022 int waitflag = !(options & WNOWAIT);
1023 + boolean_t have_brand_helper = B_FALSE;
934 1024
935 1025 /*
936 1026 * Obsolete flag, defined here only for binary compatibility
937 1027 * with old statically linked executables. Delete this when
938 1028 * we no longer care about these old and broken applications.
939 1029 */
940 1030 #define _WNOCHLD 0400
941 1031 options &= ~_WNOCHLD;
942 1032
943 1033 if (options == 0 || (options & ~WOPTMASK))
944 1034 return (EINVAL);
945 1035
946 1036 switch (idtype) {
947 1037 case P_PID:
948 1038 case P_PGID:
949 1039 if (id < 0 || id >= maxpid)
950 1040 return (EINVAL);
|
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
951 1041 /* FALLTHROUGH */
952 1042 case P_ALL:
953 1043 break;
954 1044 default:
955 1045 return (EINVAL);
956 1046 }
957 1047
958 1048 pp = ttoproc(curthread);
959 1049
960 1050 /*
961 - * lock parent mutex so that sibling chain can be searched.
1051 + * Anytime you are looking for a process, you take pidlock to prevent
1052 + * things from changing as you look.
962 1053 */
963 1054 mutex_enter(&pidlock);
964 1055
965 1056 /*
966 1057 * if we are only looking for exited processes and child_ns list
967 1058 * is empty no reason to look at all children.
968 1059 */
969 1060 if (idtype == P_ALL &&
970 1061 (options & ~WNOWAIT) == (WNOHANG | WEXITED) &&
971 1062 pp->p_child_ns == NULL) {
972 1063 if (pp->p_child) {
973 1064 mutex_exit(&pidlock);
974 1065 bzero(ip, sizeof (k_siginfo_t));
975 1066 return (0);
976 1067 }
977 1068 mutex_exit(&pidlock);
978 1069 return (ECHILD);
979 1070 }
980 1071
981 - while (pp->p_child != NULL) {
1072 + if (PROC_IS_BRANDED(pp) && BROP(pp)->b_waitid_helper != NULL) {
1073 + have_brand_helper = B_TRUE;
1074 + }
982 1075
983 - proc_gone = 0;
1076 + while (pp->p_child != NULL || have_brand_helper) {
1077 + boolean_t brand_wants_wait = B_FALSE;
1078 + int proc_gone = 0;
1079 + int found = 0;
984 1080
1081 + /*
1082 + * Give the brand a chance to return synthetic results from
1083 + * this waitid() call before we do the real thing.
1084 + */
1085 + if (have_brand_helper) {
1086 + int ret;
1087 +
1088 + if (BROP(pp)->b_waitid_helper(idtype, id, ip, options,
1089 + &brand_wants_wait, &ret) == 0) {
1090 + mutex_exit(&pidlock);
1091 + return (ret);
1092 + }
1093 +
1094 + if (pp->p_child == NULL) {
1095 + goto no_real_children;
1096 + }
1097 + }
1098 +
1099 + /*
1100 + * Look for interesting children in the newstate list.
1101 + */
1102 + VERIFY(pp->p_child != NULL);
985 1103 for (cp = pp->p_child_ns; cp != NULL; cp = cp->p_sibling_ns) {
986 1104 if (idtype != P_PID && (cp->p_pidflag & CLDWAITPID))
987 1105 continue;
988 1106 if (idtype == P_PID && id != cp->p_pid)
989 1107 continue;
990 1108 if (idtype == P_PGID && id != cp->p_pgrp)
991 1109 continue;
1110 + if (PROC_IS_BRANDED(pp)) {
1111 + if (BROP(pp)->b_wait_filter != NULL &&
1112 + BROP(pp)->b_wait_filter(pp, cp) == B_FALSE)
1113 + continue;
1114 + }
992 1115
993 1116 switch (cp->p_wcode) {
994 1117
995 1118 case CLD_TRAPPED:
996 1119 case CLD_STOPPED:
997 1120 case CLD_CONTINUED:
998 1121 cmn_err(CE_PANIC,
999 1122 "waitid: wrong state %d on the p_newstate"
1000 1123 " list", cp->p_wcode);
1001 1124 break;
1002 1125
1003 1126 case CLD_EXITED:
1004 1127 case CLD_DUMPED:
1005 1128 case CLD_KILLED:
1006 1129 if (!(options & WEXITED)) {
1007 1130 /*
1008 1131 * Count how many are already gone
1009 1132 * for good.
1010 1133 */
1011 1134 proc_gone++;
1012 1135 break;
1013 1136 }
1014 1137 if (!waitflag) {
1015 1138 winfo(cp, ip, 0);
1016 1139 } else {
1017 1140 winfo(cp, ip, 1);
1018 1141 freeproc(cp);
1019 1142 }
1020 1143 mutex_exit(&pidlock);
1021 1144 if (waitflag) { /* accept SIGCLD */
1022 1145 sigcld_delete(ip);
1023 1146 sigcld_repost();
1024 1147 }
1025 1148 return (0);
|
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
1026 1149 }
1027 1150
1028 1151 if (idtype == P_PID)
1029 1152 break;
1030 1153 }
1031 1154
1032 1155 /*
1033 1156 * Wow! None of the threads on the p_sibling_ns list were
1034 1157 * interesting threads. Check all the kids!
1035 1158 */
1036 - found = 0;
1037 1159 for (cp = pp->p_child; cp != NULL; cp = cp->p_sibling) {
1038 1160 if (idtype == P_PID && id != cp->p_pid)
1039 1161 continue;
1040 1162 if (idtype == P_PGID && id != cp->p_pgrp)
1041 1163 continue;
1164 + if (PROC_IS_BRANDED(pp)) {
1165 + if (BROP(pp)->b_wait_filter != NULL &&
1166 + BROP(pp)->b_wait_filter(pp, cp) == B_FALSE)
1167 + continue;
1168 + }
1042 1169
1043 1170 switch (cp->p_wcode) {
1044 1171 case CLD_TRAPPED:
1045 1172 if (!(options & WTRAPPED))
1046 1173 break;
1047 1174 winfo(cp, ip, waitflag);
1048 1175 mutex_exit(&pidlock);
1049 1176 if (waitflag) { /* accept SIGCLD */
1050 1177 sigcld_delete(ip);
1051 1178 sigcld_repost();
1052 1179 }
1053 1180 return (0);
1054 1181
1055 1182 case CLD_STOPPED:
1056 1183 if (!(options & WSTOPPED))
1057 1184 break;
1058 1185 /* Is it still stopped? */
1059 1186 mutex_enter(&cp->p_lock);
1060 1187 if (!jobstopped(cp)) {
1061 1188 mutex_exit(&cp->p_lock);
1062 1189 break;
1063 1190 }
1064 1191 mutex_exit(&cp->p_lock);
1065 1192 winfo(cp, ip, waitflag);
1066 1193 mutex_exit(&pidlock);
1067 1194 if (waitflag) { /* accept SIGCLD */
1068 1195 sigcld_delete(ip);
1069 1196 sigcld_repost();
1070 1197 }
1071 1198 return (0);
1072 1199
1073 1200 case CLD_CONTINUED:
1074 1201 if (!(options & WCONTINUED))
1075 1202 break;
1076 1203 winfo(cp, ip, waitflag);
1077 1204 mutex_exit(&pidlock);
1078 1205 if (waitflag) { /* accept SIGCLD */
1079 1206 sigcld_delete(ip);
1080 1207 sigcld_repost();
1081 1208 }
1082 1209 return (0);
1083 1210
1084 1211 case CLD_EXITED:
1085 1212 case CLD_DUMPED:
1086 1213 case CLD_KILLED:
1087 1214 if (idtype != P_PID &&
1088 1215 (cp->p_pidflag & CLDWAITPID))
1089 1216 continue;
1090 1217 /*
1091 1218 * Don't complain if a process was found in
1092 1219 * the first loop but we broke out of the loop
1093 1220 * because of the arguments passed to us.
1094 1221 */
1095 1222 if (proc_gone == 0) {
1096 1223 cmn_err(CE_PANIC,
1097 1224 "waitid: wrong state on the"
1098 1225 " p_child list");
1099 1226 } else {
|
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
1100 1227 break;
1101 1228 }
1102 1229 }
1103 1230
1104 1231 found++;
1105 1232
1106 1233 if (idtype == P_PID)
1107 1234 break;
1108 1235 }
1109 1236
1237 +no_real_children:
1110 1238 /*
1111 1239 * If we found no interesting processes at all,
1112 1240 * break out and return ECHILD.
1113 1241 */
1114 - if (found + proc_gone == 0)
1242 + if (!brand_wants_wait && (found + proc_gone == 0))
1115 1243 break;
1116 1244
1117 1245 if (options & WNOHANG) {
1118 1246 mutex_exit(&pidlock);
1119 1247 bzero(ip, sizeof (k_siginfo_t));
1120 1248 /*
1121 1249 * We should set ip->si_signo = SIGCLD,
1122 1250 * but there is an SVVS test that expects
1123 1251 * ip->si_signo to be zero in this case.
1124 1252 */
1125 1253 return (0);
1126 1254 }
1127 1255
1128 1256 /*
1129 1257 * If we found no processes of interest that could
1130 1258 * change state while we wait, we don't wait at all.
1131 1259 * Get out with ECHILD according to SVID.
1132 1260 */
1133 - if (found == proc_gone)
1261 + if (!brand_wants_wait && (found == proc_gone))
1134 1262 break;
1135 1263
1136 1264 if (!cv_wait_sig_swap(&pp->p_cv, &pidlock)) {
1137 1265 mutex_exit(&pidlock);
1138 1266 return (EINTR);
1139 1267 }
1140 1268 }
1141 1269 mutex_exit(&pidlock);
1142 1270 return (ECHILD);
1143 1271 }
1144 1272
1145 1273 int
1146 1274 waitsys(idtype_t idtype, id_t id, siginfo_t *infop, int options)
1147 1275 {
1148 1276 int error;
1149 1277 k_siginfo_t info;
1150 1278
1151 1279 if (error = waitid(idtype, id, &info, options))
1152 1280 return (set_errno(error));
1153 1281 if (copyout(&info, infop, sizeof (k_siginfo_t)))
1154 1282 return (set_errno(EFAULT));
1155 1283 return (0);
1156 1284 }
1157 1285
1158 1286 #ifdef _SYSCALL32_IMPL
1159 1287
1160 1288 int
1161 1289 waitsys32(idtype_t idtype, id_t id, siginfo_t *infop, int options)
1162 1290 {
1163 1291 int error;
1164 1292 k_siginfo_t info;
1165 1293 siginfo32_t info32;
1166 1294
1167 1295 if (error = waitid(idtype, id, &info, options))
1168 1296 return (set_errno(error));
1169 1297 siginfo_kto32(&info, &info32);
1170 1298 if (copyout(&info32, infop, sizeof (info32)))
1171 1299 return (set_errno(EFAULT));
1172 1300 return (0);
1173 1301 }
1174 1302
1175 1303 #endif /* _SYSCALL32_IMPL */
1176 1304
1177 1305 void
1178 1306 proc_detach(proc_t *p)
1179 1307 {
1180 1308 proc_t *q;
1181 1309
1182 1310 ASSERT(MUTEX_HELD(&pidlock));
1183 1311
1184 1312 q = p->p_parent;
1185 1313 ASSERT(q != NULL);
1186 1314
1187 1315 /*
1188 1316 * Take it off the newstate list of its parent
1189 1317 */
1190 1318 delete_ns(q, p);
1191 1319
1192 1320 if (q->p_child == p) {
1193 1321 q->p_child = p->p_sibling;
1194 1322 /*
1195 1323 * If the parent has no children, it better not
1196 1324 * have any with new states either!
1197 1325 */
1198 1326 ASSERT(q->p_child ? 1 : q->p_child_ns == NULL);
1199 1327 }
1200 1328
1201 1329 if (p->p_sibling) {
1202 1330 p->p_sibling->p_psibling = p->p_psibling;
1203 1331 }
1204 1332
1205 1333 if (p->p_psibling) {
1206 1334 p->p_psibling->p_sibling = p->p_sibling;
1207 1335 }
1208 1336 }
1209 1337
1210 1338 /*
1211 1339 * Remove zombie children from the process table.
1212 1340 */
1213 1341 void
1214 1342 freeproc(proc_t *p)
1215 1343 {
1216 1344 proc_t *q;
1217 1345 task_t *tk;
1218 1346
|
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
1219 1347 ASSERT(p->p_stat == SZOMB);
1220 1348 ASSERT(p->p_tlist == NULL);
1221 1349 ASSERT(MUTEX_HELD(&pidlock));
1222 1350
1223 1351 sigdelq(p, NULL, 0);
1224 1352 if (p->p_killsqp) {
1225 1353 siginfofree(p->p_killsqp);
1226 1354 p->p_killsqp = NULL;
1227 1355 }
1228 1356
1357 + /* Clear any remaining brand data */
1358 + if (PROC_IS_BRANDED(p)) {
1359 + brand_clearbrand(p, B_FALSE);
1360 + }
1361 +
1362 +
1229 1363 prfree(p); /* inform /proc */
1230 1364
1231 1365 /*
1232 1366 * Don't free the init processes.
1233 1367 * Other dying processes will access it.
1234 1368 */
1235 1369 if (p == proc_init)
1236 1370 return;
1237 1371
1238 1372
1239 1373 /*
1240 1374 * We wait until now to free the cred structure because a
1241 1375 * zombie process's credentials may be examined by /proc.
1242 1376 * No cred locking needed because there are no threads at this point.
1243 1377 */
1244 1378 upcount_dec(crgetruid(p->p_cred), crgetzoneid(p->p_cred));
1245 1379 crfree(p->p_cred);
1246 1380 if (p->p_corefile != NULL) {
1247 1381 corectl_path_rele(p->p_corefile);
1248 1382 p->p_corefile = NULL;
1249 1383 }
1250 1384 if (p->p_content != NULL) {
1251 1385 corectl_content_rele(p->p_content);
1252 1386 p->p_content = NULL;
1253 1387 }
1254 1388
1255 1389 if (p->p_nextofkin && !((p->p_nextofkin->p_flag & SNOWAIT) ||
1256 1390 (PTOU(p->p_nextofkin)->u_signal[SIGCLD - 1] == SIG_IGN))) {
1257 1391 /*
1258 1392 * This should still do the right thing since p_utime/stime
1259 1393 * get set to the correct value on process exit, so it
1260 1394 * should get properly updated
1261 1395 */
1262 1396 p->p_nextofkin->p_cutime += p->p_utime;
1263 1397 p->p_nextofkin->p_cstime += p->p_stime;
1264 1398
1265 1399 p->p_nextofkin->p_cacct[LMS_USER] += p->p_acct[LMS_USER];
1266 1400 p->p_nextofkin->p_cacct[LMS_SYSTEM] += p->p_acct[LMS_SYSTEM];
1267 1401 p->p_nextofkin->p_cacct[LMS_TRAP] += p->p_acct[LMS_TRAP];
1268 1402 p->p_nextofkin->p_cacct[LMS_TFAULT] += p->p_acct[LMS_TFAULT];
1269 1403 p->p_nextofkin->p_cacct[LMS_DFAULT] += p->p_acct[LMS_DFAULT];
1270 1404 p->p_nextofkin->p_cacct[LMS_KFAULT] += p->p_acct[LMS_KFAULT];
1271 1405 p->p_nextofkin->p_cacct[LMS_USER_LOCK]
1272 1406 += p->p_acct[LMS_USER_LOCK];
1273 1407 p->p_nextofkin->p_cacct[LMS_SLEEP] += p->p_acct[LMS_SLEEP];
1274 1408 p->p_nextofkin->p_cacct[LMS_WAIT_CPU]
1275 1409 += p->p_acct[LMS_WAIT_CPU];
1276 1410 p->p_nextofkin->p_cacct[LMS_STOPPED] += p->p_acct[LMS_STOPPED];
1277 1411
1278 1412 p->p_nextofkin->p_cru.minflt += p->p_ru.minflt;
1279 1413 p->p_nextofkin->p_cru.majflt += p->p_ru.majflt;
1280 1414 p->p_nextofkin->p_cru.nswap += p->p_ru.nswap;
1281 1415 p->p_nextofkin->p_cru.inblock += p->p_ru.inblock;
1282 1416 p->p_nextofkin->p_cru.oublock += p->p_ru.oublock;
1283 1417 p->p_nextofkin->p_cru.msgsnd += p->p_ru.msgsnd;
1284 1418 p->p_nextofkin->p_cru.msgrcv += p->p_ru.msgrcv;
1285 1419 p->p_nextofkin->p_cru.nsignals += p->p_ru.nsignals;
1286 1420 p->p_nextofkin->p_cru.nvcsw += p->p_ru.nvcsw;
1287 1421 p->p_nextofkin->p_cru.nivcsw += p->p_ru.nivcsw;
1288 1422 p->p_nextofkin->p_cru.sysc += p->p_ru.sysc;
1289 1423 p->p_nextofkin->p_cru.ioch += p->p_ru.ioch;
1290 1424
1291 1425 }
1292 1426
1293 1427 q = p->p_nextofkin;
1294 1428 if (q && q->p_orphan == p)
1295 1429 q->p_orphan = p->p_nextorph;
1296 1430 else if (q) {
1297 1431 for (q = q->p_orphan; q; q = q->p_nextorph)
1298 1432 if (q->p_nextorph == p)
1299 1433 break;
1300 1434 ASSERT(q && q->p_nextorph == p);
1301 1435 q->p_nextorph = p->p_nextorph;
1302 1436 }
1303 1437
1304 1438 /*
1305 1439 * The process table slot is being freed, so it is now safe to give up
1306 1440 * task and project membership.
1307 1441 */
1308 1442 mutex_enter(&p->p_lock);
1309 1443 tk = p->p_task;
1310 1444 task_detach(p);
1311 1445 mutex_exit(&p->p_lock);
1312 1446
1313 1447 proc_detach(p);
1314 1448 pid_exit(p, tk); /* frees pid and proc structure */
1315 1449
1316 1450 task_rele(tk);
1317 1451 }
1318 1452
1319 1453 /*
1320 1454 * Delete process "child" from the newstate list of process "parent"
1321 1455 */
1322 1456 void
1323 1457 delete_ns(proc_t *parent, proc_t *child)
1324 1458 {
1325 1459 proc_t **ns;
1326 1460
1327 1461 ASSERT(MUTEX_HELD(&pidlock));
1328 1462 ASSERT(child->p_parent == parent);
1329 1463 for (ns = &parent->p_child_ns; *ns != NULL; ns = &(*ns)->p_sibling_ns) {
1330 1464 if (*ns == child) {
1331 1465
1332 1466 ASSERT((*ns)->p_parent == parent);
1333 1467
1334 1468 *ns = child->p_sibling_ns;
1335 1469 child->p_sibling_ns = NULL;
1336 1470 return;
1337 1471 }
1338 1472 }
1339 1473 }
1340 1474
1341 1475 /*
1342 1476 * Add process "child" to the new state list of process "parent"
1343 1477 */
1344 1478 void
1345 1479 add_ns(proc_t *parent, proc_t *child)
1346 1480 {
1347 1481 ASSERT(child->p_sibling_ns == NULL);
1348 1482 child->p_sibling_ns = parent->p_child_ns;
1349 1483 parent->p_child_ns = child;
1350 1484 }
|
↓ open down ↓ |
112 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX