View | Details | Raw Unified | Return to bug 201276 | Differences between
and this patch

Collapse All | Expand All

(-)b/sys/kern/kern_exit.c (-2 / +14 lines)
Lines 337-342 exit1(struct thread *td, int rval, int signo) Link Here
337
	 */
337
	 */
338
	PROC_LOCK(p);
338
	PROC_LOCK(p);
339
	stopprofclock(p);
339
	stopprofclock(p);
340
	if (p->p_flag & P_TRACED) {
341
		p->p_flag2 |= P2_P_ALL_NOTI;
342
	}
340
	p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
343
	p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
341
	p->p_ptevents = 0;
344
	p->p_ptevents = 0;
342
345
Lines 559-565 exit1(struct thread *td, int rval, int signo) Link Here
559
	 * procdesc_exit() to serialize concurrent calls to close() and
562
	 * procdesc_exit() to serialize concurrent calls to close() and
560
	 * exit().
563
	 * exit().
561
	 */
564
	 */
562
	if (p->p_procdesc == NULL || procdesc_exit(p)) {
565
	if (p->p_procdesc == NULL || procdesc_exit(p) ||
566
	    (p->p_flag & P_TRACED)) {
563
		/*
567
		/*
564
		 * Notify parent that we're gone.  If parent has the
568
		 * Notify parent that we're gone.  If parent has the
565
		 * PS_NOCLDWAIT flag set, or if the handler is set to SIG_IGN,
569
		 * PS_NOCLDWAIT flag set, or if the handler is set to SIG_IGN,
Lines 951-957 proc_to_reap(struct thread *td, struct proc *p, idtype_t idtype, id_t id, Link Here
951
955
952
	switch (idtype) {
956
	switch (idtype) {
953
	case P_ALL:
957
	case P_ALL:
954
		if (p->p_procdesc != NULL) {
958
		/*
959
		 * Usually, processes created with pdfork(2) should be
960
		 * invisible to wait(2) when using P_ALL. However, ptrace(2) in
961
		 * PTRACE_FORK mode does not know whether a process was created
962
		 * by pdfork(2) or fork(2) and expects the tracing process
963
		 * to deal with the new process in its event loop.
964
		 */
965
		if (p->p_procdesc != NULL && !(p->p_flag & P_TRACED) &&
966
		    !(p->p_flag2 & P2_P_ALL_NOTI)) {
955
			PROC_UNLOCK(p);
967
			PROC_UNLOCK(p);
956
			return (0);
968
			return (0);
957
		}
969
		}
(-)b/sys/kern/sys_procdesc.c (-19 / +28 lines)
Lines 399-424 procdesc_close(struct file *fp, struct thread *td) Link Here
399
			PROC_SLOCK(p);
399
			PROC_SLOCK(p);
400
			proc_reap(curthread, p, NULL, 0);
400
			proc_reap(curthread, p, NULL, 0);
401
		} else {
401
		} else {
402
			/*
402
			/* we don't need to do the following if we are already
403
			 * If the process is not yet dead, we need to kill it,
403
			 * exiting */
404
			 * but we can't wait around synchronously for it to go
404
			if (!(p->p_flag & P_WEXIT)) {
405
			 * away, as that path leads to madness (and deadlocks).
405
				/*
406
			 * First, detach the process from its descriptor so that
406
				 * If the process is not yet dead, we need to
407
			 * its exit status will be reported normally.
407
				 * kill it, but we can't wait around
408
			 */
408
				 * synchronously for it to go away, as that
409
			pd->pd_proc = NULL;
409
				 * path leads to madness (and deadlocks).
410
			p->p_procdesc = NULL;
410
				 * First, detach the process from its
411
			procdesc_free(pd);
411
				 * descriptor so that its exit status will be
412
				 * reported normally.
413
				 */
414
				pd->pd_proc = NULL;
415
				p->p_procdesc = NULL;
416
				procdesc_free(pd);
417
418
				/*
419
				 * Next, reparent it to init(8) so that there's
420
				 * someone to pick up the pieces; finally,
421
				 * terminate with prejudice.
422
				 */
423
				p->p_sigparent = SIGCHLD;
424
				if (!(p->p_flag & P_TRACED)) {
425
					proc_reparent(p, initproc);
426
				}
427
				if ((pd->pd_flags & PDF_DAEMON) == 0)
428
					kern_psignal(p, SIGKILL);
429
			}
412
430
413
			/*
414
			 * Next, reparent it to init(8) so that there's someone
415
			 * to pick up the pieces; finally, terminate with
416
			 * prejudice.
417
			 */
418
			p->p_sigparent = SIGCHLD;
419
			proc_reparent(p, initproc);
420
			if ((pd->pd_flags & PDF_DAEMON) == 0)
421
				kern_psignal(p, SIGKILL);
422
			PROC_UNLOCK(p);
431
			PROC_UNLOCK(p);
423
			sx_xunlock(&proctree_lock);
432
			sx_xunlock(&proctree_lock);
424
		}
433
		}
(-)b/sys/sys/proc.h (+1 lines)
Lines 730-735 struct proc { Link Here
730
#define	P2_AST_SU	0x00000008	/* Handles SU ast for kthreads. */
730
#define	P2_AST_SU	0x00000008	/* Handles SU ast for kthreads. */
731
#define	P2_PTRACE_FSTP	0x00000010 /* SIGSTOP from PT_ATTACH not yet handled. */
731
#define	P2_PTRACE_FSTP	0x00000010 /* SIGSTOP from PT_ATTACH not yet handled. */
732
#define	P2_TRAPCAP	0x00000020	/* SIGTRAP on ENOTCAPABLE */
732
#define	P2_TRAPCAP	0x00000020	/* SIGTRAP on ENOTCAPABLE */
733
#define	P2_P_ALL_NOTI	0x00000040 /* force notification in wait(2) P_ALL */
733
734
734
/* Flags protected by proctree_lock, kept in p_treeflags. */
735
/* Flags protected by proctree_lock, kept in p_treeflags. */
735
#define	P_TREE_ORPHANED		0x00000001	/* Reparented, on orphan list */
736
#define	P_TREE_ORPHANED		0x00000001	/* Reparented, on orphan list */

Return to bug 201276