diff options
-rw-r--r-- | ChangeLog | 34 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 34 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 34 | ||||
-rwxr-xr-x | bin/auto_compile | 16 | ||||
-rw-r--r-- | bin/sandbox.cpp | 165 |
5 files changed, 249 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog index 167d97cfb89..6c944b72149 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,32 @@ +Thu Dec 28 16:02:51 2000 Carlos O'Ryan <coryan@uci.edu> + + * bin/sandbox.cpp: + This program executes a child process (and its children), in a + new session and process group. If the process tree does not + finish before a given timeout (the first argument) the whole + tree is terminated. + The program is useful for test scripts and programs, + occasionally they hang the whole auto build. + + * bin/auto_compile: + Add new options '-sandbox' and '-sandbox_timeout' to support the + sandbox program. + Thu Dec 28 16:10:59 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * performance-tests/UDP/udp_test.cpp: - * performance-tests/Server_Concurrency/Latency_Stats.h: - * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp - * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp - Fixed compile problems under VxWorks when handling - 64 bit integers. Basically, truncated the 64 bit integers - to 32 bit integers for operations not supported by - ACE_U_LongLong. + * performance-tests/UDP/udp_test.cpp: + * performance-tests/Server_Concurrency/Latency_Stats.h: + * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp + * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp + Fixed compile problems under VxWorks when handling + 64 bit integers. Basically, truncated the 64 bit integers + to 32 bit integers for operations not supported by + ACE_U_LongLong. Wed Dec 27 15:32:43 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * examples/Reactor/WFMO_Reactor/test_network_events.cpp: - Added missing ; + * examples/Reactor/WFMO_Reactor/test_network_events.cpp: + Added missing ; Wed Dec 27 11:11:02 2000 Carlos O'Ryan <coryan@uci.edu> diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 167d97cfb89..6c944b72149 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,18 +1,32 @@ +Thu Dec 28 16:02:51 2000 Carlos O'Ryan <coryan@uci.edu> + + * bin/sandbox.cpp: + This program executes a child process (and its children), in a + new session and process group. If the process tree does not + finish before a given timeout (the first argument) the whole + tree is terminated. + The program is useful for test scripts and programs, + occasionally they hang the whole auto build. + + * bin/auto_compile: + Add new options '-sandbox' and '-sandbox_timeout' to support the + sandbox program. + Thu Dec 28 16:10:59 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * performance-tests/UDP/udp_test.cpp: - * performance-tests/Server_Concurrency/Latency_Stats.h: - * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp - * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp - Fixed compile problems under VxWorks when handling - 64 bit integers. Basically, truncated the 64 bit integers - to 32 bit integers for operations not supported by - ACE_U_LongLong. + * performance-tests/UDP/udp_test.cpp: + * performance-tests/Server_Concurrency/Latency_Stats.h: + * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp + * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp + Fixed compile problems under VxWorks when handling + 64 bit integers. Basically, truncated the 64 bit integers + to 32 bit integers for operations not supported by + ACE_U_LongLong. Wed Dec 27 15:32:43 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * examples/Reactor/WFMO_Reactor/test_network_events.cpp: - Added missing ; + * examples/Reactor/WFMO_Reactor/test_network_events.cpp: + Added missing ; Wed Dec 27 11:11:02 2000 Carlos O'Ryan <coryan@uci.edu> diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 167d97cfb89..6c944b72149 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,18 +1,32 @@ +Thu Dec 28 16:02:51 2000 Carlos O'Ryan <coryan@uci.edu> + + * bin/sandbox.cpp: + This program executes a child process (and its children), in a + new session and process group. If the process tree does not + finish before a given timeout (the first argument) the whole + tree is terminated. + The program is useful for test scripts and programs, + occasionally they hang the whole auto build. + + * bin/auto_compile: + Add new options '-sandbox' and '-sandbox_timeout' to support the + sandbox program. + Thu Dec 28 16:10:59 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * performance-tests/UDP/udp_test.cpp: - * performance-tests/Server_Concurrency/Latency_Stats.h: - * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp - * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp - Fixed compile problems under VxWorks when handling - 64 bit integers. Basically, truncated the 64 bit integers - to 32 bit integers for operations not supported by - ACE_U_LongLong. + * performance-tests/UDP/udp_test.cpp: + * performance-tests/Server_Concurrency/Latency_Stats.h: + * performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp + * performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp + Fixed compile problems under VxWorks when handling + 64 bit integers. Basically, truncated the 64 bit integers + to 32 bit integers for operations not supported by + ACE_U_LongLong. Wed Dec 27 15:32:43 2000 Frank Hunleth <fhunleth@cs.wustl.edu> - * examples/Reactor/WFMO_Reactor/test_network_events.cpp: - Added missing ; + * examples/Reactor/WFMO_Reactor/test_network_events.cpp: + Added missing ; Wed Dec 27 11:11:02 2000 Carlos O'Ryan <coryan@uci.edu> diff --git a/bin/auto_compile b/bin/auto_compile index 118c5483ea3..ec3c368774d 100755 --- a/bin/auto_compile +++ b/bin/auto_compile @@ -51,6 +51,8 @@ $pre_realclean = 0; $post_realclean = 0; $report_success = 0; $debug = 0; +$sandbox = ''; +$sandbox_timeout = 600; @BUILD_LIST= (); @CONFIGURATION_OPTIONS = (); @@ -90,10 +92,12 @@ while ($#ARGV >= 0) { shift; $copy_logs = 1; $LOG_DESTINATION = $ARGV[0]; - } elsif ($ARGV[0] eq "-mail_logs") { + } elsif ($ARGV[0] eq "-sandbox") { shift; - $copy_logs = 0; - $LOG_DESTINATION = $ARGV[0]; + $sandbox = $ARGV[0]; + } elsif ($ARGV[0] eq "-sandbox_timeout") { + shift; + $sandbox_timeout = $ARGV[0]; } elsif ($ARGV[0] eq "-dont_run") { $dont_run = 1; } elsif ($ARGV[0] eq "-pre_realclean") { @@ -448,7 +452,11 @@ if ($dont_run == 0) { || mydie "cannot chdir to $subdir"; $run_error = 0; - if (open(RUN, "perl $program 2>&1 |") == 0) { + my $prefix = ''; + if ($sandbox ne "") { + $prefix = $sandbox.' '.$sandbox_timeout.' '; + } + if (open(RUN, $prefix."perl $program 2>&1 |") == 0) { push @failures, "cannot run $program in $directory"; next; } diff --git a/bin/sandbox.cpp b/bin/sandbox.cpp new file mode 100644 index 00000000000..d3f3b54f27a --- /dev/null +++ b/bin/sandbox.cpp @@ -0,0 +1,165 @@ +// +// $Id$ +// +#include <stdio.h> +#include <stdlib.h> + +#include <unistd.h> +#include <signal.h> +#include <sys/wait.h> +#include <sys/types.h> + +/// Run by the child process +static int child(int argc, char* argv[]); + +static int max_child_time = 300; +const char *child_name = 0; + +static int parse_args(int& argc, char* argv[]); + +int +main(int argc, char* argv[]) +{ + if (parse_args(argc, argv) != 0) + return 1; + + pid_t pid = fork(); + if (pid == -1) { + fprintf(stderr, "Error in fork\n"); + return 1; + } + + if (pid == 0) { + // In the child... + return child(argc, argv); + } + + int status; + pid_t child = waitpid(pid, &status, 0); + if (child == -1) { + fprintf(stderr, "sandbox: error waiting for child\n"); + return 1; + } + // Return whatever status the child has... + return status; +} + +sig_atomic_t child_died = 0; + +extern "C" void +sigchld_handler(int signal) +{ + child_died = 1; +} + + +static int +child (int /* argc */, char* argv[]) +{ + // The child becomes its own session, implicitly this turns the + // child process into its own process group leader, allowing us to + // terminate a hierarchy of children easily. + pid_t sid = setsid(); + if (sid == -1) + { + fprintf(stderr, "sandbox: error in setid\n"); + return 1; + } + + // Setup the signal handler to receive SIGCHLD signals: + (void) signal(SIGCHLD, sigchld_handler); + + // Now we must fork again to wait for the grandchild process... + + pid_t grandchild = fork(); + if (grandchild == 0) { + // Exec the arguments... + int r = execvp(child_name, argv); + if (r == -1) { + fprintf(stderr, "sandbox: error in execvp()\n"); + return 1; + } + } + + // As the process leader we wait until the child returns or there is + // a timeout... + + int status; + int remaining_time = max_child_time; + + while (remaining_time != 0) + { + // We use the signal handler to return from sleep before all the + // time expires + remaining_time = sleep(remaining_time); + + // We could exit + if (child_died) + { + pid_t child = waitpid(grandchild, &status, WNOHANG); + if (child == -1) + { + fprintf(stderr, + "sandbox: no grandchild process (%d), panic\n", + grandchild); + return 1; + } + if (child != 0) + { + printf("sandbox: grandchild %d exits with status %d\n", + child, status); + return status; + } + } + } + + printf("sandbox: timeout for grandchild %d\n", grandchild); + + // timeout, kill the progress group (that is commit suicide!) + killpg(getpgrp(), SIGTERM); + + printf("sandbox: ooops! I should be dead!\n"); +#if 0 + // timeout kill the child... + (void) kill(child_pid, SIGTERM); sleep(1); + pid_t child = waitpid(child, &status, WNOHANG); + if (child == 0) + { + // TERM did not work, use the heavy duty signal + (void) kill(child_pid, SIGQUIT); sleep(1); + child = waitpid(child, &status, WNOHANG); + } + if (child == -1) + { + fprintf(stderr, "No such child (%d), panic\n", + child_pid); + return 1; + } + + fprintf(stderr, "Child timeout\n"); +#endif + return 1; +} + +static int +parse_args(int &argc, char* argv[]) +{ + if (argc < 3) { + fprintf(stderr, "Usage: sandbox max_time program arguments\n"); + return 1; + } + + max_child_time = atoi(argv[1]); + child_name = argv[2]; + argc -= 2; + for (int i = 0; i != argc; ++i) + { + argv[i] = argv[i + 2]; + } + argv[argc] = 0; + + if (child_name == 0) + return 1; + + return 0; +} |