relay: use sigaction iso signal to set SA_RESTART
Avoid IO operations to fail with EINTR to simplify some code.
@@ -381,6 +381,8 @@ main(int argc, char * const argv[])
{
char id;
int ch;
+ struct sigaction sigact;
+ sigset_t sigmask;
size_t numaggregators;
char *allowed_chars = NULL;
char *pidfile = NULL;
@@ -676,7 +678,7 @@ main(int argc, char * const argv[])
} else {
fds[0] = fds[1] = -1;
}
-#define exit_err(...) \
+#define exit_err(...) { \
if (fds[0] != -1) { \
char msg[1024]; \
snprintf(msg, sizeof(msg), __VA_ARGS__); \
@@ -686,8 +688,9 @@ main(int argc, char * const argv[])
} else { \
logerr(__VA_ARGS__); \
exit(1); \
+ } \
}
-#define exit_ok \
+#define exit_ok { \
if (fds[0] != -1) { \
/* we're fine, flag our grandparent (= the original
* process being called) it can terminate */ \
@@ -697,7 +700,8 @@ main(int argc, char * const argv[])
close(fds[1]); \
} \
fds[0] = fds[1] = -1; \
- startup_success = 1;
+ startup_success = 1; \
+}
if (pidfile_handle) {
fprintf(pidfile_handle, "%zu\n", (ssize_t)getpid());
@@ -790,21 +794,29 @@ main(int argc, char * const argv[])
exit(0);
}
- if (signal(SIGINT, sig_handler) == SIG_ERR) {
+ sigemptyset(&sigmask);
+ sigaddset(&sigmask, SIGINT);
+ sigaddset(&sigmask, SIGTERM);
+ sigaddset(&sigmask, SIGQUIT);
+ sigaddset(&sigmask, SIGHUP);
+ sigact.sa_handler = sig_handler;
+ sigact.sa_mask = sigmask;
+ sigact.sa_flags = SA_RESTART;
+ if (sigaction(SIGINT, &sigact, NULL) < 0)
exit_err("failed to create SIGINT handler: %s\n", strerror(errno));
- }
- if (signal(SIGTERM, sig_handler) == SIG_ERR) {
+ if (sigaction(SIGTERM, &sigact, NULL) < 0)
exit_err("failed to create SIGTERM handler: %s\n", strerror(errno));
- }
- if (signal(SIGQUIT, sig_handler) == SIG_ERR) {
+ if (sigaction(SIGQUIT, &sigact, NULL) < 0)
exit_err("failed to create SIGQUIT handler: %s\n", strerror(errno));
- }
- if (signal(SIGHUP, sig_handler) == SIG_ERR) {
+ if (sigaction(SIGHUP, &sigact, NULL) < 0)
exit_err("failed to create SIGHUP handler: %s\n", strerror(errno));
- }
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
+ sigact.sa_handler = SIG_IGN;
+ if (sigaction(SIGPIPE, &sigact, NULL) < 0)
exit_err("failed to ignore SIGPIPE: %s\n", strerror(errno));
- }
+ if (sigaction(SIGUSR1, &sigact, NULL) < 0)
+ exit_err("failed to ignore SIGUSR1: %s\n", strerror(errno));
+ if (sigaction(SIGUSR2, &sigact, NULL) < 0)
+ exit_err("failed to ignore SIGUSR2: %s\n", strerror(errno));
workers = malloc(sizeof(dispatcher *) *
(1/*lsnr*/ + workercnt + 1/*sentinel*/));
