mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-05 04:46:21 -04:00
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:
parent
ca74a559c5
commit
7534a9cddb
@ -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
18
test/test_ret_code.cc
Normal 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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user