From ed0a9c9fb1ef5965fdec536572abce0e29dccc0c Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 30 Jan 2005 06:58:36 +0000 Subject: [PATCH] fix pidfile for heavyweight threads --- src/daapd.h | 1 + src/main.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/daapd.h b/src/daapd.h index a6dc898b..d47e4eb5 100644 --- a/src/daapd.h +++ b/src/daapd.h @@ -55,6 +55,7 @@ typedef struct tag_config { int process_m3u; /**< Should we process m3u files? */ int scan_type; /**< How hard to search mp3 files. see scan_get_mp3fileinfo() */ int compress; /**< Should we compress? */ + int pid; /**< pid that will accept INT to terminate */ char *adminpassword; /**< Password to web management pages */ char *readpassword; /**< iTunes password */ char *mp3dir; /**< root directory of the mp3 files */ diff --git a/src/main.c b/src/main.c index 08be2a17..c69196ef 100644 --- a/src/main.c +++ b/src/main.c @@ -612,6 +612,7 @@ void *signal_handler(void *arg) { config.stop=0; config.reload=0; + config.pid=getpid(); DPRINTF(E_WARN,L_MAIN,"Signal handler started\n"); @@ -804,8 +805,8 @@ int main(int argc, char *argv[]) { daemon_start(); - fprintf(pid_fp,"%d\n",getpid()); - fclose(pid_fp); + /* just to be on the safe side... */ + config.pid=0; } /* DWB: shouldn't this be done after dropping privs? */ @@ -824,6 +825,15 @@ int main(int argc, char *argv[]) { DPRINTF(E_FATAL,L_MAIN,"Error starting signal handler %s\n",strerror(errno)); } + + /* wait to for config.pid to be set by the signal handler */ + while(!config.pid) { + sleep(1); + } + + fprintf(pid_fp,"%d\n",config.pid); + fclose(pid_fp); + DPRINTF(E_LOG,L_MAIN|L_PL,"Loading playlists\n"); if(config.playlist)