From 12f26893b731a5ac2a8eb5fc5aacc95b0d222a16 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Sat, 18 Oct 2014 16:00:33 +0100 Subject: [PATCH] Only customise libdaemon if localstatedir option is really chosen. --- Makefile.am | 11 ++++++++--- configure.ac | 9 +++++++-- shairport.c | 15 +++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index f923c9b8..a0cf7156 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,10 @@ bin_PROGRAMS = shairport-sync shairport_sync_SOURCES = shairport.c rtsp.c mdns.c mdns_external.c common.c rtp.c player.c alac.c audio.c audio_dummy.c audio_pipe.c -install-exec-hook: - [ -f /etc/init.d/shairport-sync ] || cp scripts/shairport-sync /etc/init.d/ - update-rc.d shairport-sync defaults 90 10 +if USE_CUSTOMLOCALSTATEDIR +AM_CFLAGS= \ + -DLOCALSTATEDIR=\"$(CUSTOM_LOCAL_STATE_DIR)\" +endif if USE_AVAHI shairport_sync_SOURCES += mdns_avahi.c @@ -32,3 +33,7 @@ endif if USE_DNS_SD shairport_sync_SOURCES += mdns_dns_sd.c endif + +install-exec-hook: + [ -f /etc/init.d/shairport-sync ] || cp scripts/shairport-sync /etc/init.d/ + update-rc.d shairport-sync defaults 90 10 diff --git a/configure.ac b/configure.ac index d8ae552c..c9b2b2e8 100644 --- a/configure.ac +++ b/configure.ac @@ -28,13 +28,18 @@ 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)) AC_CHECK_LIB([popt],[poptGetContext], , AC_MSG_ERROR(libpopt needed)) +# Look for localstatedir flag +AC_ARG_WITH(localstatedir, [ --with-localstatedir = choose where to place the run directory containing the PID file], [ + HAS_CUSTOMLOCALSTATEDIR=1 + AC_SUBST(CUSTOM_LOCAL_STATE_DIR,["${with_localstatedir}"]) + AC_DEFINE([USE_CUSTOM_LOCAL_STATE_DIR],1,[Hook up special proc to libdaemon])], ) +AM_CONDITIONAL([USE_CUSTOMLOCALSTATEDIR], [test "x$HAS_CUSTOMLOCALSTATEDIR" = "x1"]) + # Look for polarssl flag AC_ARG_WITH(polarssl, [ --with-polarssl = choose polarssl for encryption services (choose this or --with-openssl)], [ AC_MSG_RESULT(>>Including polarssl) diff --git a/shairport.c b/shairport.c index 041c6732..654331cd 100644 --- a/shairport.c +++ b/shairport.c @@ -321,19 +321,23 @@ void shairport_startup_complete(void) { } } +#ifdef USE_CUSTOM_LOCAL_STATE_DIR + 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"); + debug(1,"Checking PID file location 1."); + asprintf(&fn, "%s/run/%s.pid", LOCALSTATEDIR, 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"); + snprintf(fn, sizeof(fn), "%s/run/%s.pid", LOCALSTATEDIR, daemon_pid_file_ident ? daemon_pid_file_ident : "unknown"); + debug(1,"Checking PID file location 2."); #endif return fn; } - +#endif int main(int argc, char **argv) { @@ -365,9 +369,12 @@ int main(int argc, char **argv) { return 1; } - /* Point to a function to help locate where the PID file will go */ +#if USE_CUSTOM_LOCAL_STATE_DIR + debug(1,"Locating localstatedir at \"%s\"",LOCALSTATEDIR); + /* Point to a function to help locate where the PID file will go */ daemon_pid_file_proc = pid_file_proc; +#endif /* 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]);