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
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#define COMMAND_RETURN_KILL 10
|
#define COMMAND_RETURN_KILL 10
|
||||||
#define COMMAND_RETURN_CLOSE 20
|
#define COMMAND_RETURN_CLOSE 20
|
||||||
|
#define COMMAND_MASTER_READY 30
|
||||||
|
|
||||||
extern char * current_command;
|
extern char * current_command;
|
||||||
extern int command_listNum;
|
extern int command_listNum;
|
||||||
|
@@ -112,6 +112,10 @@ void registerConfigParam(char * name, int repeatable, int block) {
|
|||||||
insertInList(configEntriesList, name, entry);
|
insertInList(configEntriesList, name, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finishConf() {
|
||||||
|
freeList(configEntriesList);
|
||||||
|
}
|
||||||
|
|
||||||
void initConf() {
|
void initConf() {
|
||||||
configEntriesList = makeList((ListFreeDataFunc *)freeConfigEntry, 1);
|
configEntriesList = makeList((ListFreeDataFunc *)freeConfigEntry, 1);
|
||||||
|
|
||||||
@@ -295,6 +299,7 @@ void readConf(char * file) {
|
|||||||
|
|
||||||
freeArgArray(array, numberOfArgs);
|
freeArgArray(array, numberOfArgs);
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigParam * getNextConfigParam(char * name, ConfigParam * last) {
|
ConfigParam * getNextConfigParam(char * name, ConfigParam * last) {
|
||||||
|
@@ -73,6 +73,7 @@ typedef struct _ConfigParam {
|
|||||||
} ConfigParam;
|
} ConfigParam;
|
||||||
|
|
||||||
void initConf();
|
void initConf();
|
||||||
|
void finishConf();
|
||||||
|
|
||||||
void readConf(char * file);
|
void readConf(char * file);
|
||||||
|
|
||||||
|
24
src/main.c
24
src/main.c
@@ -42,6 +42,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -306,6 +307,7 @@ void startMainProcess() {
|
|||||||
|
|
||||||
mainPid = pid;
|
mainPid = pid;
|
||||||
masterInitSigHandlers();
|
masterInitSigHandlers();
|
||||||
|
kill(mainPid, SIGUSR1);
|
||||||
while (masterHandlePendingSignals()!=COMMAND_RETURN_KILL)
|
while (masterHandlePendingSignals()!=COMMAND_RETURN_KILL)
|
||||||
waitOnSignals();
|
waitOnSignals();
|
||||||
/* we're killed */
|
/* we're killed */
|
||||||
@@ -320,6 +322,9 @@ void startMainProcess() {
|
|||||||
finishPaths();
|
finishPaths();
|
||||||
|
|
||||||
kill(mainPid, SIGTERM);
|
kill(mainPid, SIGTERM);
|
||||||
|
waitpid(mainPid,NULL,0);
|
||||||
|
finishConf();
|
||||||
|
myfprintfCloseLogFile();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
} else if(pid<0) {
|
} else if(pid<0) {
|
||||||
@@ -483,8 +488,8 @@ void killFromPidFile(char * cmd, int killOption) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
FILE * out;
|
FILE * out = NULL;
|
||||||
FILE * err;
|
FILE * err = NULL;
|
||||||
Options options;
|
Options options;
|
||||||
|
|
||||||
closeAllFDs();
|
closeAllFDs();
|
||||||
@@ -519,8 +524,7 @@ int main(int argc, char * argv[]) {
|
|||||||
/* This is the main process which has
|
/* This is the main process which has
|
||||||
* been forked from the master process.
|
* been forked from the master process.
|
||||||
*/
|
*/
|
||||||
|
initSigHandlers();
|
||||||
|
|
||||||
|
|
||||||
initPermissions();
|
initPermissions();
|
||||||
|
|
||||||
@@ -539,8 +543,12 @@ int main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
setupLogOutput(&options, out, err);
|
setupLogOutput(&options, out, err);
|
||||||
|
|
||||||
openVolumeDevice();
|
/* wait for the master process to get ready so we can start
|
||||||
initSigHandlers();
|
* playing if readPlaylistState thinks we should*/
|
||||||
|
while (COMMAND_MASTER_READY != handlePendingSignals())
|
||||||
|
my_usleep(1);
|
||||||
|
|
||||||
|
openVolumeDevice();
|
||||||
readPlaylistState();
|
readPlaylistState();
|
||||||
|
|
||||||
|
|
||||||
@@ -567,6 +575,8 @@ int main(int argc, char * argv[]) {
|
|||||||
finishCommands();
|
finishCommands();
|
||||||
finishInputPlugins();
|
finishInputPlugins();
|
||||||
cleanUpPidFile();
|
cleanUpPidFile();
|
||||||
|
finishConf();
|
||||||
|
|
||||||
|
myfprintfCloseLogFile();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -122,3 +122,10 @@ int myfprintfCloseAndOpenLogFile() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void myfprintfCloseLogFile() {
|
||||||
|
if(myfprintf_stdLogMode) {
|
||||||
|
while(fclose(myfprintf_out)<0 && errno==EINTR);
|
||||||
|
while(fclose(myfprintf_err)<0 && errno==EINTR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -29,4 +29,5 @@ void myfprintf(FILE * fp, char * format, ... );
|
|||||||
|
|
||||||
int myfprintfCloseAndOpenLogFile();
|
int myfprintfCloseAndOpenLogFile();
|
||||||
|
|
||||||
|
void myfprintfCloseLogFile();
|
||||||
#endif
|
#endif
|
||||||
|
@@ -56,7 +56,17 @@ int masterHandlePendingSignals() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int handlePendingSignals() {
|
int handlePendingSignals() {
|
||||||
if(signal_is_pending(SIGINT) || signal_is_pending(SIGTERM)) {
|
/* this SIGUSR1 signal comes before the KILL signals, because there if the process is
|
||||||
|
* looping, waiting for this signal, it will not respond to the KILL signal. This might be
|
||||||
|
* better implemented by using bit-wise defines and or'ing of the COMMAND_FOO as return.
|
||||||
|
*/
|
||||||
|
if (signal_is_pending(SIGUSR1)) {
|
||||||
|
signal_clear(SIGUSR1);
|
||||||
|
DEBUG("The master process is ready to receive signals\n");
|
||||||
|
return COMMAND_MASTER_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(signal_is_pending(SIGINT) || signal_is_pending(SIGTERM)) {
|
||||||
DEBUG("main process got SIGINT or SIGTERM, exiting\n");
|
DEBUG("main process got SIGINT or SIGTERM, exiting\n");
|
||||||
return COMMAND_RETURN_KILL;
|
return COMMAND_RETURN_KILL;
|
||||||
}
|
}
|
||||||
@@ -135,6 +145,7 @@ void initSigHandlers() {
|
|||||||
while(sigaction(SIGPIPE,&sa,NULL)<0 && errno==EINTR);
|
while(sigaction(SIGPIPE,&sa,NULL)<0 && errno==EINTR);
|
||||||
sa.sa_handler = chldSigHandler;
|
sa.sa_handler = chldSigHandler;
|
||||||
while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
|
while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
|
||||||
|
signal_handle(SIGUSR2);
|
||||||
signal_handle(SIGUSR1);
|
signal_handle(SIGUSR1);
|
||||||
signal_handle(SIGINT);
|
signal_handle(SIGINT);
|
||||||
signal_handle(SIGTERM);
|
signal_handle(SIGTERM);
|
||||||
|
Reference in New Issue
Block a user