aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorQball Cow <qball@qballcow.nl>2005-11-16 14:43:04 +0000
committerQball Cow <qball@qballcow.nl>2005-11-16 14:43:04 +0000
commit32e5f4ca2b43c310ff6639320dec2dd52f159f50 (patch)
tree5cc7966297e726b9b6cb961a28ec6979796acacb /src/main.c
parent402c8cd707640f7bd857c3387a03bb4db40222d7 (diff)
downloadmpd-32e5f4ca2b43c310ff6639320dec2dd52f159f50.tar.gz
mpd-32e5f4ca2b43c310ff6639320dec2dd52f159f50.tar.xz
mpd-32e5f4ca2b43c310ff6639320dec2dd52f159f50.zip
DJWLindenaar balanced tree and master process patch
git-svn-id: https://svn.musicpd.org/mpd/trunk@3669 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c74
1 files changed, 60 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 67c76a981..4c6ef9c26 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,9 @@
#define SYSTEM_CONFIG_FILE_LOCATION "/etc/mpd.conf"
#define USER_CONFIG_FILE_LOCATION "/.mpdconf"
+volatile int masterPid = 0;
+volatile int mainPid = 0;
+
typedef struct _Options {
int kill;
int daemon;
@@ -288,6 +291,45 @@ void openDB(Options * options, char * argv0) {
}
}
+void startMainProcess() {
+ int pid;
+ fflush(0);
+ pid = fork();
+ if(pid>0) {
+ initInputStream();
+ initReplayGainState();
+ /* qball crappy code */
+ readAudioDevicesState();
+
+ /* free stuff we don't need */
+ freeAllListenSockets();
+
+ mainPid = pid;
+ masterInitSigHandlers();
+ while (masterHandlePendingSignals()!=COMMAND_RETURN_KILL)
+ waitOnSignals();
+ /* we're killed */
+ playerKill();
+
+ finishAudioConfig();
+ finishAudioDriver();
+
+ /* qball crappy code */
+ saveAudioDevicesState();
+
+ finishPaths();
+
+ kill(mainPid, SIGTERM);
+ exit(EXIT_SUCCESS);
+
+ } else if(pid<0) {
+ ERROR("problems fork'ing main process!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ DEBUG("main process started!\n");
+}
+
void daemonize(Options * options) {
FILE * fp;
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
@@ -338,6 +380,7 @@ void daemonize(Options * options) {
DEBUG("writing pid file\n");
fprintf(fp, "%lu\n", (unsigned long)getpid());
fclose(fp);
+ masterPid = getpid();
}
void setupLogOutput(Options * options, FILE * out, FILE * err) {
@@ -451,6 +494,7 @@ int main(int argc, char * argv[]) {
parseOptions(argc, argv, &options);
if(options.kill) killFromPidFile(argv[0], options.kill);
+
initStats();
initTagConfig();
@@ -459,31 +503,39 @@ int main(int argc, char * argv[]) {
if(options.createDB <= 0 && !options.updateDB) listenOnPort();
changeToUser();
-
+
openLogFiles(&options, &out, &err);
+ initPlayerData();
+
+ daemonize(&options);
+
+ initInputPlugins();
initPaths();
+ initAudioConfig();
+ initAudioDriver();
+
+ startMainProcess();
+ /* This is the main process which has
+ * been forked from the master process.
+ */
+
+
+
initPermissions();
- initReplayGainState();
initPlaylist();
- initInputPlugins();
openDB(&options, argv[0]);
initCommands();
- initPlayerData();
- initAudioConfig();
- initAudioDriver();
initVolume();
initInterfaces();
- initInputStream();
printMemorySavedByTagTracker();
printSavedMemoryFromFilenames();
/*printSavedMemoryFromDirectoryNames();*/
- daemonize(&options);
setupLogOutput(&options, out, err);
@@ -491,8 +543,6 @@ int main(int argc, char * argv[]) {
initSigHandlers();
readPlaylistState();
- /* qball crappy code */
- readAudioDevicesState();
while(COMMAND_RETURN_KILL!=doIOForInterfaces()) {
if(COMMAND_RETURN_KILL==handlePendingSignals()) break;
@@ -502,12 +552,8 @@ int main(int argc, char * argv[]) {
}
savePlaylistState();
- /* qball crappy code */
- saveAudioDevicesState();
- playerKill();
-
freeAllInterfaces();
closeAllListenSockets();
closeMp3Directory();