[PATCH 1/2] Prepare to trace fork series calls using PTRACE_SETOPTIONS
Wang Chao
wang.chao at cn.fujitsu.com
Wed Sep 1 09:17:34 UTC 2010
* defs.h: Add new function declaration.
* process.c (reparent): Move code which handle parent relationship
of new child process to a new function.
(internal_fork): Call it.
Signed-off-by: Wang Chao <wang.chao at cn.fujitsu.com>
---
defs.h | 3 ++
process.c | 79 +++++++++++++++++++++++++++++++-----------------------------
2 files changed, 44 insertions(+), 38 deletions(-)
diff --git a/defs.h b/defs.h
index 4b9c29e..a813f5b 100644
--- a/defs.h
+++ b/defs.h
@@ -545,6 +545,9 @@ extern int internal_fork(struct tcb *);
extern int internal_exec(struct tcb *);
extern int internal_wait(struct tcb *, int);
extern int internal_exit(struct tcb *);
+#ifdef LINUX
+extern void reparent(struct tcb *, struct tcb *);
+#endif
extern const struct ioctlent *ioctl_lookup(long);
extern const struct ioctlent *ioctl_next_match(const struct ioctlent *);
diff --git a/process.c b/process.c
index f7af196..7f9353a 100644
--- a/process.c
+++ b/process.c
@@ -790,6 +790,46 @@ change_syscall(struct tcb *tcp, int new)
}
#ifdef LINUX
+void reparent(struct tcb *tcp, struct tcb *tcpchild)
+{
+ /*
+ * Save the flags used in this call,
+ * in case we point TCP to our parent below.
+ */
+ int call_flags = tcp->u_arg[ARG_FLAGS];
+ if ((tcp->flags & TCB_CLONE_THREAD) &&
+ tcp->parent != NULL) {
+ /* The parent in this clone is itself a
+ thread belonging to another process.
+ There is no meaning to the parentage
+ relationship of the new child with the
+ thread, only with the process. We
+ associate the new thread with our
+ parent. Since this is done for every
+ new thread, there will never be a
+ TCB_CLONE_THREAD process that has
+ children. */
+ --tcp->nchildren;
+ tcp = tcp->parent;
+ tcpchild->parent = tcp;
+ ++tcp->nchildren;
+ }
+ if (call_flags & CLONE_THREAD) {
+ tcpchild->flags |= TCB_CLONE_THREAD;
+ ++tcp->nclone_threads;
+ }
+ if ((call_flags & CLONE_PARENT) &&
+ !(call_flags & CLONE_THREAD)) {
+ --tcp->nchildren;
+ tcpchild->parent = NULL;
+ if (tcp->parent != NULL) {
+ tcp = tcp->parent;
+ tcpchild->parent = tcp;
+ ++tcp->nchildren;
+ }
+ }
+}
+
int
internal_fork(struct tcb *tcp)
{
@@ -882,44 +922,7 @@ Process %u resumed (parent %d ready)\n",
}
#ifdef TCB_CLONE_THREAD
- {
- /*
- * Save the flags used in this call,
- * in case we point TCP to our parent below.
- */
- int call_flags = tcp->u_arg[ARG_FLAGS];
- if ((tcp->flags & TCB_CLONE_THREAD) &&
- tcp->parent != NULL) {
- /* The parent in this clone is itself a
- thread belonging to another process.
- There is no meaning to the parentage
- relationship of the new child with the
- thread, only with the process. We
- associate the new thread with our
- parent. Since this is done for every
- new thread, there will never be a
- TCB_CLONE_THREAD process that has
- children. */
- --tcp->nchildren;
- tcp = tcp->parent;
- tcpchild->parent = tcp;
- ++tcp->nchildren;
- }
- if (call_flags & CLONE_THREAD) {
- tcpchild->flags |= TCB_CLONE_THREAD;
- ++tcp->nclone_threads;
- }
- if ((call_flags & CLONE_PARENT) &&
- !(call_flags & CLONE_THREAD)) {
- --tcp->nchildren;
- tcpchild->parent = NULL;
- if (tcp->parent != NULL) {
- tcp = tcp->parent;
- tcpchild->parent = tcp;
- ++tcp->nchildren;
- }
- }
- }
+ reparent(tcp, tcpchild);
#endif /* TCB_CLONE_THREAD */
}
return 0;
--
1.6.5.2
More information about the Strace-devel
mailing list