Boost logo

Boost-Commit :

From: kbelco_at_[hidden]
Date: 2007-09-20 15:06:55


Author: noel_belcourt
Date: 2007-09-20 15:06:54 EDT (Thu, 20 Sep 2007)
New Revision: 39423
URL: http://svn.boost.org/trac/boost/changeset/39423

Log:
Added diagnostic message to output.c to inform users
when a process has timed out and been killed.

Because timed out processes now emit a diagnostic, I
had to update option_l.jam so we wouldn't break test.sh
when it runs.

Minor cleanup to execunix.c to remove unneeded code
and to set the process exit status as returned from
waitpid. The exit status is used to identify timed
out processes so we can emit a diagnostic to the user.

Text files modified:
   trunk/tools/jam/src/execunix.c | 40 ++++++++++++++++------------------------
   trunk/tools/jam/src/output.c | 16 ++++++++++++++++
   trunk/tools/jam/test/option_l.jam | 1 +
   3 files changed, 33 insertions(+), 24 deletions(-)

Modified: trunk/tools/jam/src/execunix.c
==============================================================================
--- trunk/tools/jam/src/execunix.c (original)
+++ trunk/tools/jam/src/execunix.c 2007-09-20 15:06:54 EDT (Thu, 20 Sep 2007)
@@ -73,6 +73,7 @@
     int fd[2]; /* file descriptors for stdout and stderr */
     FILE *stream[2]; /* child's stdout (0) and stderr (1) file stream */
     clock_t start_time; /* start time of child process */
+ int exit_reason; /* termination status */
     int action_length; /* length of action string */
     int target_length; /* length of target string */
     char *action; /* buffer to hold action and target invoked */
@@ -184,17 +185,11 @@
         /* 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
+ /*
+ * handle hung processes by manually tracking elapsed
+ * time and signal process when time limit expires
              */
+ struct tms buf;
             cmdtab[ slot ].start_time = times(&buf);
 
             /* make a global, only do this once */
@@ -216,19 +211,6 @@
             else
                 dup2(err[1], STDERR_FILENO);
 
- /* terminate processes only if timeout is positive */
- if (0 < globs.timeout) {
- struct rlimit rl;
-
- /*
- * set hard and soft resource limits for cpu usage
- * won't catch hung processes that don't consume cpu
- */
- rl.rlim_cur = globs.timeout;
- rl.rlim_max = globs.timeout;
- setrlimit(RLIMIT_CPU, &rl);
- }
-
             execvp( argv[0], argv );
             _exit(127);
         }
@@ -386,6 +368,7 @@
             clock_t current = times(&buf);
             if (globs.timeout <= (current-cmdtab[i].start_time)/tps) {
                 kill(cmdtab[i].pid, SIGKILL);
+ cmdtab[i].exit_reason = EXIT_TIMEOUT;
             }
         }
     }
@@ -469,12 +452,21 @@
                         pid = 0;
                         cmdtab[i].pid = 0;
 
+ /* set reason for exit if not timed out */
+ if (WIFEXITED(status))
+ {
+ if (0 == WEXITSTATUS(status))
+ cmdtab[i].exit_reason = EXIT_OK;
+ else
+ cmdtab[i].exit_reason = EXIT_FAIL;
+ }
+
                         times(&old_time);
 
                         /* print out the rule and target name */
                         out_action(cmdtab[i].action, cmdtab[i].target,
                             cmdtab[i].command, cmdtab[i].buffer[OUT], cmdtab[i].buffer[ERR],
- EXIT_OK);
+ cmdtab[i].exit_reason);
 
                         times(&new_time);
 

Modified: trunk/tools/jam/src/output.c
==============================================================================
--- trunk/tools/jam/src/output.c (original)
+++ trunk/tools/jam/src/output.c 2007-09-20 15:06:54 EDT (Thu, 20 Sep 2007)
@@ -53,6 +53,22 @@
     {
         fputs(command,globs.cmdout);
     }
+
+ switch (exit_reason)
+ {
+ case EXIT_OK:
+ break;
+ case EXIT_FAIL:
+ break;
+ case EXIT_TIMEOUT:
+ {
+ /* process expired, make user aware with explicit message */
+ fprintf(bjam_out, "%d second time limit exceeded\n", globs.timeout);
+ break;
+ }
+ default:
+ break;
+ }
     
     /* print out the command output, if requested */
     if (0 != out_data &&

Modified: trunk/tools/jam/test/option_l.jam
==============================================================================
--- trunk/tools/jam/test/option_l.jam (original)
+++ trunk/tools/jam/test/option_l.jam 2007-09-20 15:06:54 EDT (Thu, 20 Sep 2007)
@@ -8,6 +8,7 @@
     assert "...found 2 targets...
 ...updating 1 target...
 .a. sleeper
+2 second time limit exceeded
 001
 
 echo 001


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