mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 20:10:13 +02:00
Add a detach function to the process handles
This commit is contained in:
@@ -96,18 +96,18 @@ char* const* ProcessEnvironment::make_environ() const {
|
||||
Process::Handle::Handle(pid_t pid) : pid_(pid) {}
|
||||
|
||||
Process::Handle::~Handle() {
|
||||
if (!is_moved_) {
|
||||
if (!detached_) {
|
||||
// If this function has already been called then that's okay
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
Process::Handle::Handle(Handle&& o) noexcept : pid_(o.pid_) {
|
||||
o.is_moved_ = true;
|
||||
o.detached_ = true;
|
||||
}
|
||||
|
||||
Process::Handle& Process::Handle::operator=(Handle&& o) noexcept {
|
||||
o.is_moved_ = true;
|
||||
o.detached_ = true;
|
||||
|
||||
pid_ = o.pid_;
|
||||
|
||||
@@ -122,6 +122,10 @@ bool Process::Handle::running() const noexcept {
|
||||
return pid_running(pid_);
|
||||
}
|
||||
|
||||
void Process::Handle::detach() noexcept {
|
||||
detached_ = true;
|
||||
}
|
||||
|
||||
void Process::Handle::terminate() const noexcept {
|
||||
kill(pid_, SIGINT);
|
||||
wait();
|
||||
|
||||
Reference in New Issue
Block a user