Use a span instead of a const reference to a vector, this does not change the behaviour and allows e.g. arrays to be used to hold arguments/file descriptors. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
87 lines
1.4 KiB
C++
87 lines
1.4 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* Process object
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <signal.h>
|
|
#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 closeAllFdsExcept(const std::vector<int> &fds);
|
|
int isolate();
|
|
void died(int wstatus);
|
|
|
|
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];
|
|
};
|
|
|
|
} /* namespace libcamera */
|