FreeBSD Bugzilla – Attachment 187941 Details for
Bug 201276
truss(1): truss -f doesn't followed pdfork()ed descendents
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Special case traced pdfork processes in wait6
special-case-traced-procs-in-wait6.patch (text/plain), 3.80 KB, created by
Jan Kokemüller
on 2017-11-12 15:15:22 UTC
(
hide
)
Description:
Special case traced pdfork processes in wait6
Filename:
MIME Type:
Creator:
Jan Kokemüller
Created:
2017-11-12 15:15:22 UTC
Size:
3.80 KB
patch
obsolete
>diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c >index d05951e150c8..4a9af5be583e 100644 >--- a/sys/kern/kern_exit.c >+++ b/sys/kern/kern_exit.c >@@ -337,6 +337,9 @@ exit1(struct thread *td, int rval, int signo) > */ > PROC_LOCK(p); > stopprofclock(p); >+ if (p->p_flag & P_TRACED) { >+ p->p_flag2 |= P2_P_ALL_NOTI; >+ } > p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE); > p->p_ptevents = 0; > >@@ -559,7 +562,8 @@ exit1(struct thread *td, int rval, int signo) > * procdesc_exit() to serialize concurrent calls to close() and > * exit(). > */ >- if (p->p_procdesc == NULL || procdesc_exit(p)) { >+ if (p->p_procdesc == NULL || procdesc_exit(p) || >+ (p->p_flag & P_TRACED)) { > /* > * Notify parent that we're gone. If parent has the > * PS_NOCLDWAIT flag set, or if the handler is set to SIG_IGN, >@@ -951,7 +955,15 @@ proc_to_reap(struct thread *td, struct proc *p, idtype_t idtype, id_t id, > > switch (idtype) { > case P_ALL: >- if (p->p_procdesc != NULL) { >+ /* >+ * Usually, processes created with pdfork(2) should be >+ * invisible to wait(2) when using P_ALL. However, ptrace(2) in >+ * PTRACE_FORK mode does not know whether a process was created >+ * by pdfork(2) or fork(2) and expects the tracing process >+ * to deal with the new process in its event loop. >+ */ >+ if (p->p_procdesc != NULL && !(p->p_flag & P_TRACED) && >+ !(p->p_flag2 & P2_P_ALL_NOTI)) { > PROC_UNLOCK(p); > return (0); > } >diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c >index 5f2c9ec69805..ab0d31a536da 100644 >--- a/sys/kern/sys_procdesc.c >+++ b/sys/kern/sys_procdesc.c >@@ -399,26 +399,35 @@ procdesc_close(struct file *fp, struct thread *td) > PROC_SLOCK(p); > proc_reap(curthread, p, NULL, 0); > } else { >- /* >- * If the process is not yet dead, we need to kill it, >- * but we can't wait around synchronously for it to go >- * away, as that path leads to madness (and deadlocks). >- * First, detach the process from its descriptor so that >- * its exit status will be reported normally. >- */ >- pd->pd_proc = NULL; >- p->p_procdesc = NULL; >- procdesc_free(pd); >+ /* we don't need to do the following if we are already >+ * exiting */ >+ if (!(p->p_flag & P_WEXIT)) { >+ /* >+ * If the process is not yet dead, we need to >+ * kill it, but we can't wait around >+ * synchronously for it to go away, as that >+ * path leads to madness (and deadlocks). >+ * First, detach the process from its >+ * descriptor so that its exit status will be >+ * reported normally. >+ */ >+ pd->pd_proc = NULL; >+ p->p_procdesc = NULL; >+ procdesc_free(pd); >+ >+ /* >+ * Next, reparent it to init(8) so that there's >+ * someone to pick up the pieces; finally, >+ * terminate with prejudice. >+ */ >+ p->p_sigparent = SIGCHLD; >+ if (!(p->p_flag & P_TRACED)) { >+ proc_reparent(p, initproc); >+ } >+ if ((pd->pd_flags & PDF_DAEMON) == 0) >+ kern_psignal(p, SIGKILL); >+ } > >- /* >- * Next, reparent it to init(8) so that there's someone >- * to pick up the pieces; finally, terminate with >- * prejudice. >- */ >- p->p_sigparent = SIGCHLD; >- proc_reparent(p, initproc); >- if ((pd->pd_flags & PDF_DAEMON) == 0) >- kern_psignal(p, SIGKILL); > PROC_UNLOCK(p); > sx_xunlock(&proctree_lock); > } >diff --git a/sys/sys/proc.h b/sys/sys/proc.h >index 2daf1a6aee7d..24434994bab8 100644 >--- a/sys/sys/proc.h >+++ b/sys/sys/proc.h >@@ -730,6 +730,7 @@ struct proc { > #define P2_AST_SU 0x00000008 /* Handles SU ast for kthreads. */ > #define P2_PTRACE_FSTP 0x00000010 /* SIGSTOP from PT_ATTACH not yet handled. */ > #define P2_TRAPCAP 0x00000020 /* SIGTRAP on ENOTCAPABLE */ >+#define P2_P_ALL_NOTI 0x00000040 /* force notification in wait(2) P_ALL */ > > /* Flags protected by proctree_lock, kept in p_treeflags. */ > #define P_TREE_ORPHANED 0x00000001 /* Reparented, on orphan list */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 201276
:
187941
|
198099