Commit acf0e147 authored by Warren Dukes's avatar Warren Dukes

when doing signal functions (like sigaction) make sure it wasn't interrupted by…

when doing signal functions (like sigaction) make sure it wasn't interrupted by a signal (errno==EINTR) git-svn-id: https://svn.musicpd.org/mpd/trunk@729 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 00c25b77
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "volume.h" #include "volume.h"
#include "mpd_types.h" #include "mpd_types.h"
#include "sig_handlers.h" #include "sig_handlers.h"
#include "player.h"
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -101,6 +102,10 @@ Directory * getDirectory(char * name); ...@@ -101,6 +102,10 @@ Directory * getDirectory(char * name);
Song * getSongDetails(char * file, char ** shortnameRet, Song * getSongDetails(char * file, char ** shortnameRet,
Directory ** directoryRet); Directory ** directoryRet);
void clearUpdatePid() {
directory_updatePid = 0;
}
int isUpdatingDB() { int isUpdatingDB() {
if(directory_updatePid>0 || directory_reReadDB) { if(directory_updatePid>0 || directory_reReadDB) {
return directory_updateJobId; return directory_updateJobId;
...@@ -120,7 +125,7 @@ void directory_sigChldHandler(int pid, int status) { ...@@ -120,7 +125,7 @@ void directory_sigChldHandler(int pid, int status) {
"updated db succesffully\n"); "updated db succesffully\n");
directory_reReadDB = 1; directory_reReadDB = 1;
} }
directory_updatePid = 0; clearUpdatePid();
} }
} }
...@@ -144,8 +149,10 @@ int updateInit(FILE * fp, List * pathList) { ...@@ -144,8 +149,10 @@ int updateInit(FILE * fp, List * pathList) {
blockSignals(); blockSignals();
directory_updatePid = fork(); directory_updatePid = fork();
if(directory_updatePid==0) { if(directory_updatePid==0) {
unblockSignals();
/* child */ /* child */
clearPlayerPid();
unblockSignals();
finishSigHandlers(); finishSigHandlers();
close(listenSocket); close(listenSocket);
......
...@@ -31,6 +31,8 @@ extern char directorydb[MAXPATHLEN+1]; ...@@ -31,6 +31,8 @@ extern char directorydb[MAXPATHLEN+1];
void readDirectoryDBIfUpdateIsFinished(); void readDirectoryDBIfUpdateIsFinished();
void clearUpdatePid();
int isUpdatingDB(); int isUpdatingDB();
void directory_sigChldHandler(int pid, int status); void directory_sigChldHandler(int pid, int status);
......
...@@ -46,13 +46,15 @@ ...@@ -46,13 +46,15 @@
#include <fcntl.h> #include <fcntl.h>
volatile int player_pid = 0; volatile int player_pid = 0;
volatile int player_termSent = 0;
void clearPlayerPid() {
player_pid = 0;
}
void resetPlayer() { void resetPlayer() {
int pid; int pid;
player_pid = 0; clearPlayerPid();
player_termSent = 0;
getPlayerData()->playerControl.stop = 0; getPlayerData()->playerControl.stop = 0;
getPlayerData()->playerControl.play = 0; getPlayerData()->playerControl.play = 0;
getPlayerData()->playerControl.pause = 0; getPlayerData()->playerControl.pause = 0;
...@@ -97,6 +99,8 @@ int playerInit() { ...@@ -97,6 +99,8 @@ int playerInit() {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
struct sigaction sa; struct sigaction sa;
clearUpdatePid();
unblockSignals(); unblockSignals();
sa.sa_flags = 0; sa.sa_flags = 0;
...@@ -104,11 +108,11 @@ int playerInit() { ...@@ -104,11 +108,11 @@ int playerInit() {
finishSigHandlers(); finishSigHandlers();
sa.sa_handler = decodeSigHandler; sa.sa_handler = decodeSigHandler;
sigaction(SIGCHLD,&sa,NULL); while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
sigaction(SIGTERM,&sa,NULL); while(sigaction(SIGTERM,&sa,NULL)<0 && errno==EINTR);
sigaction(SIGINT,&sa,NULL); while(sigaction(SIGINT,&sa,NULL)<0 && errno==EINTR);
close(listenSocket); while(close(listenSocket)<0 && errno==EINTR);
freeAllInterfaces(); freeAllInterfaces();
closeMp3Directory(); closeMp3Directory();
finishPlaylist(); finishPlaylist();
......
...@@ -79,6 +79,8 @@ typedef struct _PlayerControl { ...@@ -79,6 +79,8 @@ typedef struct _PlayerControl {
volatile int decode_pid; volatile int decode_pid;
} PlayerControl; } PlayerControl;
void clearPlayerPid();
void player_sigChldHandler(int pid, int status); void player_sigChldHandler(int pid, int status);
int playerPlay(FILE * fp, char * utf8file); int playerPlay(FILE * fp, char * utf8file);
......
...@@ -67,9 +67,9 @@ void initSigHandlers() { ...@@ -67,9 +67,9 @@ void initSigHandlers() {
sa.sa_flags = 0; sa.sa_flags = 0;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE,&sa,NULL); while(sigaction(SIGPIPE,&sa,NULL)<0 && errno==EINTR);
sa.sa_handler = chldSigHandler; sa.sa_handler = chldSigHandler;
sigaction(SIGCHLD,&sa,NULL); while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
signal_handle(SIGUSR1); signal_handle(SIGUSR1);
signal_handle(SIGINT); signal_handle(SIGINT);
signal_handle(SIGTERM); signal_handle(SIGTERM);
...@@ -90,7 +90,7 @@ void blockSignals() { ...@@ -90,7 +90,7 @@ void blockSignals() {
sigaddset(&sset,SIGCHLD); sigaddset(&sset,SIGCHLD);
sigaddset(&sset,SIGUSR1); sigaddset(&sset,SIGUSR1);
sigaddset(&sset,SIGHUP); sigaddset(&sset,SIGHUP);
sigprocmask(SIG_BLOCK,&sset,NULL); while(sigprocmask(SIG_BLOCK,&sset,NULL)<0 && errno==EINTR);
} }
void unblockSignals() { void unblockSignals() {
...@@ -100,5 +100,5 @@ void unblockSignals() { ...@@ -100,5 +100,5 @@ void unblockSignals() {
sigaddset(&sset,SIGCHLD); sigaddset(&sset,SIGCHLD);
sigaddset(&sset,SIGUSR1); sigaddset(&sset,SIGUSR1);
sigaddset(&sset,SIGHUP); sigaddset(&sset,SIGHUP);
sigprocmask(SIG_UNBLOCK,&sset,NULL); while(sigprocmask(SIG_UNBLOCK,&sset,NULL)<0 && errno==EINTR);
} }
#include "signal_check.h" #include "signal_check.h"
#include <errno.h>
volatile sig_atomic_t __caught_signals[NSIG]; volatile sig_atomic_t __caught_signals[NSIG];
static void __signal_handler(int sig) static void __signal_handler(int sig)
...@@ -12,7 +14,7 @@ static void __set_signal_handler(int sig, void (* handler)(int)) ...@@ -12,7 +14,7 @@ static void __set_signal_handler(int sig, void (* handler)(int))
struct sigaction act; struct sigaction act;
act.sa_flags = 0; act.sa_flags = 0;
act.sa_handler = handler; act.sa_handler = handler;
sigaction(sig, &act, 0); while(sigaction(sig, &act, 0) && errno==EINTR);
} }
void signal_handle(int sig) void signal_handle(int sig)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment