exit(EXIT_FAILURE);
}
+static int catch_signal(int sig)
+{
+ struct sigaction act;
+
+ act.sa_handler = signal_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ return sigaction(sig, &act, NULL);
+}
+
static int init_signals(void)
{
- if (signal(SIGINT, &signal_handler) == SIG_ERR)
- return -E_SIGNAL_SIG_ERR;
- if (signal(SIGTERM, &signal_handler) == SIG_ERR)
- return -E_SIGNAL_SIG_ERR;
- if (signal(SIGPIPE, &signal_handler) == SIG_ERR)
- return -E_SIGNAL_SIG_ERR;
+ if (catch_signal(SIGINT) < 0)
+ return -E_SIGACTION;
+ if (catch_signal(SIGTERM) < 0)
+ return -E_SIGACTION;
+ if (catch_signal(SIGPIPE) == SIG_ERR)
+ return -E_SIGACTION;
return 1;
}
_ERROR(EMPTY, "file empty") \
_ERROR(MMAP, "mmap error") \
_ERROR(OSL, "osl error") \
- _ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR") \
+ _ERROR(SIGACTION, "could not install signal handler") \
_ERROR(OUTPUT, "error writing output") \
_ERROR(MALFORMED_FORMAT, "malformed format string") \
_ERROR(BAD_ALIGN_SPEC, "bad alignment specifier") \