* procdesc_close() - last close on a process descriptor. If the process is * still running, terminate with SIGKILL (unless PDF_DAEMON is set) and let * its reaper clean up the mess; if not, we have to clean up the zombie * ourselves. */
| 348 | * ourselves. |
| 349 | */ |
| 350 | static int |
| 351 | procdesc_close(struct file *fp, struct thread *td) |
| 352 | { |
| 353 | struct procdesc *pd; |
| 354 | struct proc *p; |
| 355 | |
| 356 | KASSERT(fp->f_type == DTYPE_PROCDESC, ("procdesc_close: !procdesc")); |
| 357 | |
| 358 | pd = fp->f_data; |
| 359 | fp->f_ops = &badfileops; |
| 360 | fp->f_data = NULL; |
| 361 | |
| 362 | sx_xlock(&proctree_lock); |
| 363 | PROCDESC_LOCK(pd); |
| 364 | pd->pd_flags |= PDF_CLOSED; |
| 365 | PROCDESC_UNLOCK(pd); |
| 366 | p = pd->pd_proc; |
| 367 | if (p == NULL) { |
| 368 | /* |
| 369 | * This is the case where process' exit status was already |
| 370 | * collected and procdesc_reap() was already called. |
| 371 | */ |
| 372 | sx_xunlock(&proctree_lock); |
| 373 | } else { |
| 374 | PROC_LOCK(p); |
| 375 | AUDIT_ARG_PROCESS(p); |
| 376 | if (p->p_state == PRS_ZOMBIE) { |
| 377 | /* |
| 378 | * If the process is already dead and just awaiting |
| 379 | * reaping, do that now. This will release the |
| 380 | * process's reference to the process descriptor when it |
| 381 | * calls back into procdesc_reap(). |
| 382 | */ |
| 383 | proc_reap(curthread, p, NULL, 0); |
| 384 | } else { |
| 385 | /* |
| 386 | * If the process is not yet dead, we need to kill it, |
| 387 | * but we can't wait around synchronously for it to go |
| 388 | * away, as that path leads to madness (and deadlocks). |
| 389 | * First, detach the process from its descriptor so that |
| 390 | * its exit status will be reported normally. |
| 391 | */ |
| 392 | pd->pd_proc = NULL; |
| 393 | p->p_procdesc = NULL; |
| 394 | procdesc_free(pd); |
| 395 | |
| 396 | /* |
| 397 | * Next, reparent it to its reaper (usually init(8)) so |
| 398 | * that there's someone to pick up the pieces; finally, |
| 399 | * terminate with prejudice. |
| 400 | */ |
| 401 | p->p_sigparent = SIGCHLD; |
| 402 | if ((p->p_flag & P_TRACED) == 0) { |
| 403 | proc_reparent(p, p->p_reaper, true); |
| 404 | } else { |
| 405 | proc_clear_orphan(p); |
| 406 | p->p_oppid = p->p_reaper->p_pid; |
| 407 | proc_add_orphan(p, p->p_reaper); |
nothing calls this directly
no test coverage detected