[PATCH v3 5/9] daemon.c: replace signal() with sigaction()
From the signal(2) man page:
The behavior of signal() varies across UNIX versions, and has also var‐
ied historically across different versions of Linux. Avoid its use:
use sigaction(2) instead.
Replaced signal() with sigaction() in daemon.c
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
daemon.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/daemon.c b/daemon.c
index eba1255..615426e 100644
--- a/daemon.c
+++ b/daemon.c
@@ -322,6 +322,7 @@ static int run_service(char *dir, struct daemon_service *service)
{
const char *path;
int enabled = service->enabled;
+ struct sigaction sa;
loginfo("Request %s for '%s'", service->name, dir);
@@ -376,7 +377,9 @@ static int run_service(char *dir, struct daemon_service *service)
* We'll ignore SIGTERM from now on, we have a
* good client.
*/
- signal(SIGTERM, SIG_IGN);
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGTERM, &sa, NULL);
return service->fn();
}
@@ -788,12 +791,16 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
static void child_handler(int signo)
{
+ struct sigaction sa;
+
/*
* Otherwise empty handler because systemcalls will get interrupted
* upon signal receipt
* SysV needs the handler to be rearmed
*/
- signal(SIGCHLD, child_handler);
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = child_handler;
+ sigaction(SIGCHLD, &sa, NULL);
}
static int set_reuse_addr(int sockfd)
@@ -996,6 +1003,7 @@ static int service_loop(struct socketlist *socklist)
{
struct pollfd *pfd;
int i;
+ struct sigaction sa;
pfd = xcalloc(socklist->nr, sizeof(struct pollfd));
@@ -1004,7 +1012,9 @@ static int service_loop(struct socketlist *socklist)
pfd[i].events = POLLIN;
}
- signal(SIGCHLD, child_handler);
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = child_handler;
+ sigaction(SIGCHLD, &sa, NULL);
for (;;) {
int i;
--
2.0.0.8.g7bf6e1f.dirty