diff --git a/configure.ac b/configure.ac index e97b89a2..d8ae552c 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.50]) -AC_INIT([shairport-sync], [2.1.3], [mikebrady@eircom.net]) +AC_INIT([shairport-sync], [2.1.4], [mikebrady@eircom.net]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([shairport.c]) AC_CONFIG_HEADERS([config.h]) @@ -28,6 +28,8 @@ if test "x${with_os_type}" = xlinux; then AC_CHECK_LIB([rt],[clock_gettime], , AC_MSG_ERROR(librt needed)) fi +AC_DEFINE_UNQUOTED([OURRUNSTATEDIR],["${localstatedir}/run"],[Needed for libdaemon]) + AC_CHECK_LIB([daemon],[daemon_log], , AC_MSG_ERROR(libdaemon needed)) AC_CHECK_LIB([pthread],[pthread_create], , AC_MSG_ERROR(pthread library needed)) AC_CHECK_LIB([m],[exp], , AC_MSG_ERROR(maths library needed)) diff --git a/shairport.c b/shairport.c index 24c366cd..041c6732 100644 --- a/shairport.c +++ b/shairport.c @@ -321,6 +321,20 @@ void shairport_startup_complete(void) { } } +const char *pid_file_proc(void) { +#ifdef HAVE_ASPRINTF + static char *fn = NULL; + free(fn); + asprintf(&fn, "%s/%s.pid", OURRUNSTATEDIR, daemon_pid_file_ident ? daemon_pid_file_ident : "unknown"); +#else + static char fn[8192]; + snprintf(fn, sizeof(fn), "%s/%s.pid", OURRUNSTATEDIR, daemon_pid_file_ident ? daemon_pid_file_ident : "unknown"); +#endif + + return fn; +} + + int main(int argc, char **argv) { daemon_set_verbosity(LOG_DEBUG); @@ -350,10 +364,14 @@ int main(int argc, char **argv) { daemon_log(LOG_ERR, "Failed to unblock all signals: %s", strerror(errno)); return 1; } + + /* Point to a function to help locate where the PID file will go */ + + daemon_pid_file_proc = pid_file_proc; /* Set indentification string for the daemon for both syslog and PID file */ daemon_pid_file_ident = daemon_log_ident = daemon_ident_from_argv0(argv[0]); - + /* Check if we are called with -P or --pause parameter */ if (argc >= 2 && ((strcmp(argv[1], "-P")==0) || (strcmp(argv[1], "--pause")==0))) { if ((pid = daemon_pid_file_is_running()) >= 0) { @@ -375,7 +393,7 @@ int main(int argc, char **argv) { if ((ret = daemon_pid_file_kill_wait(SIGTERM, 5)) < 0) daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno)); else - daemon_pid_file_remove(); // + daemon_pid_file_remove(); return ret < 0 ? 1 : 0; }