aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-27 22:25:06 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-27 22:25:06 +0000
commit8b19235b6113d869fba1239ac4d1406d6d7310b8 (patch)
tree8812c98d678e1ebc53072dfb707a11214a344afc /src
parentad4246d6cb9249c1bd3865d5619d57ae0d5fd8cd (diff)
downloadmpd-8b19235b6113d869fba1239ac4d1406d6d7310b8.tar.gz
mpd-8b19235b6113d869fba1239ac4d1406d6d7310b8.tar.xz
mpd-8b19235b6113d869fba1239ac4d1406d6d7310b8.zip
put decode_pid in shared mem, so if player process dies, the master
can still kill the decode process. git-svn-id: https://svn.musicpd.org/mpd/trunk@107 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/decode.c39
-rw-r--r--src/player.c20
-rw-r--r--src/player.h1
-rw-r--r--src/playerData.c1
4 files changed, 43 insertions, 18 deletions
diff --git a/src/decode.c b/src/decode.c
index 3ad93626c..637df6d66 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -49,31 +49,35 @@
#define FADE_CHUNKS 1024
-int decode_pid = 0;
+int * decode_pid = NULL;
void decodeSigHandler(int sig) {
if(sig==SIGCHLD) {
int status;
- if(decode_pid==wait3(&status,WNOHANG,NULL)) {
+ if(decode_pid && *decode_pid==wait3(&status,WNOHANG,NULL)) {
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
ERROR("decode process died from a "
"non-TERM signal: %i\n",
WTERMSIG(status));
}
- decode_pid = 0;
+ *decode_pid = 0;
}
}
else if(sig==SIGTERM) {
- int pid = decode_pid;
- if(pid>0) kill(pid,SIGTERM);
+ if(decode_pid) {
+ int pid = *decode_pid;
+ if(pid>0) kill(pid,SIGTERM);
+ }
exit(0);
}
}
void stopDecode(DecoderControl * dc) {
- if(decode_pid>0 && (dc->start || dc->state==DECODE_STATE_DECODE)) {
+ if(decode_pid && *decode_pid>0 &&
+ (dc->start || dc->state==DECODE_STATE_DECODE))
+ {
dc->stop = 1;
- while(decode_pid>0 && dc->stop) usleep(10);
+ while(decode_pid && *decode_pid>0 && dc->stop) usleep(10);
}
}
@@ -106,7 +110,7 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
Buffer * cb)
{
- while(decode_pid>0 && dc->start) usleep(10);
+ while(decode_pid && *decode_pid>0 && dc->start) usleep(10);
if(dc->start || dc->error!=DECODE_ERROR_NOERROR) {
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
@@ -135,7 +139,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
Buffer * cb)
{
- if(decode_pid>0) {
+ if(decode_pid && *decode_pid>0) {
cb->next = -1;
if(dc->state!=DECODE_STATE_DECODE || dc->error ||
strcmp(dc->file,pc->file)!=0)
@@ -147,7 +151,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
dc->error = 0;
waitOnDecode(pc,af,dc,cb);
}
- if(decode_pid>0 && dc->state==DECODE_STATE_DECODE) {
+ if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) {
dc->seekWhere = pc->seekWhere > pc->totalTime-1 ?
pc->totalTime-1 : pc->seekWhere;
dc->seekWhere = 1 > dc->seekWhere ? 1 : dc->seekWhere;
@@ -155,7 +159,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
dc->seek = 1;
pc->elapsedTime = dc->seekWhere;
pc->bitRate = 0;
- while(decode_pid>0 && dc->seek) usleep(10);
+ while(*decode_pid>0 && dc->seek) usleep(10);
}
}
pc->seek = 0;
@@ -193,9 +197,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
DecoderControl * dc) {
- decode_pid = fork();
+ decode_pid = &(pc->decode_pid);
+ *decode_pid = fork();
- if(decode_pid==0) {
+ if(*decode_pid==0) {
/* CHILD */
while(1) {
@@ -242,7 +247,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
exit(0);
/* END OF CHILD */
}
- else if(decode_pid<0) {
+ else if(*decode_pid<0) {
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
pc->error = PLAYER_ERROR_SYSTEM;
return -1;
@@ -274,7 +279,7 @@ void decode() {
dc->start = 1;
cb->next = -1;
- if(decode_pid<=0) {
+ if(decode_pid==NULL || *decode_pid<=0) {
if(decoderInit(pc,cb,af,dc)<0) return;
}
@@ -299,7 +304,7 @@ void decode() {
pc->beginTime = pc->elapsedTime;
kill(getppid(),SIGUSR1);
- while(decode_pid>0 && !cb->wrap && cb->end-cb->begin<bbp &&
+ while(*decode_pid>0 && !cb->wrap && cb->end-cb->begin<bbp &&
dc->state==DECODE_STATE_DECODE)
{
processDecodeInput();
@@ -443,7 +448,7 @@ void decode() {
}
pc->beginTime = cb->times[cb->begin];
}
- else if(decode_pid<=0 ||
+ else if(*decode_pid<=0 ||
(dc->state==DECODE_STATE_STOP && !dc->start))
{
quit = 1;
diff --git a/src/player.c b/src/player.c
index 6bc671002..e42acca18 100644
--- a/src/player.c
+++ b/src/player.c
@@ -48,6 +48,8 @@ int player_pid = 0;
int player_termSent = 0;
void resetPlayer() {
+ int pid;
+
player_pid = 0;
player_termSent = 0;
getPlayerData()->playerControl.stop = 0;
@@ -58,12 +60,17 @@ void resetPlayer() {
getPlayerData()->playerControl.state = PLAYER_STATE_STOP;
getPlayerData()->playerControl.queueState = PLAYER_QUEUE_UNLOCKED;
getPlayerData()->playerControl.seek = 0;
+ /* kill decode process if it got left running */
+ pid = getPlayerData()->playerControl.decode_pid;
+ if(pid>0) kill(pid,SIGTERM);
+ getPlayerData()->playerControl.decode_pid = 0;
}
void player_sigHandler(int signal) {
if(signal==SIGCHLD) {
int status;
- if(player_pid==wait3(&status,WNOHANG,NULL)) {
+ int pid = wait3(&status,WNOHANG,NULL);
+ if(player_pid==pid) {
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
ERROR("player process died from a "
"non-TERM signal: %i\n",
@@ -71,6 +78,17 @@ void player_sigHandler(int signal) {
}
resetPlayer();
}
+ else if(pid==getPlayerData()->playerControl.decode_pid &&
+ player_pid<=0)
+ {
+ if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
+ ERROR("(caught by master parent) "
+ "decode process died from a "
+ "non-TERM signal: %i\n",
+ WTERMSIG(status));
+ }
+ getPlayerData()->playerControl.decode_pid = 0;
+ }
}
}
diff --git a/src/player.h b/src/player.h
index a50b799c8..51f9e04ed 100644
--- a/src/player.h
+++ b/src/player.h
@@ -74,6 +74,7 @@ typedef struct _PlayerControl {
float crossFade;
mpd_sint8 softwareVolume;
double totalPlayTime;
+ int decode_pid;
} PlayerControl;
void player_sigHandler(int signal);
diff --git a/src/playerData.c b/src/playerData.c
index 4a95f1d8d..7e02bbb2f 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -107,6 +107,7 @@ void initPlayerData() {
playerData_pd->playerControl.crossFade = crossfade;
playerData_pd->playerControl.softwareVolume = 100;
playerData_pd->playerControl.totalPlayTime = 0;
+ playerData_pd->playerControl.decode_pid = 0;
playerData_pd->decoderControl.stop = 0;
playerData_pd->decoderControl.start = 0;