aboutsummaryrefslogtreecommitdiffstats
path: root/src/sig_handlers.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-11 23:07:43 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-11 23:07:43 +0000
commitae33b348afa800447db9344cf6e5d082f1a1fcb3 (patch)
tree6e0977b81c8f9413a5513d27bd3a53cccabcf950 /src/sig_handlers.c
parent063affb04775fcf59e92df0bf70f0ecec0edf4ed (diff)
downloadmpd-ae33b348afa800447db9344cf6e5d082f1a1fcb3.tar.gz
mpd-ae33b348afa800447db9344cf6e5d082f1a1fcb3.tar.xz
mpd-ae33b348afa800447db9344cf6e5d082f1a1fcb3.zip
clean up signal handling using a polling method, from the genius that is mackstann
git-svn-id: https://svn.musicpd.org/mpd/trunk@697 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/sig_handlers.c')
-rw-r--r--src/sig_handlers.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/src/sig_handlers.c b/src/sig_handlers.c
index ed6fb4631..1dc1f428b 100644
--- a/src/sig_handlers.c
+++ b/src/sig_handlers.c
@@ -20,35 +20,41 @@
#include "player.h"
#include "playlist.h"
#include "directory.h"
+#include "command.h"
+#include "signal_check.h"
+#include "log.h"
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
-
-struct sigaction original_termSa;
-struct sigaction original_hupSa;
-
-void termSigHandler(int signal) {
- if(signal==SIGTERM) {
- savePlaylistState();
- playerKill();
- exit(EXIT_SUCCESS);
+#include <errno.h>
+
+int handlePendingSignals() {
+ if(signal_is_pending(SIGINT) || signal_is_pending(SIGTERM)) {
+ DEBUG("got SIGINT or SIGTERM, exiting\n");
+ return COMMAND_RETURN_KILL;
+ }
+
+ if(signal_is_pending(SIGHUP)) {
+ DEBUG("got SIGHUP, rereading DB\n");
+ signal_clear(SIGHUP);
+ readDirectoryDB();
}
-}
-
-void usr1SigHandler(int signal) {
-}
-void hupSigHandler(int signal) {
- readDirectoryDB();
+ return 0;
}
void chldSigHandler(int signal) {
int status;
int pid;
- while((pid = wait3(&status,WNOHANG,NULL)) > 0) {
+ DEBUG("got SIGCHLD\n");
+ while(0 != (pid = wait3(&status,WNOHANG,NULL))) {
+ if(pid<0) {
+ if(errno==EINTR) continue;
+ else break;
+ }
player_sigChldHandler(pid,status);
directory_sigChldHandler(pid,status);
}
@@ -61,19 +67,19 @@ void initSigHandlers() {
sigemptyset(&sa.sa_mask);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE,&sa,NULL);
- sa.sa_handler = usr1SigHandler;
- sigaction(SIGUSR1,&sa,NULL);
sa.sa_handler = chldSigHandler;
sigaction(SIGCHLD,&sa,NULL);
- sa.sa_handler = hupSigHandler;
- sigaction(SIGHUP,&sa,&original_hupSa);
- sa.sa_handler = termSigHandler;
- sigaction(SIGTERM,&sa,&original_termSa);
+ signal_handle(SIGUSR1);
+ signal_handle(SIGINT);
+ signal_handle(SIGTERM);
+ signal_handle(SIGHUP);
}
void finishSigHandlers() {
- sigaction(SIGHUP,&original_termSa,NULL);
- sigaction(SIGTERM,&original_termSa,NULL);
+ signal_unhandle(SIGINT);
+ signal_unhandle(SIGUSR1);
+ signal_unhandle(SIGTERM);
+ signal_unhandle(SIGHUP);
}
void blockSignals() {
@@ -95,21 +101,3 @@ void unblockSignals() {
sigaddset(&sset,SIGHUP);
sigprocmask(SIG_UNBLOCK,&sset,NULL);
}
-
-void blockTermSignal() {
- sigset_t sset;
-
- sigemptyset(&sset);
- sigaddset(&sset,SIGTERM);
- sigaddset(&sset,SIGHUP);
- sigprocmask(SIG_BLOCK,&sset,NULL);
-}
-
-void unblockTermSignal() {
- sigset_t sset;
-
- sigemptyset(&sset);
- sigaddset(&sset,SIGTERM);
- sigaddset(&sset,SIGHUP);
- sigprocmask(SIG_UNBLOCK,&sset,NULL);
-}