From 39186370a880b3c0fe70cf112b097c7957815f17 Mon Sep 17 00:00:00 2001 From: Giso Grimm Date: Tue, 14 May 2024 12:26:30 +0200 Subject: [PATCH] try to prevent segmentation fault in osc_server when unloading --- libtascar/include/osc_helper.h | 7 ++++--- libtascar/src/osc_helper.cc | 7 ++++--- libtascar/src/session_reader.cc | 5 ++++- plugins/src/tascarmod_oscserver.cc | 7 ++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libtascar/include/osc_helper.h b/libtascar/include/osc_helper.h index 16fc6613..05a75844 100644 --- a/libtascar/include/osc_helper.h +++ b/libtascar/include/osc_helper.h @@ -8,6 +8,7 @@ /* License (GPL) * * Copyright (C) 2018 Giso Grimm + * Copyright (C) 2024 Giso Grimm * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -315,9 +316,9 @@ namespace TASCAR { std::string osc_srv_url; std::string prefix; lo_server_thread lost; - bool initialized; - bool isactive; - bool verbose; + std::atomic_bool initialized = false; + std::atomic_bool isactive = false; + bool verbose = false; std::map datamap; std::atomic runscriptthread; std::atomic cancelscript; diff --git a/libtascar/src/osc_helper.cc b/libtascar/src/osc_helper.cc index 7fe6316b..5bde252f 100644 --- a/libtascar/src/osc_helper.cc +++ b/libtascar/src/osc_helper.cc @@ -576,8 +576,7 @@ int string2proto(const std::string& proto) osc_server_t::osc_server_t(const std::string& multicast, const std::string& port, const std::string& proto, bool verbose_) - : osc_srv_addr(multicast), osc_srv_port(port), initialized(false), - isactive(false), verbose(verbose_) + : osc_srv_addr(multicast), osc_srv_port(port), verbose(verbose_) { runscriptthread = true; cancelscript = false; @@ -625,6 +624,8 @@ osc_server_t::osc_server_t(const std::string& multicast, int osc_server_t::dispatch_data(void* data, size_t size) { + if(!isactive) + return 0; // std::lock_guard lk{mtxdispatch}; lo_server srv(lo_server_thread_get_server(lost)); return lo_server_dispatch_data(srv, data, size); @@ -890,8 +891,8 @@ void osc_server_t::activate() void osc_server_t::deactivate() { if(initialized) { - lo_server_thread_stop(lost); isactive = false; + lo_server_thread_stop(lost); if(verbose) std::cerr << "server inactive\n"; } diff --git a/libtascar/src/session_reader.cc b/libtascar/src/session_reader.cc index 7d40b398..25d3e092 100644 --- a/libtascar/src/session_reader.cc +++ b/libtascar/src/session_reader.cc @@ -89,7 +89,10 @@ const std::string& showstring(const std::string& s) TASCAR::tsc_reader_t::~tsc_reader_t() { - chdir(orig_path.c_str()); + auto result = chdir(orig_path.c_str()); + if(result != 0) + TASCAR::add_warning("Unable to change to directory \"" + orig_path + "\"." + + strerror(errno)); } TASCAR::tsc_reader_t::tsc_reader_t(const std::string& filename_or_data, diff --git a/plugins/src/tascarmod_oscserver.cc b/plugins/src/tascarmod_oscserver.cc index 0ae51899..517d4b89 100644 --- a/plugins/src/tascarmod_oscserver.cc +++ b/plugins/src/tascarmod_oscserver.cc @@ -48,9 +48,10 @@ oscserver_t::oscserver_t(const TASCAR::module_cfg_t& cfg) : module_base_t(cfg), srv_addr(""), srv_port("9877"), srv_proto("TCP"), srv(NULL) { - GET_ATTRIBUTE_(srv_addr); - GET_ATTRIBUTE_(srv_port); - GET_ATTRIBUTE_(srv_proto); + GET_ATTRIBUTE(srv_addr, "", + "Server address (network device, multicast address)"); + GET_ATTRIBUTE(srv_port, "", "Port number"); + GET_ATTRIBUTE(srv_proto, "", "Server protocol (UDP or TCP)"); srv = new TASCAR::osc_server_t(srv_addr, srv_port, srv_proto); srv->add_method("", NULL, osc_recv_, this); srv->activate();