Boost logo

Boost-Commit :

From: kbelco_at_[hidden]
Date: 2007-09-20 00:11:13


Author: noel_belcourt
Date: 2007-09-20 00:11:11 EDT (Thu, 20 Sep 2007)
New Revision: 39399
URL: http://svn.boost.org/trac/boost/changeset/39399

Log:
Fix a bug Chris Cambly reported with the timeout code on
AIX. Apparently AIX doesn't permit a forked process to
reference (set) memory in the parent's address space. No
other system seems to object to this practice but it taught
me a lesson!

The fix was to move the call to get the child process start
time directly before calling vfork. This isn't really fair
to the forked process as we start counting time against the
child process that we haven't even forked (we count the
vfork/exec call overhead against the child process).

Tested Rene's test.sh script on Sun, Linux, AIX, and Sgi.

Text files modified:
   trunk/tools/jam/src/execunix.c | 33 ++++++++++++++++++---------------
   1 files changed, 18 insertions(+), 15 deletions(-)

Modified: trunk/tools/jam/src/execunix.c
==============================================================================
--- trunk/tools/jam/src/execunix.c (original)
+++ trunk/tools/jam/src/execunix.c 2007-09-20 00:11:11 EDT (Thu, 20 Sep 2007)
@@ -63,7 +63,6 @@
 static struct timeval tv;
 static int intr = 0;
 static int cmdsrunning = 0;
-static void (*istat)( int );
 
 #define OUT 0
 #define ERR 1
@@ -161,8 +160,6 @@
             argv[3] = 0;
         }
 
- if (tps == 0) tps = sysconf(_SC_CLK_TCK);
-
         /* increment jobs running */
         ++cmdsrunning;
 
@@ -186,6 +183,24 @@
 
         /* Start the command */
 
+ if (0 < globs.timeout) {
+ struct tms buf;
+
+ /*
+ * handle hung processes using different mechanism
+ * manually track elapsed time and signal process
+ * when time limit expires
+ *
+ * could use this approach for both consuming too
+ * much cpu and hung processes, but it never hurts
+ * to have backup
+ */
+ cmdtab[ slot ].start_time = times(&buf);
+
+ /* make a global, only do this once */
+ if (tps == 0) tps = sysconf(_SC_CLK_TCK);
+ }
+
         if ((cmdtab[slot].pid = vfork()) == 0)
            {
             close(out[0]);
@@ -204,7 +219,6 @@
             /* terminate processes only if timeout is positive */
             if (0 < globs.timeout) {
               struct rlimit rl;
- struct tms buf;
 
               /*
                * set hard and soft resource limits for cpu usage
@@ -213,17 +227,6 @@
               rl.rlim_cur = globs.timeout;
               rl.rlim_max = globs.timeout;
               setrlimit(RLIMIT_CPU, &rl);
-
- /*
- * handle hung processes using different mechanism
- * manually track elapsed time and signal process
- * when time limit expires
- *
- * could use this approach for both consuming too
- * much cpu and hung processes, but it never hurts
- * to have backup
- */
- cmdtab[ slot ].start_time = times(&buf);
             }
 
             execvp( argv[0], argv );


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk