diff --git a/src/Updater.cpp b/src/Updater.cpp index 9fc5a64..2e25321 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -172,40 +172,45 @@ void Updater::ThreadProc() pfd.fd = this->event_reader; pfd.events = POLLIN; - while (true) - { - int ret = poll(&pfd, 1, std::chrono::duration_cast(updateRate).count()); // 1000 ms timeout + try { + while (true) + { + int ret = poll(&pfd, 1, std::chrono::duration_cast(updateRate).count()); // 1000 ms timeout - if (ret == -1) - { - Lv2Log::error("Updater: Poll error."); - break; - } - else if (ret == 0) - { - CheckForUpdate(true); - } - else - { - // Event occurred - uint64_t value; - ssize_t s = read(event_reader, &value, sizeof(uint64_t)); - if (s == sizeof(uint64_t)) + if (ret == -1) { - if (value == CHECK_NOW_EVENT) + Lv2Log::error("Updater: Poll error."); + break; + } + else if (ret == 0) + { + CheckForUpdate(true); + } + else + { + // Event occurred + uint64_t value; + ssize_t s = read(event_reader, &value, sizeof(uint64_t)); + if (s == sizeof(uint64_t)) { - CheckForUpdate(true); - } - else if (value == UNCACHED_CHECK_NOW_EVENT) - { - CheckForUpdate(false); - } - else - { - break; + if (value == CHECK_NOW_EVENT) + { + CheckForUpdate(true); + } + else if (value == UNCACHED_CHECK_NOW_EVENT) + { + CheckForUpdate(false); + } + else + { + break; + } } } } + } catch (const std::exception&e) + { + Lv2Log::error(SS("Updater: Service thread terminated abnormally: " << e.what())); } } diff --git a/src/main.cpp b/src/main.cpp index 43a845b..5a19f19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,8 +220,28 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; // tell systemd not to auto-restart. } } + // only accept signals on the main thread. + // block now so that threads spawned by model inherit the block mask. + int sig; + sigset_t sigSet; + int s; + sigemptyset(&sigSet); + sigaddset(&sigSet, SIGINT); + sigaddset(&sigSet, SIGTERM); + sigaddset(&sigSet, SIGUSR1); + + s = pthread_sigmask(SIG_BLOCK, &sigSet, NULL); + if (s != 0) + { + throw std::logic_error("pthread_sigmask failed."); + } + + + PiPedalModel model; + + model.SetRestartListener( []() { @@ -243,20 +263,6 @@ int main(int argc, char *argv[]) model.WaitForAudioDeviceToComeOnline(); - // only accept signals on the main thread. - int sig; - sigset_t sigSet; - int s; - sigemptyset(&sigSet); - sigaddset(&sigSet, SIGINT); - sigaddset(&sigSet, SIGTERM); - sigaddset(&sigSet, SIGUSR1); - - s = pthread_sigmask(SIG_BLOCK, &sigSet, NULL); - if (s != 0) - { - throw std::logic_error("pthread_sigmask failed."); - } #if JACK_HOST if (systemd)