libcamera v0.5.1+100-e53bdf1f
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2019, Google Inc.
4 *
5 * Process object
6 */
7
8#pragma once
9
10#include <signal.h>
11#include <string>
12#include <vector>
13
17
18namespace libcamera {
19
20class EventNotifier;
21
22class Process final
23{
24public:
30
31 Process();
32 ~Process();
33
34 int start(const std::string &path,
35 const std::vector<std::string> &args = std::vector<std::string>(),
36 const std::vector<int> &fds = std::vector<int>());
37
38 ExitStatus exitStatus() const { return exitStatus_; }
39 int exitCode() const { return exitCode_; }
40
41 void kill();
42
44
45private:
47
48 void closeAllFdsExcept(const std::vector<int> &fds);
49 int isolate();
50 void died(int wstatus);
51
52 pid_t pid_;
53 bool running_;
54 enum ExitStatus exitStatus_;
55 int exitCode_;
56
57 friend class ProcessManager;
58};
59
61{
62public:
65
66 void registerProcess(Process *proc);
67
68 static ProcessManager *instance();
69
70 int writePipe() const;
71
72 const struct sigaction &oldsa() const;
73
74private:
75 static ProcessManager *self_;
76
77 void sighandler();
78
79 std::list<Process *> processes_;
80
81 struct sigaction oldsa_;
82
83 EventNotifier *sigEvent_;
84 UniqueFD pipe_[2];
85};
86
87} /* namespace libcamera */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
Notify of activity on a file descriptor.
Definition event_notifier.h:20
Manager of processes.
Definition process.h:61
static ProcessManager * instance()
Retrieve the Process manager instance.
Definition process.cpp:162
int writePipe() const
Retrieve the Process manager's write pipe.
Definition process.cpp:174
void registerProcess(Process *proc)
Register process with process manager.
Definition process.cpp:101
ProcessManager()
Construct a ProcessManager instance.
Definition process.cpp:114
const struct sigaction & oldsa() const
Retrive the old signal action data.
Definition process.cpp:186
Process object.
Definition process.h:23
void kill()
Kill the process.
Definition process.cpp:391
int exitCode() const
Retrieve the exit code of the process.
Definition process.h:39
int start(const std::string &path, const std::vector< std::string > &args=std::vector< std::string >(), const std::vector< int > &fds=std::vector< int >())
Fork and exec a process, and close fds.
Definition process.cpp:237
ExitStatus
Exit status of process.
Definition process.h:25
@ NormalExit
Definition process.h:27
@ NotExited
Definition process.h:26
@ SignalExit
Definition process.h:28
Signal< enum ExitStatus, int > finished
Definition process.h:43
ExitStatus exitStatus() const
Retrieve the exit status of the process.
Definition process.h:38
Generic signal and slot communication mechanism.
Definition signal.h:39
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:17
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
File descriptor wrapper that owns a file descriptor.