fix(process): avoid leaking zombies and fds in detached processes (#3379)
This commit is contained in:
@@ -241,22 +241,24 @@ namespace platf {
|
|||||||
|
|
||||||
bp::child
|
bp::child
|
||||||
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
||||||
|
// clang-format off
|
||||||
if (!group) {
|
if (!group) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > bp::null, bp::std_err > bp::null, bp::limit_handles, ec);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > file, bp::std_err > file, bp::limit_handles, ec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec, *group);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > bp::null, bp::std_err > bp::null, bp::limit_handles, ec, *group);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec, *group);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > file, bp::std_err > file, bp::limit_handles, ec, *group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -182,22 +182,24 @@ namespace platf {
|
|||||||
|
|
||||||
bp::child
|
bp::child
|
||||||
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
||||||
|
// clang-format off
|
||||||
if (!group) {
|
if (!group) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > bp::null, bp::std_err > bp::null, bp::limit_handles, ec);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > file, bp::std_err > file, bp::limit_handles, ec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > bp::null, bp::std_err > bp::null, ec, *group);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > bp::null, bp::std_err > bp::null, bp::limit_handles, ec, *group);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_out > file, bp::std_err > file, ec, *group);
|
return bp::child(cmd, env, bp::start_dir(working_dir), bp::std_in < bp::null, bp::std_out > file, bp::std_err > file, bp::limit_handles, ec, *group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -269,6 +269,16 @@ namespace proc {
|
|||||||
|
|
||||||
int
|
int
|
||||||
proc_t::running() {
|
proc_t::running() {
|
||||||
|
#ifndef _WIN32
|
||||||
|
// On POSIX OSes, we must periodically wait for our children to avoid
|
||||||
|
// them becoming zombies. This must be synchronized carefully with
|
||||||
|
// calls to bp::wait() and platf::process_group_running() which both
|
||||||
|
// invoke waitpid() under the hood.
|
||||||
|
auto reaper = util::fail_guard([]() {
|
||||||
|
while (waitpid(-1, nullptr, WNOHANG) > 0);
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
if (placebo) {
|
if (placebo) {
|
||||||
return _app_id;
|
return _app_id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user