blob: 95e67e105a92b510cf706956cbb11bd497d90269 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* process.h - Process object
*/
#pragma once
#include <signal.h>
#include <string>
#include <vector>
#include <libcamera/base/signal.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,
const std::vector<std::string> &args = std::vector<std::string>(),
const std::vector<int> &fds = std::vector<int>());
ExitStatus exitStatus() const { return exitStatus_; }
int exitCode() const { return exitCode_; }
void kill();
Signal<enum ExitStatus, int> finished;
private:
void closeAllFdsExcept(const std::vector<int> &fds);
int isolate();
void died(int wstatus);
pid_t pid_;
bool running_;
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 */
|