mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-26 06:03:20 -05:00
Fix signal handling on linuxthreads/NSLU2
This commit is contained in:
parent
c9e70fb47f
commit
55014d0a71
@ -360,40 +360,43 @@ int os_drop_privs(char *user) {
|
|||||||
*/
|
*/
|
||||||
void os_wait(int seconds) {
|
void os_wait(int seconds) {
|
||||||
sigset_t intmask;
|
sigset_t intmask;
|
||||||
int sig;
|
|
||||||
int status;
|
int status;
|
||||||
int done=0;
|
struct sigaction sa_ign;
|
||||||
|
struct sigaction sa_dfl;
|
||||||
sleep(seconds);
|
sleep(seconds);
|
||||||
|
|
||||||
while(!done) {
|
sigpending(&intmask);
|
||||||
if(!sigpending(&intmask)) {
|
|
||||||
if(sigismember(&intmask, SIGCLD) ||
|
sa_ign.sa_handler=SIG_IGN;
|
||||||
sigismember(&intmask, SIGINT) ||
|
sa_ign.sa_flags=0;
|
||||||
sigismember(&intmask, SIGHUP) ||
|
sigemptyset(&sa_ign.sa_mask);
|
||||||
sigismember(&intmask, SIGTERM)) {
|
|
||||||
/* do a sigwait for it */
|
sa_dfl.sa_handler=SIG_DFL;
|
||||||
if((sigemptyset(&intmask) == -1) ||
|
sa_dfl.sa_flags=0;
|
||||||
(sigaddset(&intmask, SIGCLD) == -1) ||
|
sigemptyset(&sa_dfl.sa_mask);
|
||||||
(sigaddset(&intmask, SIGINT) == -1) ||
|
|
||||||
(sigaddset(&intmask, SIGHUP) == -1) ||
|
|
||||||
(sigaddset(&intmask, SIGTERM) == -1) ||
|
if(sigismember(&intmask, SIGCLD)) {
|
||||||
(sigwait(&intmask, &sig) == -1)) {
|
|
||||||
DPRINTF(E_FATAL,L_MAIN,"Error waiting for signals.");
|
|
||||||
} else {
|
|
||||||
/* process the signal */
|
|
||||||
switch(sig) {
|
|
||||||
case SIGCLD:
|
|
||||||
DPRINTF(E_LOG,L_MAIN,"Got CLD signal. Reaping\n");
|
DPRINTF(E_LOG,L_MAIN,"Got CLD signal. Reaping\n");
|
||||||
while (wait3(&status, WNOHANG, NULL) > 0) {};
|
while (wait3(&status, WNOHANG, NULL) > 0) {};
|
||||||
break;
|
|
||||||
case SIGTERM:
|
sigaction(SIGCLD,&sa_ign,NULL);
|
||||||
case SIGINT:
|
sigaction(SIGCLD,&sa_dfl,NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((sigismember(&intmask, SIGTERM)) ||
|
||||||
|
(sigismember(&intmask, SIGINT))) {
|
||||||
DPRINTF(E_LOG,L_MAIN,"Got shutdown signal.\n");
|
DPRINTF(E_LOG,L_MAIN,"Got shutdown signal.\n");
|
||||||
config.stop=1;
|
config.stop=1;
|
||||||
return;
|
|
||||||
break;
|
sigaction(SIGTERM,&sa_ign,NULL);
|
||||||
case SIGHUP:
|
sigaction(SIGTERM,&sa_dfl,NULL);
|
||||||
|
|
||||||
|
sigaction(SIGINT,&sa_ign,NULL);
|
||||||
|
sigaction(SIGINT,&sa_dfl,NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sigismember(&intmask, SIGHUP)) {
|
||||||
DPRINTF(E_LOG,L_MAIN,"Got HUP signal.\n");
|
DPRINTF(E_LOG,L_MAIN,"Got HUP signal.\n");
|
||||||
/* if we can't reload, it keeps the old config file,
|
/* if we can't reload, it keeps the old config file,
|
||||||
* so no real damage */
|
* so no real damage */
|
||||||
@ -401,21 +404,11 @@ void os_wait(int seconds) {
|
|||||||
err_reopen();
|
err_reopen();
|
||||||
|
|
||||||
config.reload=1;
|
config.reload=1;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DPRINTF(E_LOG,L_MAIN,"What am I doing here?\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
done=1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DPRINTF(E_FATAL,L_MAIN,"Error in sigpending\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
sigaction(SIGHUP,&sa_ign,NULL);
|
||||||
|
sigaction(SIGHUP,&sa_dfl,NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for signals and flag the main process. This is
|
* Wait for signals and flag the main process. This is
|
||||||
@ -436,19 +429,6 @@ void os_wait(int seconds) {
|
|||||||
*/
|
*/
|
||||||
int _os_start_signal_handler(void) {
|
int _os_start_signal_handler(void) {
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
struct sigaction action;
|
|
||||||
|
|
||||||
action.sa_handler = SIG_IGN;
|
|
||||||
sigemptyset(&action.sa_mask);
|
|
||||||
action.sa_flags=0;
|
|
||||||
|
|
||||||
if((sigaction(SIGTERM,&action,NULL) == -1) ||
|
|
||||||
(sigaction(SIGHUP,&action,NULL) == -1) ||
|
|
||||||
(sigaction(SIGCLD,&action,NULL) == -1) ||
|
|
||||||
(sigaction(SIGINT,&action,NULL) ==-1)) {
|
|
||||||
DPRINTF(E_LOG,L_MAIN,"Error ignoring signals\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((sigemptyset(&set) == -1) ||
|
if((sigemptyset(&set) == -1) ||
|
||||||
(sigaddset(&set,SIGINT) == -1) ||
|
(sigaddset(&set,SIGINT) == -1) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user