libcamera: process: Remove ProcessManager singleton
The `ProcessManager` is a singleton class to handle `SIGCHLD` signals and report the exit status to the particular `Process` instance. However, having a singleton in a library is not favourable and it is even less favourable if it installs a signal handler. Using pidfd it is possible to avoid the need for the signal handler; and the `Process` objects can watch their pidfd themselves, eliminating the need for the `ProcessManager` class altogether. `P_PIDFD` for `waitid()` was introduced in Linux 5.4, so this change raises the minimum supported kernel version. `clone3()`, `CLONE_PIDFD`, `pidfd_send_signal()` were all introduced earlier. Furthermore, the call to the `unshare()` system call can be removed as those options can be passed to `clone3()` directly. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -65,7 +65,6 @@ private:
|
||||
std::unique_ptr<DeviceEnumerator> enumerator_;
|
||||
|
||||
std::unique_ptr<IPAManager> ipaManager_;
|
||||
ProcessManager processManager_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
@@ -45,41 +44,14 @@ public:
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(Process)
|
||||
|
||||
int isolate();
|
||||
void died(int wstatus);
|
||||
void onPidfdNotify();
|
||||
|
||||
pid_t pid_;
|
||||
enum ExitStatus exitStatus_;
|
||||
int exitCode_;
|
||||
|
||||
friend class ProcessManager;
|
||||
};
|
||||
|
||||
class ProcessManager
|
||||
{
|
||||
public:
|
||||
ProcessManager();
|
||||
~ProcessManager();
|
||||
|
||||
void registerProcess(Process *proc);
|
||||
|
||||
static ProcessManager *instance();
|
||||
|
||||
int writePipe() const;
|
||||
|
||||
const struct sigaction &oldsa() const;
|
||||
|
||||
private:
|
||||
static ProcessManager *self_;
|
||||
|
||||
void sighandler();
|
||||
|
||||
std::list<Process *> processes_;
|
||||
|
||||
struct sigaction oldsa_;
|
||||
|
||||
EventNotifier *sigEvent_;
|
||||
UniqueFD pipe_[2];
|
||||
UniqueFD pidfd_;
|
||||
std::unique_ptr<EventNotifier> pidfdNotify_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
Reference in New Issue
Block a user