Fix crash on exit if a process is currently running
This commit is contained in:
@@ -594,6 +594,11 @@ main(int argc, char *argv[]) {
|
|||||||
BOOST_LOG(error) << "Platform failed to initialize"sv;
|
BOOST_LOG(error) << "Platform failed to initialize"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto proc_deinit_guard = proc::init();
|
||||||
|
if (!proc_deinit_guard) {
|
||||||
|
BOOST_LOG(error) << "Proc failed to initialize"sv;
|
||||||
|
}
|
||||||
|
|
||||||
reed_solomon_init();
|
reed_solomon_init();
|
||||||
auto input_deinit_guard = input::init();
|
auto input_deinit_guard = input::init();
|
||||||
if (video::probe_encoders()) {
|
if (video::probe_encoders()) {
|
||||||
|
|||||||
@@ -40,6 +40,22 @@ namespace proc {
|
|||||||
|
|
||||||
proc_t proc;
|
proc_t proc;
|
||||||
|
|
||||||
|
class deinit_t: public platf::deinit_t {
|
||||||
|
public:
|
||||||
|
~deinit_t() {
|
||||||
|
proc.terminate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes proc functions
|
||||||
|
* @return Unique pointer to `deinit_t` to manage cleanup
|
||||||
|
*/
|
||||||
|
std::unique_ptr<platf::deinit_t>
|
||||||
|
init() {
|
||||||
|
return std::make_unique<deinit_t>();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
process_end(bp::child &proc, bp::group &proc_handle) {
|
process_end(bp::child &proc, bp::group &proc_handle) {
|
||||||
if (!proc.running()) {
|
if (!proc.running()) {
|
||||||
@@ -266,7 +282,12 @@ namespace proc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc_t::~proc_t() {
|
proc_t::~proc_t() {
|
||||||
terminate();
|
// It's not safe to call terminate() here because our proc_t is a static variable
|
||||||
|
// that may be destroyed after the Boost loggers have been destroyed. Instead,
|
||||||
|
// we return a deinit_t to main() to handle termination when we're exiting.
|
||||||
|
// Once we reach this point here, termination must have already happened.
|
||||||
|
assert(!placebo);
|
||||||
|
assert(!_process.running());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view::iterator
|
std::string_view::iterator
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <boost/process.hpp>
|
#include <boost/process.hpp>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "platform/common.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
namespace proc {
|
namespace proc {
|
||||||
@@ -116,5 +117,8 @@ namespace proc {
|
|||||||
std::optional<proc::proc_t>
|
std::optional<proc::proc_t>
|
||||||
parse(const std::string &file_name);
|
parse(const std::string &file_name);
|
||||||
|
|
||||||
|
std::unique_ptr<platf::deinit_t>
|
||||||
|
init();
|
||||||
|
|
||||||
extern proc_t proc;
|
extern proc_t proc;
|
||||||
} // namespace proc
|
} // namespace proc
|
||||||
|
|||||||
Reference in New Issue
Block a user