|
From: <sv...@va...> - 2009-05-21 23:54:23
|
Author: njn
Date: 2009-05-22 00:54:19 +0100 (Fri, 22 May 2009)
New Revision: 10085
Log:
Make post-fork code clearer.
Modified:
branches/DARWIN/coregrind/m_syswrap/syswrap-generic.c
Modified: branches/DARWIN/coregrind/m_syswrap/syswrap-generic.c
===================================================================
--- branches/DARWIN/coregrind/m_syswrap/syswrap-generic.c 2009-05-21 23:53:40 UTC (rev 10084)
+++ branches/DARWIN/coregrind/m_syswrap/syswrap-generic.c 2009-05-21 23:54:19 UTC (rev 10085)
@@ -2885,7 +2885,8 @@
// ignore the various args it gets, and so it looks arch-neutral. Hmm.
PRE(sys_fork)
{
- UWord result;
+ Bool is_child;
+ Int child_pid;
vki_sigset_t mask;
PRINT("sys_fork ( )");
@@ -2901,15 +2902,18 @@
if (!SUCCESS) return;
#if defined(VGO_darwin)
- // RES is child's pid; RESHI is 1 for child, 0 for parent
- result = RESHI ? 0 : RES;
+ // RES is the child's pid. RESHI is 1 for child, 0 for parent.
+ is_child = RESHI;
+ child_pid = RES;
#else
- result = RES;
+ // RES is 0 for child, non-0 (the child's PID) for parent.
+ is_child = ( RES == 0 ? True : False );
+ child_pid = ( is_child ? -1 : RES );
#endif
VG_(do_atfork_pre)(tid);
- if (result == 0) {
+ if (is_child) {
/* child */
VG_(do_atfork_child)(tid);
@@ -2927,7 +2931,7 @@
/* parent */
VG_(do_atfork_parent)(tid);
- PRINT(" fork: process %d created child %ld\n", VG_(getpid)(), result);
+ PRINT(" fork: process %d created child %d\n", VG_(getpid)(), child_pid);
/* restore signal mask */
VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
|