Fix regression in pid_running from d99f571

In some cases we would treat dead processes as not running (we could
also get EAVAIL instead of EINVAL, so it's better to just check the one
thing we should treat as a success instead).
This commit is contained in:
Robbert van der Helm
2021-07-20 02:35:13 +02:00
parent fae8314017
commit 138dfb3284
+5 -9
View File
@@ -94,17 +94,13 @@ bool pid_running(pid_t pid) {
// processes and zombies, and a terminated group host process will always be
// left as a zombie process. If the process is active, then
// `/proc/<pid>/{cwd,exe,root}` will be valid symlinks.
// NOTE: We can get a `EACCES` here if we don't have permissions to read
// this process's memory, so we should explicitly check for `EINVAL`
// indicating that the 'symlink' is broken or just does not exist at
// all.
boost::system::error_code err;
fs::canonical("/proc/" + std::to_string(pid) + "/exe", err);
if (err && err.value() == EINVAL) {
return false;
} else {
return true;
}
// NOTE: We can get a `EACCES` here if we don't have permissions to read
// this process's memory. This does mean that the process is still
// running.
return err.failed() || err.value() == EACCES;
}
std::string url_encode_path(std::string path) {