diff options
author | Steve Huston <shuston@riverace.com> | 2007-06-28 15:20:48 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2007-06-28 15:20:48 +0000 |
commit | 189825e9d1ed5b5cfb272db52d61259cf867b0ab (patch) | |
tree | 1e6b21254258901963bcf81221c4f192260903e4 /ACE | |
parent | b0d2fe6a829e86ca2baf7543478a9f9e8c45807c (diff) | |
download | ATCD-189825e9d1ed5b5cfb272db52d61259cf867b0ab.tar.gz |
ChangeLogTag:Thu Jun 28 15:18:35 UTC 2007 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ACE')
-rw-r--r-- | ACE/ChangeLog | 5 | ||||
-rw-r--r-- | ACE/bin/sandbox.cpp | 167 |
2 files changed, 5 insertions, 167 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 2837d99cf3b..fb3e7238476 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 28 15:18:35 UTC 2007 Steve Huston <shuston@riverace.com> + + * bin/sandbox.cpp: Removed. There's an identical copy of this file + in the autobuild repository, autobuild/posixsandbox/sandbox.cpp. + Thu Jun 28 14:12:12 UTC 2007 Johnny Willemsen <jwillemsen@remedy.nl> * examples/ASX/Message_Queue/buffer_stream.cpp: diff --git a/ACE/bin/sandbox.cpp b/ACE/bin/sandbox.cpp deleted file mode 100644 index fce69dedcb6..00000000000 --- a/ACE/bin/sandbox.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// -// $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, try to kill the child - (void) kill(grandchild, SIGTERM); - - // Second chance, if the child does not die, then really kill it: - pid_t killed = waitpid(grandchild, &status, WNOHANG); - if (killed == 0) - { - // TERM did not work, use the heavy duty signal - (void) kill(grandchild, SIGQUIT); sleep(1); - killed = waitpid(grandchild, &status, WNOHANG); - } - if (killed == -1) - { - fprintf(stderr, "No such child (%d), panic\n", - grandchild); - return 1; - } - sleep(1); - - printf("sandbox: killing session %d\n", sid); - - // OK, now commit suicide, kill the session ID and all their friends - (void) killpg(sid, SIGQUIT); - fprintf(stderr, "sandbox: ooops! I should be dead!\n"); - - 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; -} |