aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-11 01:53:25 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-11 01:53:25 +0000
commit12ee01660739b19fa9b0c112e6a6b266a4e2d6a8 (patch)
treeca377875b1101607907243c3bf330ad80b7018cf /src/directory.c
parent171a7752a8fab0e1c55be1469a331ef20a7b3755 (diff)
downloadmpd-12ee01660739b19fa9b0c112e6a6b266a4e2d6a8.tar.gz
mpd-12ee01660739b19fa9b0c112e6a6b266a4e2d6a8.tar.xz
mpd-12ee01660739b19fa9b0c112e6a6b266a4e2d6a8.zip
make "update" command background/non-blocking
git-svn-id: https://svn.musicpd.org/mpd/trunk@665 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/directory.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/directory.c b/src/directory.c
index dd0f49b54..16f2c0fa0 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -26,14 +26,21 @@
#include "conf.h"
#include "stats.h"
#include "playlist.h"
+#include "listen.h"
+#include "interface.h"
+#include "volume.h"
#include <string.h>
#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
+#include <signal.h>
#define DIRECTORY_DIR "directory: "
#define DIRECTORY_MTIME "mtime: "
@@ -63,6 +70,8 @@ Directory * mp3rootDirectory = NULL;
char directorydb[MAXPATHLEN+1];
+int directory_updatePid = 0;
+
DirectoryList * newDirectoryList();
int addToDirectory(Directory * directory, char * shortname, char * name);
@@ -79,6 +88,61 @@ void deleteEmptyDirectoriesInDirectory(Directory * directory);
int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name);
+void directory_sigChldHandler(int pid, int status) {
+ if(directory_updatePid==pid) {
+ if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
+ ERROR("update process died from a "
+ "non-TERM signal: %i\n",
+ WTERMSIG(status));
+ }
+ else if(WEXITSTATUS(status)==EXIT_SUCCESS) {
+ readDirectoryDB();
+ incrPlaylistVersion();
+ DEBUG("direcotry_sigChldHandler: "
+ "updated db succesffully\n");
+ }
+ directory_updatePid = 0;
+ }
+}
+
+int updateInit(FILE * fp) {
+ if(directory_updatePid > 0) {
+ myfprintf(fp,"%s already updating\n",COMMAND_RESPOND_ERROR);
+ return -1;
+ }
+
+ directory_updatePid = fork();
+ if(directory_updatePid==0) {
+ /* child */
+ struct sigaction sa;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE,&sa,NULL);
+ sigaction(SIGCHLD,&sa,NULL);
+
+ close(listenSocket);
+ freeAllInterfaces();
+ finishPlaylist();
+ finishVolume();
+
+ if(updateMp3Directory(stderr)) exit(EXIT_FAILURE);
+ exit(EXIT_SUCCESS);
+ }
+ else if(directory_updatePid < 0) {
+ ERROR("updateInit: Problems forking()'ing\n");
+ myfprintf(fp,"%s problems trying to update\n",
+ COMMAND_RESPOND_ERROR);
+ directory_updatePid = 0;
+ return -1;
+ }
+
+ DEBUG("updateInit: fork()'d update child\n");
+
+ return 0;
+}
+
Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mtime) {
Directory * directory;