aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorQball Cow <qball@qballcow.nl>2005-11-18 12:09:05 +0000
committerQball Cow <qball@qballcow.nl>2005-11-18 12:09:05 +0000
commit4b00c62587dbe0ce131992dcd574ffe323cffa5c (patch)
tree231924d4c2fb4eb916c3a02ed1fc505e42081e58 /src/main.c
parent32e5f4ca2b43c310ff6639320dec2dd52f159f50 (diff)
downloadmpd-4b00c62587dbe0ce131992dcd574ffe323cffa5c.tar.gz
mpd-4b00c62587dbe0ce131992dcd574ffe323cffa5c.tar.xz
mpd-4b00c62587dbe0ce131992dcd574ffe323cffa5c.zip
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
Diffstat (limited to '')
-rw-r--r--src/main.c24
1 files changed, 17 insertions, 7 deletions
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 <stdio.h>
#include <sys/select.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
@@ -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;
}