libcamera  v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
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 
14 #include <libcamera/base/signal.h>
16 
17 namespace libcamera {
18 
19 class EventNotifier;
20 
21 class Process final
22 {
23 public:
24  enum ExitStatus {
28  };
29 
30  Process();
31  ~Process();
32 
33  int start(const std::string &path,
34  const std::vector<std::string> &args = std::vector<std::string>(),
35  const std::vector<int> &fds = std::vector<int>());
36 
37  ExitStatus exitStatus() const { return exitStatus_; }
38  int exitCode() const { return exitCode_; }
39 
40  void kill();
41 
43 
44 private:
45  void closeAllFdsExcept(const std::vector<int> &fds);
46  int isolate();
47  void died(int wstatus);
48 
49  pid_t pid_;
50  bool running_;
51  enum ExitStatus exitStatus_;
52  int exitCode_;
53 
54  friend class ProcessManager;
55 };
56 
58 {
59 public:
61  ~ProcessManager();
62 
63  void registerProcess(Process *proc);
64 
65  static ProcessManager *instance();
66 
67  int writePipe() const;
68 
69  const struct sigaction &oldsa() const;
70 
71 private:
72  static ProcessManager *self_;
73 
74  void sighandler();
75 
76  std::list<Process *> processes_;
77 
78  struct sigaction oldsa_;
79 
80  EventNotifier *sigEvent_;
81  UniqueFD pipe_[2];
82 };
83 
84 } /* namespace libcamera */
Manager of processes.
Definition: process.h:57
Signal< enum ExitStatus, int > finished
Definition: process.h:42
File descriptor wrapper that owns a file descriptor.
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
Process object.
Definition: process.h:21
Top-level libcamera namespace.
Definition: backtrace.h:17
Definition: process.h:25
Signal & slot implementation.
Definition: process.h:27
unique_ptr-like wrapper for a file descriptor
Definition: unique_fd.h:17
void kill()
Kill the process.
Definition: process.cpp:369
Notify of activity on a file descriptor.
Definition: event_notifier.h:19
ExitStatus
Exit status of process.
Definition: process.h:24
Definition: process.h:26
ExitStatus exitStatus() const
Retrieve the exit status of the process.
Definition: process.h:37
int exitCode() const
Retrieve the exit code of the process.
Definition: process.h:38