[PATCH 1/3] New function to handle parent relationship of new child
Wang Chao
wang.chao at cn.fujitsu.com
Thu Sep 16 08:34:12 UTC 2010
* defs.h [LINUX] (reparent): New function declaration.
* process.c [LINUX] (reparent): New function.
[LINUX] (internal_fork): Move code that handles parent relationship of
new child process to the new function, and call it instead.
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 fc7e362..0b3ba43 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 8999fc6..3cf6d28 100644
--- a/process.c
+++ b/process.c
@@ -792,6 +792,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)
{
@@ -884,44 +924,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