From 4b00c62587dbe0ce131992dcd574ffe323cffa5c Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Fri, 18 Nov 2005 12:09:05 +0000 Subject: DJWLindenaar's fix race condition and some memory leaks patch git-svn-id: https://svn.musicpd.org/mpd/trunk@3681 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 4c6ef9c26..1866ecfe0 100644 --- a/src/main.c +++ b/src/main.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -306,6 +307,7 @@ void startMainProcess() { mainPid = pid; masterInitSigHandlers(); + kill(mainPid, SIGUSR1); while (masterHandlePendingSignals()!=COMMAND_RETURN_KILL) waitOnSignals(); /* we're killed */ @@ -320,6 +322,9 @@ void startMainProcess() { finishPaths(); kill(mainPid, SIGTERM); + waitpid(mainPid,NULL,0); + finishConf(); + myfprintfCloseLogFile(); exit(EXIT_SUCCESS); } else if(pid<0) { @@ -483,8 +488,8 @@ void killFromPidFile(char * cmd, int killOption) { } int main(int argc, char * argv[]) { - FILE * out; - FILE * err; + FILE * out = NULL; + FILE * err = NULL; Options options; closeAllFDs(); @@ -519,8 +524,7 @@ int main(int argc, char * argv[]) { /* This is the main process which has * been forked from the master process. */ - - + initSigHandlers(); initPermissions(); @@ -539,8 +543,12 @@ int main(int argc, char * argv[]) { setupLogOutput(&options, out, err); - openVolumeDevice(); - initSigHandlers(); + /* wait for the master process to get ready so we can start + * playing if readPlaylistState thinks we should*/ + while (COMMAND_MASTER_READY != handlePendingSignals()) + my_usleep(1); + + openVolumeDevice(); readPlaylistState(); @@ -567,6 +575,8 @@ int main(int argc, char * argv[]) { finishCommands(); finishInputPlugins(); cleanUpPidFile(); - + finishConf(); + + myfprintfCloseLogFile(); return EXIT_SUCCESS; } -- cgit v1.2.3