mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Move pid_running() to process.h
This commit is contained in:
@@ -18,6 +18,29 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <ghc/filesystem.hpp>
|
||||||
|
|
||||||
|
namespace fs = ghc::filesystem;
|
||||||
|
|
||||||
|
bool pid_running(pid_t pid) {
|
||||||
|
// With regular individually hosted plugins we can simply check whether the
|
||||||
|
// process is still running, however Boost.Process does not allow you to do
|
||||||
|
// the same thing for a process that's not a direct child if this process.
|
||||||
|
// When using plugin groups we'll have to manually check whether the PID
|
||||||
|
// returned by the group host process is still active. We sadly can't use
|
||||||
|
// `kill()` for this as that provides no way to distinguish between active
|
||||||
|
// 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.
|
||||||
|
std::error_code err;
|
||||||
|
fs::canonical("/proc/" + std::to_string(pid) + "/exe", err);
|
||||||
|
|
||||||
|
// 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 || err.value() == EACCES;
|
||||||
|
}
|
||||||
|
|
||||||
ProcessEnvironment::ProcessEnvironment(char** initial_env) {
|
ProcessEnvironment::ProcessEnvironment(char** initial_env) {
|
||||||
// We'll need to read all strings from `initial_env`. They _should_ all be
|
// We'll need to read all strings from `initial_env`. They _should_ all be
|
||||||
// zero-terminated strings, with a null pointer to indicate the end of the
|
// zero-terminated strings, with a null pointer to indicate the end of the
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
// pulling in Boost.Process' Boost.Filesystem dependency (which would defeat the
|
// pulling in Boost.Process' Boost.Filesystem dependency (which would defeat the
|
||||||
// entire purpose).
|
// entire purpose).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a process with the given PID is still active (and not a
|
||||||
|
* zombie).
|
||||||
|
*/
|
||||||
|
bool pid_running(pid_t pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to create an `environ`-like environment object for passing to the
|
* Helper to create an `environ`-like environment object for passing to the
|
||||||
* `exec*e()` family of functions.
|
* `exec*e()` family of functions.
|
||||||
|
|||||||
@@ -94,25 +94,6 @@ bool is_watchdog_timer_disabled() {
|
|||||||
return disable_watchdog_env && disable_watchdog_env == "1"sv;
|
return disable_watchdog_env && disable_watchdog_env == "1"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pid_running(pid_t pid) {
|
|
||||||
// With regular individually hosted plugins we can simply check whether the
|
|
||||||
// process is still running, however Boost.Process does not allow you to do
|
|
||||||
// the same thing for a process that's not a direct child if this process.
|
|
||||||
// When using plugin groups we'll have to manually check whether the PID
|
|
||||||
// returned by the group host process is still active. We sadly can't use
|
|
||||||
// `kill()` for this as that provides no way to distinguish between active
|
|
||||||
// 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.
|
|
||||||
std::error_code err;
|
|
||||||
fs::canonical("/proc/" + std::to_string(pid) + "/exe", err);
|
|
||||||
|
|
||||||
// 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 || err.value() == EACCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string url_encode_path(std::string path) {
|
std::string url_encode_path(std::string path) {
|
||||||
// We only need to escape a couple of special characters here. This is used
|
// We only need to escape a couple of special characters here. This is used
|
||||||
// in the notifications as well as in the XDND proxy. We encode the reserved
|
// in the notifications as well as in the XDND proxy. We encode the reserved
|
||||||
|
|||||||
@@ -138,12 +138,6 @@ std::optional<rlim_t> get_rttime_limit() noexcept;
|
|||||||
*/
|
*/
|
||||||
bool is_watchdog_timer_disabled();
|
bool is_watchdog_timer_disabled();
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether a process with the given PID is still active (and not a
|
|
||||||
* zombie).
|
|
||||||
*/
|
|
||||||
bool pid_running(pid_t pid);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL encode a file path. We won't escape forward slashes, and `path` should
|
* URL encode a file path. We won't escape forward slashes, and `path` should
|
||||||
* not yet include the `file://` prefix.
|
* not yet include the `file://` prefix.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../../common/process.h"
|
||||||
#include "../editor.h"
|
#include "../editor.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user