From 52ebbe544830fb9634f8b5b7fd57ca03e40aa62e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 18 Jun 2024 22:21:59 +0200 Subject: use sigaction(2) instead of signal(2) As stated in the man pages, `sigaction` should be preferred to `signal`. --- pacredir.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pacredir.c b/pacredir.c index cf92b60..4bfb16c 100644 --- a/pacredir.c +++ b/pacredir.c @@ -675,7 +675,9 @@ int main(int argc, char ** argv) { /* Probing for static pacserve hosts takes some time. * Receiving a SIGHUP at this time could kill us. So register signal * SIGHUP here before probing. */ - signal(SIGHUP, sighup_callback); + struct sigaction act_hup = { 0 }; + act_hup.sa_handler = sighup_callback; + sigaction(SIGHUP, &act_hup, NULL); /* parse config file */ if ((ini = iniparser_load(CONFIGFILE)) == NULL) { @@ -787,9 +789,11 @@ int main(int argc, char ** argv) { curl_global_init(CURL_GLOBAL_ALL); /* register SIG{TERM,KILL,INT} signal callbacks */ - signal(SIGTERM, sig_callback); - signal(SIGKILL, sig_callback); - signal(SIGINT, sig_callback); + struct sigaction act = { 0 }; + act.sa_handler = sig_callback; + sigaction(SIGTERM, &act, NULL); + sigaction(SIGKILL, &act, NULL); + sigaction(SIGINT, &act, NULL); /* report ready to systemd */ sd_notify(0, "READY=1\nSTATUS=Waiting for requests to redirect..."); -- cgit v1.2.3-70-g09d2