libcamera  v0.5.1+5-8d168f33
Supporting cameras in Linux since 2019
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/class.h>
15 #include <libcamera/base/signal.h>
17 
18 namespace libcamera {
19 
20 class EventNotifier;
21 
22 class Process final
23 {
24 public:
25  enum ExitStatus {
29  };
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 
45 private:
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 {
62 public:
64  ~ProcessManager();
65 
66  void registerProcess(Process *proc);
67 
68  static ProcessManager *instance();
69 
70  int writePipe() const;
71 
72  const struct sigaction &oldsa() const;
73 
74 private:
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.
Manager of processes.
Definition: process.h:60
Signal< enum ExitStatus, int > finished
Definition: process.h:43
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:22
Top-level libcamera namespace.
Definition: backtrace.h:17
Definition: process.h:26
Signal & slot implementation.
Definition: process.h:28
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
unique_ptr-like wrapper for a file descriptor
Definition: unique_fd.h:16
void kill()
Kill the process.
Definition: process.cpp:391
Notify of activity on a file descriptor.
Definition: event_notifier.h:19
ExitStatus
Exit status of process.
Definition: process.h:25
Definition: process.h:27
ExitStatus exitStatus() const
Retrieve the exit status of the process.
Definition: process.h:38
int exitCode() const
Retrieve the exit code of the process.
Definition: process.h:39