Kill orphaned subprocesses on crash (#6366)

Co-authored-by: Lukas W <lukaswhl@gmail.com>
This commit is contained in:
Dominic Clark
2022-04-20 17:15:33 +01:00
committed by GitHub
parent b4317edd43
commit 0dcf909129
5 changed files with 126 additions and 14 deletions

View File

@@ -27,6 +27,15 @@
#include "RemotePluginBase.h"
#ifndef LMMS_BUILD_WIN32
# include <condition_variable>
# include <mutex>
# include <thread>
# include <signal.h>
# include <unistd.h>
#endif
class RemotePluginClient : public RemotePluginBase
{
public:
@@ -126,6 +135,47 @@ private:
fpp_t m_bufferSize;
} ;
#ifndef LMMS_BUILD_WIN32
class PollParentThread
{
public:
PollParentThread() :
m_stop{false},
m_thread{
[this]
{
using namespace std::literals::chrono_literals;
auto lock = std::unique_lock{m_mutex};
while (!m_cv.wait_for(lock, 500ms, [this] { return m_stop; }))
{
if (getppid() == 1)
{
kill(getpid(), SIGHUP);
break;
}
}
}
}
{ }
~PollParentThread()
{
{
const auto lock = std::unique_lock{m_mutex};
m_stop = true;
}
m_cv.notify_all();
m_thread.join();
}
private:
bool m_stop;
std::mutex m_mutex;
std::condition_variable m_cv;
std::thread m_thread;
};
#endif
#ifdef SYNC_WITH_SHM_FIFO
RemotePluginClient::RemotePluginClient( key_t _shm_in, key_t _shm_out ) :
RemotePluginBase( new shmFifo( _shm_in ), new shmFifo( _shm_out ) ),