mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-27 06:33:21 -05:00
Starting to fix signal stuff
This commit is contained in:
parent
855cfe5d00
commit
2dee0cebd4
@ -33,6 +33,7 @@ typedef struct tag_stats {
|
||||
typedef struct tag_config {
|
||||
int use_mdns;
|
||||
int stop;
|
||||
int reload;
|
||||
char *configfile;
|
||||
char *web_root;
|
||||
int port;
|
||||
|
85
src/main.c
85
src/main.c
@ -432,6 +432,74 @@ int drop_privs(char *user) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* signal_handler
|
||||
*
|
||||
* This thread merely spins waiting for signals
|
||||
*/
|
||||
void *signal_handler(void *arg) {
|
||||
int error;
|
||||
sigset_t intmask;
|
||||
int sig;
|
||||
|
||||
config.stop=0;
|
||||
config.reload=0;
|
||||
|
||||
DPRINTF(ERR_WARN,"Signal handler started\n");
|
||||
|
||||
while(!config.stop) {
|
||||
if((sigemptyset(&intmask) == -1) ||
|
||||
(sigaddset(&intmask, SIGINT) == -1) ||
|
||||
(sigaddset(&intmask, SIGHUP) == -1) ||
|
||||
(sigwait(&intmask, &sig) == -1)) {
|
||||
DPRINTF(ERR_FATAL,"Error waiting for signals. Aborting\n");
|
||||
} else {
|
||||
/* process the signal */
|
||||
switch(sig) {
|
||||
case SIGINT:
|
||||
DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n");
|
||||
config.stop=1;
|
||||
return NULL;
|
||||
break;
|
||||
case SIGHUP:
|
||||
DPRINTF(ERR_LOG,"Got HUP signal. Notifying daap server.\n");
|
||||
config.reload=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* start_signal_handler
|
||||
*
|
||||
* Block signals and set up the signal handler
|
||||
*/
|
||||
int start_signal_handler(void) {
|
||||
int error;
|
||||
sigset_t set;
|
||||
pthread_t handler_tid;
|
||||
|
||||
if((sigemptyset(&set) == -1) ||
|
||||
(sigaddset(&set,SIGINT) == -1) ||
|
||||
(sigaddset(&set,SIGHUP) == -1) ||
|
||||
(sigprocmask(SIG_BLOCK, &set, NULL) == -1)) {
|
||||
DPRINTF(ERR_LOG,"Error setting signal set\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(error=pthread_create(&handler_tid, NULL, signal_handler, NULL)) {
|
||||
errno=error;
|
||||
DPRINTF(ERR_LOG,"Error creating signal_handler thread\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_detach(handler_tid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int option;
|
||||
char *configfile=DEFAULT_CONFIGFILE;
|
||||
@ -491,9 +559,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/* block signals and set up the signal handling thread */
|
||||
|
||||
|
||||
|
||||
if((config.use_mdns) && (!parseonly)) {
|
||||
DPRINTF(ERR_LOG,"Starting rendezvous daemon\n");
|
||||
@ -502,7 +567,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(db_open(config.dbdir)) {
|
||||
DPRINTF(ERR_FATAL,"Error in db_open: %s\n",strerror(errno));
|
||||
}
|
||||
@ -512,6 +576,12 @@ int main(int argc, char *argv[]) {
|
||||
DPRINTF(ERR_FATAL,"Error in drop_privs: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
/* block signals and set up the signal handling thread */
|
||||
DPRINTF(ERR_LOG,"Starting signal handler\n");
|
||||
if(start_signal_handler()) {
|
||||
DPRINTF(ERR_FATAL,"Error starting signal handler %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
DPRINTF(ERR_LOG,"Loading playlists\n");
|
||||
|
||||
if(config.playlist)
|
||||
@ -574,8 +644,13 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
config.stop=0;
|
||||
|
||||
while(!config.stop)
|
||||
while(!config.stop) {
|
||||
if(config.reload) {
|
||||
config.reload=0;
|
||||
DPRINTF(ERR_LOG,"Reloading configuration\n");
|
||||
}
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
DPRINTF(ERR_LOG,"Stopping gracefully\n");
|
||||
|
||||
|
@ -318,6 +318,11 @@ int scan_path(char *path) {
|
||||
}
|
||||
|
||||
while(1) {
|
||||
if(config.stop) {
|
||||
DPRINTF(ERR_WARN,"Stop detected. Aborting scan of %s.\n",path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pde=(struct dirent *)&de;
|
||||
|
||||
err=readdir_r(current_dir,(struct dirent *)de,&pde);
|
||||
|
@ -89,6 +89,9 @@
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.18 2004/04/19 06:19:46 rpedde
|
||||
Starting to fix signal stuff
|
||||
|
||||
Revision 1.17 2004/03/29 19:44:58 rpedde
|
||||
Move mdns stuff out of mdns subdir to help compile on older automakes
|
||||
|
||||
@ -437,6 +440,7 @@ int rend_private_init(char *user) {
|
||||
|
||||
signal(SIGINT, HandleSigInt); // SIGINT is what you get for a Ctrl-C
|
||||
signal(SIGQUIT, HandleSigQuit); // SIGQUIT is what you get for a Ctrl-\ (indeed)
|
||||
signal(SIGHUP, SIG_IGN); // SIGHUP might happen from a request to reload the daap server
|
||||
|
||||
while (!gStopNow) {
|
||||
int nfds = 1;
|
||||
|
@ -98,6 +98,7 @@ int rend_running(void) {
|
||||
int result;
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Status inquiry\n");
|
||||
memset((void*)&msg,0x00,sizeof(msg));
|
||||
msg.cmd=REND_MSG_TYPE_STATUS;
|
||||
result=rend_send_message(&msg);
|
||||
DPRINTF(ERR_DEBUG,"Returning status %d\n",result);
|
||||
|
Loading…
x
Reference in New Issue
Block a user