Don't waitpid on SIGCHLD, which lost the retcode (#11)

* Don't waitpid on SIGCHLD, which lost the retcode

* Adding test
This commit is contained in:
okaymaged 2018-03-02 06:58:24 -08:00 committed by Arun Muralidharan
parent ca74a559c5
commit 7534a9cddb
2 changed files with 18 additions and 5 deletions

View File

@ -1150,11 +1150,6 @@ inline void Popen::execute_process() throw (CalledProcessError, OSError)
} }
exe_name_ = vargs_[0]; exe_name_ = vargs_[0];
std::signal(SIGCHLD, [](int sig){
int status;
waitpid(-1, &status, WNOHANG);
});
child_pid_ = fork(); child_pid_ = fork();
if (child_pid_ < 0) { if (child_pid_ < 0) {

18
test/test_ret_code.cc Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
#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();
}