mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 12:10:09 +02:00
Treat EACCES for pid_running() as alive
When the user has some sort of hardening going on, we might not be able to read the Wine process's memory. In that case this check would return `false` even though the process is still running. To combat this, we should explicitly check for `EINVAL` which is returned when the file doesn't exist at all or when it's a broken 'symlink' (even though it isn't really a symlink).
This commit is contained in:
@@ -85,11 +85,16 @@ 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.
|
||||
try {
|
||||
fs::canonical("/proc/" + std::to_string(pid) + "/exe");
|
||||
return true;
|
||||
} catch (const fs::filesystem_error&) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user