libcamera  v0.0.0+100-debian/0_git20200629+e7aa92a-8-9-g77f5237c-dirty (2021-05-05T16:20:29+01:00)
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.h - Process object
6  */
7 #ifndef __LIBCAMERA_INTERNAL_PROCESS_H__
8 #define __LIBCAMERA_INTERNAL_PROCESS_H__
9 
10 #include <signal.h>
11 #include <string>
12 #include <vector>
13 
14 #include <libcamera/signal.h>
15 
16 namespace libcamera {
17 
18 class EventNotifier;
19 
20 class Process final
21 {
22 public:
23  enum ExitStatus {
27  };
28 
29  Process();
30  ~Process();
31 
32  int start(const std::string &path,
33  const std::vector<std::string> &args = std::vector<std::string>(),
34  const std::vector<int> &fds = std::vector<int>());
35 
36  ExitStatus exitStatus() const { return exitStatus_; }
37  int exitCode() const { return exitCode_; }
38 
39  void kill();
40 
42 
43 private:
44  void closeAllFdsExcept(const std::vector<int> &fds);
45  int isolate();
46  void died(int wstatus);
47 
48  pid_t pid_;
49  bool running_;
50  enum ExitStatus exitStatus_;
51  int exitCode_;
52 
53  friend class ProcessManager;
54 };
55 
57 {
58 public:
60  ~ProcessManager();
61 
62  void registerProcess(Process *proc);
63 
64  static ProcessManager *instance();
65 
66  int writePipe() const;
67 
68  const struct sigaction &oldsa() const;
69 
70 private:
71  static ProcessManager *self_;
72 
73  void sighandler(EventNotifier *notifier);
74 
75  std::list<Process *> processes_;
76 
77  struct sigaction oldsa_;
78  EventNotifier *sigEvent_;
79  int pipe_[2];
80 };
81 
82 } /* namespace libcamera */
83 
84 #endif /* __LIBCAMERA_INTERNAL_PROCESS_H__ */
Manager of processes.
Definition: process.h:56
Signal< Process *, enum ExitStatus, int > finished
Definition: process.h:41
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:235
Process object.
Definition: process.h:20
Top-level libcamera namespace.
Definition: bound_method.h:15
Definition: process.h:24
Signal & slot implementation.
Definition: process.h:26
void kill()
Kill the process.
Definition: process.cpp:365
Generic signal and slot communication mechanism.
Definition: object.h:20
Notify of activity on a file descriptor.
Definition: event_notifier.h:17
ExitStatus
Exit status of process.
Definition: process.h:23
Definition: process.h:25
ExitStatus exitStatus() const
Retrieve the exit status of the process.
Definition: process.h:36
int exitCode() const
Retrieve the exit code of the process.
Definition: process.h:37