From 7534a9cddb7b6f9aa354e0ec4194fbb1b5a9fa9c Mon Sep 17 00:00:00 2001 From: okaymaged Date: Fri, 2 Mar 2018 06:58:24 -0800 Subject: [PATCH] Don't waitpid on SIGCHLD, which lost the retcode (#11) * Don't waitpid on SIGCHLD, which lost the retcode * Adding test --- subprocess.hpp | 5 ----- test/test_ret_code.cc | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 test/test_ret_code.cc diff --git a/subprocess.hpp b/subprocess.hpp index 45e52c9..0341474 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -1150,11 +1150,6 @@ inline void Popen::execute_process() throw (CalledProcessError, OSError) } exe_name_ = vargs_[0]; - std::signal(SIGCHLD, [](int sig){ - int status; - waitpid(-1, &status, WNOHANG); - }); - child_pid_ = fork(); if (child_pid_ < 0) { diff --git a/test/test_ret_code.cc b/test/test_ret_code.cc new file mode 100644 index 0000000..9e00f25 --- /dev/null +++ b/test/test_ret_code.cc @@ -0,0 +1,18 @@ +#include +#include "../subprocess.hpp" + +namespace sp = subprocess; + +void test_ret_code() +{ + std::cout << "Test::test_poll_ret_code" << std::endl; + auto p = sp::Popen({"/bin/false"}); + while (p.poll() == -1) { + usleep(1000 * 100); + } + assert (p.retcode() == 1); +} + +int main() { + test_ret_code(); +}