summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-21 00:42:33 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-09-21 00:42:33 (GMT)
commit71288f0b3194055e2300667e5a2bc2b75eb83e04 (patch)
tree32fe43d7dd3cd32d1d34ff01507268e902288e78
parent1bb82e686f2aa870e7ee2118fe9e387a7f9c6b99 (diff)
fixed exit code after signal
-rw-r--r--src/dropnroll.c16
-rw-r--r--src/sig_handler.c21
2 files changed, 18 insertions, 19 deletions
diff --git a/src/dropnroll.c b/src/dropnroll.c
index 24b22af..a3bd97f 100644
--- a/src/dropnroll.c
+++ b/src/dropnroll.c
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <signal.h>
enum cmd_id_enum { ADD, REMOVE, STATUS, LOG, LISTEN };
typedef enum cmd_id_enum cmd_id_t;
@@ -414,10 +415,9 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
}
if(FD_ISSET(sig_fd, &tmpfds)) {
- if(signal_handle()) {
- return_value = 1;
+ return_value = signal_handle();
+ if(return_value == SIGINT || return_value == SIGQUIT || return_value == SIGTERM);
break;
- }
}
if(FD_ISSET(inotify_fd, &tmpfds)) {
@@ -584,17 +584,21 @@ int main(int argc, char* argv[])
ret = main_loop(cmd_listen_fd, inotify_fd, &opt);
- close(cmd_listen_fd);
+ if(cmd_listen_fd > 0)
+ close(cmd_listen_fd);
close(inotify_fd);
+ options_clear(&opt);
if(!ret)
log_printf(NOTICE, "normal shutdown");
else if(ret < 0)
log_printf(NOTICE, "shutdown after error");
- else
+ else {
log_printf(NOTICE, "shutdown after signal");
+ log_close();
+ kill(getpid(), ret);
+ }
- options_clear(&opt);
log_close();
return ret;
diff --git a/src/sig_handler.c b/src/sig_handler.c
index 7287320..1733742 100644
--- a/src/sig_handler.c
+++ b/src/sig_handler.c
@@ -22,21 +22,16 @@
#include "datatypes.h"
#include "log.h"
+#include "sig_handler.h"
+
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
-#include <sys/select.h>
#include <errno.h>
#include <string.h>
-#include "sig_handler.h"
-
-#include <stdio.h>
-
-
static int sig_pipe_fds[2];
-
static void sig_handler(int sig)
{
sigset_t set;
@@ -115,12 +110,12 @@ int signal_handle()
for(sig=1; sig < NSIG; ++sig) {
if(sigismember(&set, sig)) {
switch(sig) {
- case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); return_value = 1; break;
- case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); return_value = 1; break;
- case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); return_value = 1; break;
- case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); break;
- case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); break;
- case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); break;
+ case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); return_value = SIGINT; break;
+ case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); return_value = SIGQUIT; break;
+ case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); return_value = SIGTERM; break;
+ case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); return_value = SIGHUP; break;
+ case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); return_value = SIGUSR1; break;
+ case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); return_value = SIGUSR2; break;
default: log_printf(WARNING, "unknown signal %d caught, ignoring", sig); break;
}
sigdelset(&set, sig);