Repository: mesos Updated Branches: refs/heads/master 3c730dc42 -> d8f48cb4a
Fixed an indentation problem in subprocess.cpp. Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d8f48cb4 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d8f48cb4 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d8f48cb4 Branch: refs/heads/master Commit: d8f48cb4a5d109837689e27a80f8c52100d0aa65 Parents: 3c730dc Author: Jie Yu <yujie....@gmail.com> Authored: Wed Sep 21 10:07:20 2016 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Wed Sep 21 10:07:20 2016 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/src/subprocess.cpp | 114 ++++++++++++++-------------- 1 file changed, 57 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/d8f48cb4/3rdparty/libprocess/src/subprocess.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/subprocess.cpp b/3rdparty/libprocess/src/subprocess.cpp index 4a8bb2e..6f50a71 100644 --- a/3rdparty/libprocess/src/subprocess.cpp +++ b/3rdparty/libprocess/src/subprocess.cpp @@ -98,67 +98,67 @@ inline void signalHandler(int signal) Subprocess::ChildHook Subprocess::ChildHook::SUPERVISOR() { return Subprocess::ChildHook([]() -> Try<Nothing> { - #ifdef __linux__ - // Send SIGTERM to the current process if the parent (i.e., the - // slave) exits. - // NOTE:: This function should always succeed because we are passing - // in a valid signal. - prctl(PR_SET_PDEATHSIG, SIGTERM); - - // Put the current process into a separate process group so that - // we can kill it and all its children easily. - if (setpgid(0, 0) != 0) { - return Error("Could not start supervisor process."); - } - - // Install a SIGTERM handler which will kill the current process - // group. Since we already setup the death signal above, the - // signal handler will be triggered when the parent (e.g., the - // slave) exits. - if (os::signals::install(SIGTERM, &signalHandler) != 0) { - return Error("Could not start supervisor process."); - } +#ifdef __linux__ + // Send SIGTERM to the current process if the parent (i.e., the + // slave) exits. + // NOTE:: This function should always succeed because we are passing + // in a valid signal. + prctl(PR_SET_PDEATHSIG, SIGTERM); + + // Put the current process into a separate process group so that + // we can kill it and all its children easily. + if (setpgid(0, 0) != 0) { + return Error("Could not start supervisor process."); + } - pid_t pid = fork(); - if (pid == -1) { - return Error("Could not start supervisor process."); - } else if (pid == 0) { - // Child. This is the process that is going to exec the - // process if zero is returned. - - // We setup death signal for the process as well in case - // someone, though unlikely, accidentally kill the parent of - // this process (the bookkeeping process). - prctl(PR_SET_PDEATHSIG, SIGKILL); - - // NOTE: We don't need to clear the signal handler explicitly - // because the subsequent 'exec' will clear them. - return Nothing(); - } else { - // Parent. This is the bookkeeping process which will wait for - // the child process to finish. - - // Close the files to prevent interference on the communication - // between the slave and the child process. - ::close(STDIN_FILENO); - ::close(STDOUT_FILENO); - ::close(STDERR_FILENO); - - // Block until the child process finishes. - int status = 0; - if (waitpid(pid, &status, 0) == -1) { - abort(); - } - - // Forward the exit status if the child process exits normally. - if (WIFEXITED(status)) { - _exit(WEXITSTATUS(status)); - } + // Install a SIGTERM handler which will kill the current process + // group. Since we already setup the death signal above, the + // signal handler will be triggered when the parent (e.g., the + // slave) exits. + if (os::signals::install(SIGTERM, &signalHandler) != 0) { + return Error("Could not start supervisor process."); + } + pid_t pid = fork(); + if (pid == -1) { + return Error("Could not start supervisor process."); + } else if (pid == 0) { + // Child. This is the process that is going to exec the + // process if zero is returned. + + // We setup death signal for the process as well in case + // someone, though unlikely, accidentally kill the parent of + // this process (the bookkeeping process). + prctl(PR_SET_PDEATHSIG, SIGKILL); + + // NOTE: We don't need to clear the signal handler explicitly + // because the subsequent 'exec' will clear them. + return Nothing(); + } else { + // Parent. This is the bookkeeping process which will wait for + // the child process to finish. + + // Close the files to prevent interference on the communication + // between the slave and the child process. + ::close(STDIN_FILENO); + ::close(STDOUT_FILENO); + ::close(STDERR_FILENO); + + // Block until the child process finishes. + int status = 0; + if (waitpid(pid, &status, 0) == -1) { abort(); - UNREACHABLE(); } - #endif + + // Forward the exit status if the child process exits normally. + if (WIFEXITED(status)) { + _exit(WEXITSTATUS(status)); + } + + abort(); + UNREACHABLE(); + } +#endif return Nothing(); }); }