Files
external_libcamera/include/libcamera/internal/process.h
Paul Elder 1469d5e26e libcamera: ProcessManager: make ProcessManager lifetime explicitly managed
If any Process instances are destroyed after the ProcessManager is
destroyed, then a segfault will occur.

Fix this by making the lifetime of the ProcessManager explicit, and make
the CameraManager construct and deconstruct (automatically, via a member
variable) the ProcessManager.

Update the tests accordingly.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 19:17:31 +09:00

85 lines
1.5 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* process.h - Process object
*/
#ifndef __LIBCAMERA_INTERNAL_PROCESS_H__
#define __LIBCAMERA_INTERNAL_PROCESS_H__
#include <signal.h>
#include <string>
#include <vector>
#include <libcamera/signal.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<Process *, 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(EventNotifier *notifier);
std::list<Process *> processes_;
struct sigaction oldsa_;
EventNotifier *sigEvent_;
int pipe_[2];
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_PROCESS_H__ */