From 62fca43f498879a025465f583180b08c9184853f Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Wed, 12 Oct 2022 14:21:43 +0100 Subject: [PATCH] Fix a bug when displayConfig was exiting when the soxr timer thread hadn't been started. Also quieten a cryptic dbus message. --- dbus-service.c | 7 ++++--- shairport.c | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dbus-service.c b/dbus-service.c index c461e12a..c6cc2ac7 100644 --- a/dbus-service.c +++ b/dbus-service.c @@ -1129,10 +1129,11 @@ int start_dbus_service() { void stop_dbus_service() { debug(2, "stopping dbus service"); - if (ownerID) + if (ownerID) { g_bus_unown_name(ownerID); - else - debug(1, "Zero OwnerID for \"org.gnome.ShairportSync\"."); + } else if (service_is_running != 0) { + debug(1, "Zero OwnerID for running \"org.gnome.ShairportSync\" dbus service."); + } service_is_running = 0; } diff --git a/shairport.c b/shairport.c index 439e5b6a..d9fe93a5 100644 --- a/shairport.c +++ b/shairport.c @@ -171,6 +171,7 @@ int has_fltp_capable_aac_decoder(void) { #ifdef CONFIG_SOXR pthread_t soxr_time_check_thread; +int soxr_time_check_thread_started = 0; void *soxr_time_check(__attribute__((unused)) void *arg) { const int buffer_length = 352; int32_t inbuffer[buffer_length * 2]; @@ -1541,6 +1542,7 @@ void exit_function() { #ifdef CONFIG_DBUS_INTERFACE debug(2, "Stopping D-Bus service"); stop_dbus_service(); + debug(2, "Stopping D-Bus service done"); #endif if (g_main_loop) { debug(2, "Stopping D-Bus Loop Thread"); @@ -1551,35 +1553,48 @@ void exit_function() { // so don't wait for it if (type_of_exit_cleanup != TOE_dbus) pthread_join(dbus_thread, NULL); + debug(2, "Stopping D-Bus Loop Thread Done"); } #endif #ifdef CONFIG_DACP_CLIENT debug(2, "Stopping DACP Monitor"); dacp_monitor_stop(); + debug(2, "Stopping DACP Monitor Done"); #endif #ifdef CONFIG_METADATA_HUB debug(2, "Stopping metadata hub"); metadata_hub_stop(); + debug(2, "Stopping metadata done"); #endif #ifdef CONFIG_METADATA debug(2, "Stopping metadata"); metadata_stop(); // close down the metadata pipe + debug(2, "Stopping metadata done"); #endif debug(2, "Stopping the activity monitor."); activity_monitor_stop(0); + debug(2, "Stopping the activity monitor done."); + if ((config.output) && (config.output->deinit)) { debug(2, "Deinitialise the audio backend."); config.output->deinit(); + debug(2, "Deinitialise the audio backend done."); + } #ifdef CONFIG_SOXR // be careful -- not sure if the thread can be cancelled cleanly, so wait for it to shut down - debug(2, "Waiting for SoXr timecheck to terminate..."); - pthread_join(soxr_time_check_thread, NULL); + if (soxr_time_check_thread_started != 0) { + debug(1, "Waiting for SoXr timecheck to terminate..."); + pthread_join(soxr_time_check_thread, NULL); + soxr_time_check_thread_started = 0; + debug(1, "Waiting for SoXr timecheck to terminate done"); + } + #endif if (conns) @@ -2354,6 +2369,7 @@ int main(int argc, char **argv) { #ifdef CONFIG_SOXR pthread_create(&soxr_time_check_thread, NULL, &soxr_time_check, NULL); + soxr_time_check_thread_started = 1; #endif /*