From a74a01c4dd6f0347e33a0a4d963a8fa8159135c0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Thu, 30 Dec 2021 22:35:37 +0100 Subject: [PATCH] Check return value of sigaction() 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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 65be6a2f..7dfccf5c 100644 --- 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 -- 2.49.0