summaryrefslogtreecommitdiff
path: root/nfcommander.c
diff options
context:
space:
mode:
Diffstat (limited to 'nfcommander.c')
-rw-r--r--nfcommander.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/nfcommander.c b/nfcommander.c
index 50cbda7..66838aa 100644
--- a/nfcommander.c
+++ b/nfcommander.c
@@ -2,6 +2,7 @@
#include <signal.h>
#include <sys/epoll.h>
#include <unistd.h>
+#include <errno.h>
#include "nfcommander.h"
#include "config.h"
@@ -18,10 +19,16 @@ typedef union {
} epoll_private_t;
static volatile sig_atomic_t shutdown_requested = 0;
+static volatile sig_atomic_t pid_signaled = 0;
static int epoll_fd = -1;
static void signal_handler(int signum){
- shutdown_requested = 1;
+ if(signum == SIGCHLD){
+ pid_signaled = 1;
+ }
+ else {
+ shutdown_requested = 1;
+ }
}
static int usage(char* fn){
@@ -47,7 +54,7 @@ int core_manage_fd(int fd, int manage, notification_target_t system){
}
if(epoll_ctl(epoll_fd, manage ? EPOLL_CTL_ADD : EPOLL_CTL_DEL, fd, &event)){
- fprintf(stderr, "Failed to modify epoll instance\n");
+ perror("core/epoll_mod");
shutdown_requested = 1;
return 1;
}
@@ -67,7 +74,7 @@ int main(int argc, char** argv){
struct epoll_event events[10];
epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if(epoll_fd < 0){
- printf("Failed to create epoll instance\n");
+ perror("core/epoll");
return EXIT_FAILURE;
}
@@ -93,12 +100,14 @@ int main(int argc, char** argv){
//handle signals
signal(SIGINT, signal_handler);
+ signal(SIGCHLD, signal_handler);
signal(SIGPIPE, SIG_IGN);
//handle events
while(!shutdown_requested){
event_count = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(struct epoll_event), 1000);
if(event_count < 0){
+ perror("core/poll");
break;
}
@@ -120,6 +129,11 @@ int main(int argc, char** argv){
break;
}
}
+
+ if(pid_signaled){
+ pid_signaled = 0;
+ command_reap();
+ }
}
//clean up