]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Check return value of sigaction()
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Thu, 30 Dec 2021 21:35:37 +0000 (22:35 +0100)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 26 Feb 2022 15:50:32 +0000 (16:50 +0100)
It shouldn't fail, but you never know. Check the return value and print
an error message. Yet do not bale out, as OpenConnect might still be
able to create the VPN connection.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
main.c

diff --git a/main.c b/main.c
index 65be6a2f1e1d791567dfddde9cf1de7c1feb2ca4..7dfccf5c02b71191a4a6402eb5a3e8c2a34c7597 100644 (file)
--- a/main.c
+++ b/main.c
@@ -826,6 +826,15 @@ static void handle_signal(int sig)
        if (sig_vpninfo)
                sig_vpninfo->need_poll_cmd_fd = 1;
 }
+
+static int checked_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
+{
+       int ret = sigaction(signum, act, oldact);
+       if (ret)
+               fprintf(stderr, _("WARNING: Cannot set handler for signal %d: %s\n"),
+                       signum, strerror(errno));
+       return ret;
+}
 #else /* _WIN32 */
 static const char *default_vpncscript;
 static void set_default_vpncscript(void)
@@ -2174,11 +2183,11 @@ int main(int argc, char **argv)
        memset(&sa, 0, sizeof(sa));
 
        sa.sa_handler = handle_signal;
-       sigaction(SIGTERM, &sa, NULL);
-       sigaction(SIGINT, &sa, NULL);
-       sigaction(SIGHUP, &sa, NULL);
-       sigaction(SIGUSR1, &sa, NULL);
-       sigaction(SIGUSR2, &sa, NULL);
+       checked_sigaction(SIGTERM, &sa, NULL);
+       checked_sigaction(SIGINT, &sa, NULL);
+       checked_sigaction(SIGHUP, &sa, NULL);
+       checked_sigaction(SIGUSR1, &sa, NULL);
+       checked_sigaction(SIGUSR2, &sa, NULL);
 #else /* _WIN32 */
        SetConsoleCtrlHandler(console_ctrl_handler, TRUE /* Add */);
 #endif