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
This commit is contained in:
parent
00c25b772e
commit
acf0e147c2
@ -31,6 +31,7 @@
|
||||
#include "volume.h"
|
||||
#include "mpd_types.h"
|
||||
#include "sig_handlers.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
@ -101,6 +102,10 @@ Directory * getDirectory(char * name);
|
||||
Song * getSongDetails(char * file, char ** shortnameRet,
|
||||
Directory ** directoryRet);
|
||||
|
||||
void clearUpdatePid() {
|
||||
directory_updatePid = 0;
|
||||
}
|
||||
|
||||
int isUpdatingDB() {
|
||||
if(directory_updatePid>0 || directory_reReadDB) {
|
||||
return directory_updateJobId;
|
||||
@ -120,7 +125,7 @@ void directory_sigChldHandler(int pid, int status) {
|
||||
"updated db succesffully\n");
|
||||
directory_reReadDB = 1;
|
||||
}
|
||||
directory_updatePid = 0;
|
||||
clearUpdatePid();
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,8 +149,10 @@ int updateInit(FILE * fp, List * pathList) {
|
||||
blockSignals();
|
||||
directory_updatePid = fork();
|
||||
if(directory_updatePid==0) {
|
||||
unblockSignals();
|
||||
/* child */
|
||||
clearPlayerPid();
|
||||
|
||||
unblockSignals();
|
||||
|
||||
finishSigHandlers();
|
||||
close(listenSocket);
|
||||
|
@ -31,6 +31,8 @@ extern char directorydb[MAXPATHLEN+1];
|
||||
|
||||
void readDirectoryDBIfUpdateIsFinished();
|
||||
|
||||
void clearUpdatePid();
|
||||
|
||||
int isUpdatingDB();
|
||||
|
||||
void directory_sigChldHandler(int pid, int status);
|
||||
|
18
src/player.c
18
src/player.c
@ -46,13 +46,15 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
volatile int player_pid = 0;
|
||||
volatile int player_termSent = 0;
|
||||
|
||||
void clearPlayerPid() {
|
||||
player_pid = 0;
|
||||
}
|
||||
|
||||
void resetPlayer() {
|
||||
int pid;
|
||||
|
||||
player_pid = 0;
|
||||
player_termSent = 0;
|
||||
clearPlayerPid();
|
||||
getPlayerData()->playerControl.stop = 0;
|
||||
getPlayerData()->playerControl.play = 0;
|
||||
getPlayerData()->playerControl.pause = 0;
|
||||
@ -97,6 +99,8 @@ int playerInit() {
|
||||
PlayerControl * pc = &(getPlayerData()->playerControl);
|
||||
struct sigaction sa;
|
||||
|
||||
clearUpdatePid();
|
||||
|
||||
unblockSignals();
|
||||
|
||||
sa.sa_flags = 0;
|
||||
@ -104,11 +108,11 @@ int playerInit() {
|
||||
|
||||
finishSigHandlers();
|
||||
sa.sa_handler = decodeSigHandler;
|
||||
sigaction(SIGCHLD,&sa,NULL);
|
||||
sigaction(SIGTERM,&sa,NULL);
|
||||
sigaction(SIGINT,&sa,NULL);
|
||||
while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
|
||||
while(sigaction(SIGTERM,&sa,NULL)<0 && errno==EINTR);
|
||||
while(sigaction(SIGINT,&sa,NULL)<0 && errno==EINTR);
|
||||
|
||||
close(listenSocket);
|
||||
while(close(listenSocket)<0 && errno==EINTR);
|
||||
freeAllInterfaces();
|
||||
closeMp3Directory();
|
||||
finishPlaylist();
|
||||
|
@ -79,6 +79,8 @@ typedef struct _PlayerControl {
|
||||
volatile int decode_pid;
|
||||
} PlayerControl;
|
||||
|
||||
void clearPlayerPid();
|
||||
|
||||
void player_sigChldHandler(int pid, int status);
|
||||
|
||||
int playerPlay(FILE * fp, char * utf8file);
|
||||
|
@ -67,9 +67,9 @@ void initSigHandlers() {
|
||||
sa.sa_flags = 0;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE,&sa,NULL);
|
||||
while(sigaction(SIGPIPE,&sa,NULL)<0 && errno==EINTR);
|
||||
sa.sa_handler = chldSigHandler;
|
||||
sigaction(SIGCHLD,&sa,NULL);
|
||||
while(sigaction(SIGCHLD,&sa,NULL)<0 && errno==EINTR);
|
||||
signal_handle(SIGUSR1);
|
||||
signal_handle(SIGINT);
|
||||
signal_handle(SIGTERM);
|
||||
@ -90,7 +90,7 @@ void blockSignals() {
|
||||
sigaddset(&sset,SIGCHLD);
|
||||
sigaddset(&sset,SIGUSR1);
|
||||
sigaddset(&sset,SIGHUP);
|
||||
sigprocmask(SIG_BLOCK,&sset,NULL);
|
||||
while(sigprocmask(SIG_BLOCK,&sset,NULL)<0 && errno==EINTR);
|
||||
}
|
||||
|
||||
void unblockSignals() {
|
||||
@ -100,5 +100,5 @@ void unblockSignals() {
|
||||
sigaddset(&sset,SIGCHLD);
|
||||
sigaddset(&sset,SIGUSR1);
|
||||
sigaddset(&sset,SIGHUP);
|
||||
sigprocmask(SIG_UNBLOCK,&sset,NULL);
|
||||
while(sigprocmask(SIG_UNBLOCK,&sset,NULL)<0 && errno==EINTR);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "signal_check.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
volatile sig_atomic_t __caught_signals[NSIG];
|
||||
|
||||
static void __signal_handler(int sig)
|
||||
@ -12,7 +14,7 @@ static void __set_signal_handler(int sig, void (* handler)(int))
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
sigaction(sig, &act, 0);
|
||||
while(sigaction(sig, &act, 0) && errno==EINTR);
|
||||
}
|
||||
|
||||
void signal_handle(int sig)
|
||||
|
Loading…
Reference in New Issue
Block a user