From 138dfb32841b09bee10aff259450ebb287bcc74f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 20 Jul 2021 02:35:13 +0200 Subject: [PATCH] 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). --- src/common/utils.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/common/utils.cpp b/src/common/utils.cpp index f748166f..ef9aab8b 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -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//{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) {