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>
58 lines
948 B
C++
58 lines
948 B
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* Process object
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <libcamera/base/class.h>
|
|
#include <libcamera/base/signal.h>
|
|
#include <libcamera/base/span.h>
|
|
#include <libcamera/base/unique_fd.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class EventNotifier;
|
|
|
|
class Process final
|
|
{
|
|
public:
|
|
enum ExitStatus {
|
|
NotExited,
|
|
NormalExit,
|
|
SignalExit,
|
|
};
|
|
|
|
Process();
|
|
~Process();
|
|
|
|
int start(const std::string &path,
|
|
Span<const std::string> args = {},
|
|
Span<const int> fds = {});
|
|
|
|
ExitStatus exitStatus() const { return exitStatus_; }
|
|
int exitCode() const { return exitCode_; }
|
|
|
|
void kill();
|
|
|
|
Signal<enum ExitStatus, int> finished;
|
|
|
|
private:
|
|
LIBCAMERA_DISABLE_COPY_AND_MOVE(Process)
|
|
|
|
void onPidfdNotify();
|
|
|
|
pid_t pid_;
|
|
enum ExitStatus exitStatus_;
|
|
int exitCode_;
|
|
|
|
UniqueFD pidfd_;
|
|
std::unique_ptr<EventNotifier> pidfdNotify_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|