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>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#ifndef __LIBCAMERA_INTERNAL_PROCESS_H__
|
||||
#define __LIBCAMERA_INTERNAL_PROCESS_H__
|
||||
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -14,6 +15,8 @@
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
|
||||
class Process final
|
||||
{
|
||||
public:
|
||||
@@ -50,6 +53,32 @@ private:
|
||||
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__ */
|
||||
|
||||
Reference in New Issue
Block a user