]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Double check debug is not a cancellation point and move the dacp monitor initialisati...
authorMike Brady <mikebrady@eircom.net>
Tue, 20 Nov 2018 12:06:13 +0000 (12:06 +0000)
committerMike Brady <mikebrady@eircom.net>
Tue, 20 Nov 2018 12:06:13 +0000 (12:06 +0000)
common.c
player.c

index 6694a3e621eef40f42c7b840c999817daf488e08..2a7d9ad8afb075537d6394f34083fef78d190a91 100644 (file)
--- a/common.c
+++ b/common.c
@@ -173,6 +173,10 @@ void debug(int level, const char *format, ...) {
   va_start(args, format);
   vsnprintf(s, sizeof(s), format, args);
   va_end(args);
+  int currentState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &currentState);
+  if (currentState == PTHREAD_CANCEL_ENABLE)
+    daemon_log(LOG_DEBUG, "Warning -- cancellation is enabled before logging");
   if ((config.debugger_show_elapsed_time) && (config.debugger_show_relative_time))
     daemon_log(LOG_DEBUG, "|% 20.9f|% 20.9f|%s", tss, tsl, s);
   else if (config.debugger_show_relative_time)
@@ -181,6 +185,9 @@ void debug(int level, const char *format, ...) {
     daemon_log(LOG_DEBUG, "% 20.9f|%s", tss, s);
   else
     daemon_log(LOG_DEBUG, "%s", s);
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &currentState);
+  if (currentState == PTHREAD_CANCEL_ENABLE)
+    daemon_log(LOG_DEBUG, "Warning -- cancellation is enabled after logging");
   pthread_setcancelstate(oldState,NULL);
 }
 
index 6436651dc033dd79a86ae3581e74866afe07ae4c..a2a1640df66c5ea5dae861ae3c6cf2d889fbe4fb 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1677,23 +1677,6 @@ void *player_thread_func(void *arg) {
   int sync_error_out_of_bounds =
       0; // number of times in a row that there's been a serious sync error
 
-// stop looking elsewhere for DACP stuff
-#ifdef CONFIG_DACP_CLIENT
-  // debug(1, "Set dacp server info");
-  // this does not have pthread cancellation points in it (assuming avahi doesn't)
-  set_dacp_server_information(conn); //  this will start scanning when a port is registered by the
-                                     // code initiated by the mdns_dacp_monitor
-#else
-  // this is only used for compatability, if dacp stuff isn't enabled.
-  // start an mdns/zeroconf thread to look for DACP messages containing our DACP_ID and getting the
-  // port number
-  if (conn->dapo_private_storage)
-    debug(1, "DACP monitor already initialised?");
-  else
-    // this does not have pthread cancellation points in it (assuming avahi doesn't)
-    conn->dapo_private_storage = mdns_dacp_monitor(conn->dacp_id);
-#endif
-
   conn->framesProcessedInThisEpoch = 0;
   conn->framesGeneratedInThisEpoch = 0;
   conn->correctionsRequestedInThisEpoch = 0;
@@ -1758,6 +1741,23 @@ void *player_thread_func(void *arg) {
 
   pthread_cleanup_push(player_thread_cleanup_handler, arg); // undo what's been done so far
 
+// stop looking elsewhere for DACP stuff
+#ifdef CONFIG_DACP_CLIENT
+  // debug(1, "Set dacp server info");
+  // this does not have pthread cancellation points in it (assuming avahi doesn't)
+  set_dacp_server_information(conn); //  this will start scanning when a port is registered by the
+                                     // code initiated by the mdns_dacp_monitor
+#else
+  // this is only used for compatability, if dacp stuff isn't enabled.
+  // start an mdns/zeroconf thread to look for DACP messages containing our DACP_ID and getting the
+  // port number
+  if (conn->dapo_private_storage)
+    debug(1, "DACP monitor already initialised?");
+  else
+    // this does not have pthread cancellation points in it (assuming avahi doesn't)
+    conn->dapo_private_storage = mdns_dacp_monitor(conn->dacp_id);
+#endif
+
   // set the default volume to whaterver it was before, as stored in the config airplay_volume
   debug(2, "Set initial volume to %f.", config.airplay_volume);
   player_volume(config.airplay_volume, conn); // will contain a cancellation point if asked to wait