From 5a50fa7147be049212274534ccfbf7ed14708070 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 13 Apr 2004 17:08:31 +0000 Subject: block signals when writing db to ensure db isn't corrupted git-svn-id: https://svn.musicpd.org/mpd/trunk@730 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 7 +++++++ src/sig_handlers.c | 4 ++++ src/song.c | 2 ++ src/tag.c | 1 + 4 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/directory.c b/src/directory.c index 8a193d5a2..ec0d24ba7 100644 --- a/src/directory.c +++ b/src/directory.c @@ -553,6 +553,7 @@ int printDirectoryInfo(FILE * fp, char * name) { return 0; } +/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */ void writeDirectoryInfo(FILE * fp, Directory * directory) { ListNode * node = (directory->subDirectories)->firstNode; Directory * subDirectory; @@ -684,12 +685,18 @@ int writeDirectoryDB() { while(!(fp=fopen(directorydb,"w")) && errno==EINTR); if(!fp) return -1; + /* block signals so we ensure the db doesn't get corrupted */ + /* no functions that writeDirectoryInfoCalls should mess with + signals or signal blocking! */ + blockSignals(); 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()); myfprintf(fp,"%s\n",DIRECTORY_INFO_END); writeDirectoryInfo(fp,mp3rootDirectory); + unblockSignals(); + while(fclose(fp) && errno==EINTR); return 0; diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 126777de6..84ca8b78e 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -90,6 +90,8 @@ void blockSignals() { sigaddset(&sset,SIGCHLD); sigaddset(&sset,SIGUSR1); sigaddset(&sset,SIGHUP); + sigaddset(&sset,SIGINT); + sigaddset(&sset,SIGTERM); while(sigprocmask(SIG_BLOCK,&sset,NULL)<0 && errno==EINTR); } @@ -100,5 +102,7 @@ void unblockSignals() { sigaddset(&sset,SIGCHLD); sigaddset(&sset,SIGUSR1); sigaddset(&sset,SIGHUP); + sigaddset(&sset,SIGINT); + sigaddset(&sset,SIGTERM); while(sigprocmask(SIG_UNBLOCK,&sset,NULL)<0 && errno==EINTR); } diff --git a/src/song.c b/src/song.c index d9b28284c..1c3d53ad2 100644 --- a/src/song.c +++ b/src/song.c @@ -132,6 +132,7 @@ void freeSongList(SongList * list) { freeList(list); } +/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */ int printSongInfo(FILE * fp, Song * song) { myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file); @@ -151,6 +152,7 @@ int printSongInfoFromList(FILE * fp, SongList * list) { return 0; } +/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */ void writeSongInfoFromList(FILE * fp, SongList * list) { ListNode * tempNode = list->firstNode; diff --git a/src/tag.c b/src/tag.c index 23128ae16..c4623bb58 100644 --- a/src/tag.c +++ b/src/tag.c @@ -51,6 +51,7 @@ #include "mp4ff/mp4ff.h" #endif +/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */ void printMpdTag(FILE * fp, MpdTag * tag) { if(tag->artist) myfprintf(fp,"Artist: %s\n",tag->artist); if(tag->album) myfprintf(fp,"Album: %s\n",tag->album); -- cgit v1.2.3