]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
check that the systems are started before trying to stop them, duh.
authorMike Brady <mikebrady@eircom.net>
Tue, 5 Feb 2019 15:51:16 +0000 (15:51 +0000)
committerMike Brady <mikebrady@eircom.net>
Tue, 5 Feb 2019 15:51:16 +0000 (15:51 +0000)
activity_monitor.c
dacp.c
metadata_hub.c
rtsp.c
shairport.c

index 6452a08ef8b8a58132686e12d5bff10f6e38159f..86af012a616eb94a4cbe38eac799e1d3ba722262 100644 (file)
@@ -45,6 +45,8 @@
 enum am_state { am_inactive, am_active, am_timing_out } state;
 enum ps_state { ps_inactive, ps_active } player_state;
 
+int activity_monitor_running = 0;
+
 pthread_t activity_monitor_thread;
 pthread_mutex_t activity_monitor_mutex;
 pthread_cond_t activity_monitor_cv;
@@ -218,11 +220,14 @@ void *activity_monitor_thread_code(void *arg) {
 void activity_monitor_start() {
   // debug(1,"activity_monitor_start");
   pthread_create(&activity_monitor_thread, NULL, activity_monitor_thread_code, NULL);
+  activity_monitor_running = 1;
 }
 
 void activity_monitor_stop() {
-  debug(1, "activity_monitor_stop start...");
-  pthread_cancel(activity_monitor_thread);
-  pthread_join(activity_monitor_thread, NULL);
-  debug(1, "activity_monitor_stop complete");
+  if (activity_monitor_running) {
+    debug(1, "activity_monitor_stop start...");
+    pthread_cancel(activity_monitor_thread);
+    pthread_join(activity_monitor_thread, NULL);
+    debug(1, "activity_monitor_stop complete");
+  }
 }
diff --git a/dacp.c b/dacp.c
index 7efaea3ad97471a48cadb7ef4592fc0f6a001fc8..4f40e2d0dbb90df1d492a23d0728c77c4fb35d98 100644 (file)
--- a/dacp.c
+++ b/dacp.c
@@ -58,6 +58,7 @@ typedef struct {
   void *port_monitor_private_storage;
 } dacp_server_record;
 
+int dacp_monitor_initialised = 0;
 pthread_t dacp_monitor_thread;
 dacp_server_record dacp_server;
 void *mdns_dacp_monitor_private_storage_pointer;
@@ -888,15 +889,18 @@ void dacp_monitor_start() {
   memset(&dacp_server, 0, sizeof(dacp_server_record));
 
   pthread_create(&dacp_monitor_thread, NULL, dacp_monitor_thread_code, NULL);
+  dacp_monitor_initialised = 1;
 }
 
 void dacp_monitor_stop() {
-  debug(1, "dacp_monitor_stop");
-  pthread_cancel(dacp_monitor_thread);
-  pthread_join(dacp_monitor_thread, NULL);
-  pthread_mutex_destroy(&dacp_server_information_lock);
-  debug(1, "DACP Conversation Lock Mutex Destroyed");
-  pthread_mutex_destroy(&dacp_conversation_lock);
+  if (dacp_monitor_initialised) { // only if it's been started and initialised
+    debug(1, "dacp_monitor_stop");
+    pthread_cancel(dacp_monitor_thread);
+    pthread_join(dacp_monitor_thread, NULL);
+    pthread_mutex_destroy(&dacp_server_information_lock);
+    debug(1, "DACP Conversation Lock Mutex Destroyed");
+    pthread_mutex_destroy(&dacp_conversation_lock);
+  }
 }
 
 uint32_t dacp_tlv_crawl(char **p, int32_t *length) {
index 5686964773492e7c8e4d660f118f7dc82135face..f116f2723e6899b1a266c2de3400fce88437f5a8 100644 (file)
@@ -58,6 +58,8 @@
 #include <openssl/md5.h>
 #endif
 
+int metadata_hub_initialised = 0;
+
 pthread_rwlock_t metadata_hub_re_lock = PTHREAD_RWLOCK_INITIALIZER;
 struct track_metadata_bundle *track_metadata; // used for a temporary track metadata store
 
@@ -100,18 +102,21 @@ void metadata_hub_init(void) {
   // debug(1, "Metadata bundle initialisation.");
   memset(&metadata_store, 0, sizeof(metadata_store));
   track_metadata = NULL;
+  metadata_hub_initialised = 1;
 }
 
 void metadata_hub_stop(void) {
-  debug(1, "metadata_hub_stop.");
-  metadata_hub_release_track_artwork();
-  if (metadata_store.track_metadata) {
-    metadata_hub_release_track_metadata(metadata_store.track_metadata);
-    metadata_store.track_metadata = NULL;
-  }
-  if (track_metadata) {
-    metadata_hub_release_track_metadata(track_metadata);
-    track_metadata = NULL;
+  if (metadata_hub_initialised) {
+    debug(1, "metadata_hub_stop.");
+    metadata_hub_release_track_artwork();
+    if (metadata_store.track_metadata) {
+      metadata_hub_release_track_metadata(metadata_store.track_metadata);
+      metadata_store.track_metadata = NULL;
+    }
+    if (track_metadata) {
+      metadata_hub_release_track_metadata(track_metadata);
+      track_metadata = NULL;
+    }
   }
 }
 
diff --git a/rtsp.c b/rtsp.c
index 4b4b28e9a75b7c60decad55b90626b10fbdcffcd..9aff0e653b02e751408370057b6e80caf42834b0 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -91,6 +91,8 @@ enum rtsp_read_request_response {
 
 // Mike Brady's part...
 
+int metadata_running = 0;
+
 // always lock use this when accessing the playing conn value
 static pthread_mutex_t playing_conn_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -1454,12 +1456,15 @@ void metadata_init(void) {
   int ret = pthread_create(&metadata_thread, NULL, metadata_thread_function, NULL);
   if (ret)
     debug(1, "Failed to create metadata thread!");
+  metadata_running = 1;
 }
 
 void metadata_stop(void) {
-  debug(1, "metadata_stop called.");
-  pthread_cancel(metadata_thread);
-  pthread_join(metadata_thread, NULL);
+  if (metadata_running) {
+    debug(1, "metadata_stop called.");
+    pthread_cancel(metadata_thread);
+    pthread_join(metadata_thread, NULL);
+  }
 }
 
 int send_metadata(uint32_t type, uint32_t code, char *data, uint32_t length, rtsp_message *carrier,
index e1689d3e05e9c7690de81bb376da94e4986d5ebe..2bea884f70c8d704d8010ad45011a19981ff6867 100644 (file)
@@ -1075,7 +1075,7 @@ int parse_options(int argc, char **argv) {
 }
 
 #if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
-GMainLoop *g_main_loop;
+static GMainLoop *g_main_loop = NULL;
 
 pthread_t dbus_thread;
 void *dbus_thread_func(__attribute__((unused)) void *arg) {
@@ -1138,7 +1138,7 @@ const char *pid_file_proc(void) {
 #endif
 
 void main_cleanup_handler(__attribute__((unused)) void *arg) {
-  // it doesn't look like this is called when the main function terminates.
+  // it doesn't look like this is called when the main function is cancelled eith a pthread cancel.
   debug(1, "main cleanup handler called.");
 #ifdef CONFIG_MQTT
   if (config.mqtt_enabled) {
@@ -1153,9 +1153,11 @@ void main_cleanup_handler(__attribute__((unused)) void *arg) {
 #ifdef CONFIG_DBUS_INTERFACE
   stop_dbus_service();
 #endif
-  debug(1, "Stopping DBUS Loop Thread");
-  g_main_loop_quit(g_main_loop);
-  pthread_join(dbus_thread, NULL);
+  if (g_main_loop) {
+    debug(1, "Stopping DBUS Loop Thread");
+    g_main_loop_quit(g_main_loop);
+    pthread_join(dbus_thread, NULL);
+  }
 #endif
 
 #ifdef CONFIG_DACP_CLIENT
@@ -1174,7 +1176,7 @@ void main_cleanup_handler(__attribute__((unused)) void *arg) {
 
   activity_monitor_stop(0);
 
-  if (config.output->deinit) {
+  if ((config.output) && (config.output->deinit)) {
     debug(1, "Deinitialise the audio backend.");
     config.output->deinit();
   }