diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/directory.c | 5 | ||||
-rw-r--r-- | src/sig_handlers.c | 14 | ||||
-rw-r--r-- | src/sig_handlers.h | 2 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/directory.c b/src/directory.c index 8f2765d26..370744aae 100644 --- a/src/directory.c +++ b/src/directory.c @@ -150,6 +150,8 @@ int updateInit(FILE * fp, List * pathList) { directory_updatePid = fork(); if(directory_updatePid==0) { /* child */ + struct sigaction sa; + clearPlayerPid(); unblockSignals(); @@ -186,6 +188,8 @@ int updateInit(FILE * fp, List * pathList) { } } else if(updateDirectory(mp3rootDirectory)<0) exit(EXIT_FAILURE); + /* ignore signals since we don't want them to corrupt the db*/ + ignoreSignals(); if(writeDirectoryDB()<0) { ERROR("problems writing music db file, \"%s\"\n", directorydb); @@ -684,6 +688,7 @@ int writeDirectoryDB() { while(!(fp=fopen(directorydb,"w")) && errno==EINTR); if(!fp) return -1; + /* block signals when writing the db so we don't get a corrupted db*/ myfprintf(fp,"%s\n",DIRECTORY_INFO_BEGIN); myfprintf(fp,"%s%s\n",DIRECTORY_MPD_VERSION,VERSION); myfprintf(fp,"%s%s\n",DIRECTORY_FS_CHARSET,getFsCharset()); diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 84ca8b78e..eb39e9719 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -83,6 +83,20 @@ void finishSigHandlers() { signal_unhandle(SIGHUP); } +void ignoreSignals() { + struct sigaction sa; + + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + while(sigaction(SIGPIPE,&sa,NULL)<0 && errno==EINTR); + while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR); + while(sigaction(SIGUSR1,&sa,NULL)<0 && errno==EINTR); + while(sigaction(SIGINT,&sa,NULL)<0 && errno==EINTR); + while(sigaction(SIGTERM,&sa,NULL)<0 && errno==EINTR); + while(sigaction(SIGHUP,&sa,NULL)<0 && errno==EINTR); +} + void blockSignals() { sigset_t sset; diff --git a/src/sig_handlers.h b/src/sig_handlers.h index 415b15b45..6c5af549b 100644 --- a/src/sig_handlers.h +++ b/src/sig_handlers.h @@ -27,6 +27,8 @@ void initSigHandlers(); void finishSigHandlers(); +void ignoreSignals(); + void blockSignals(); void unblockSignals(); |