aboutsummaryrefslogtreecommitdiffstats
path: root/testing/shairport-sync/dont-check-pidfile-when-not-daemonised.patch
blob: aabeb818c8487248af038d327f6d4b68b96f0700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Tue, 11 Apr 2017 12:24:00 +0200
Subject: [PATCH] Don't check pidfile when not --daemon

shairport reads pidfile to check if it's not already running even when
started without -d / --daemon. Thus it cannot be properly started by
init system without enabling --daemon (that's a bad practice).

This patch fixes this behaviour.

--- a/shairport.c
+++ b/shairport.c
@@ -87,7 +87,9 @@
   shairport_shutdown();
   //  daemon_log(LOG_NOTICE, "exit...");
   daemon_retval_send(255);
-  daemon_pid_file_remove();
+  if (config.daemonise) {
+    daemon_pid_file_remove();
+  }
   exit(0);
 }
 
@@ -997,7 +999,7 @@
   }
 
   /* Check that the daemon is not running twice at the same time */
-  if ((pid = daemon_pid_file_is_running()) >= 0) {
+  if (config.daemonise && (pid = daemon_pid_file_is_running()) >= 0) {
     daemon_log(LOG_ERR, "Daemon already running on PID file %u", pid);
     return 1;
   }
@@ -1257,6 +1259,8 @@
 finish:
   daemon_log(LOG_NOTICE, "Unexpected exit...");
   daemon_retval_send(255);
-  daemon_pid_file_remove();
+  if (config.daemonise) {
+    daemon_pid_file_remove();
+  }
   return 1;
 }