laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/36203?usp=email )
(
1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: osmo_hnbgw_main: Install our usual SIGUSR1/SIGUSR2/SIGABRT handlers ......................................................................
osmo_hnbgw_main: Install our usual SIGUSR1/SIGUSR2/SIGABRT handlers
I just wanted to get a talloc report from osmo-hnbgw by sending SIGUSR1 and the process terminated. Clearly not the desired behaviour...
Change-Id: I1209a2fadacf62afd5027480426285f527249788 --- M src/osmo-hnbgw/osmo_hnbgw_main.c 1 file changed, 45 insertions(+), 1 deletion(-)
Approvals: fixeria: Looks good to me, approved pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/src/osmo-hnbgw/osmo_hnbgw_main.c b/src/osmo-hnbgw/osmo_hnbgw_main.c index d371914..377ee47 100644 --- a/src/osmo-hnbgw/osmo_hnbgw_main.c +++ b/src/osmo-hnbgw/osmo_hnbgw_main.c @@ -1,6 +1,6 @@ /* OsmoHNBGW main routine */
-/* (C) 2015 by Harald Welte laforge@gnumonks.org +/* (C) 2015-2024 by Harald Welte laforge@gnumonks.org * (C) 2016-2023 by sysmocom s.f.m.c. GmbH info@sysmocom.de * All Rights Reserved * @@ -19,6 +19,7 @@ * */
+#include <signal.h> #include <getopt.h>
#include "config.h" @@ -64,6 +65,32 @@ NULL, };
+static void signal_handler(int signum) +{ + fprintf(stdout, "signal %u received\n", signum); + + switch (signum) { + case SIGABRT: + /* in case of abort, we want to obtain a talloc report and + * then run default SIGABRT handler, who will generate coredump + * and abort the process. abort() should do this for us after we + * return, but program wouldn't exit if an external SIGABRT is + * received. + */ + talloc_report(tall_vty_ctx, stderr); + talloc_report_full(g_hnbgw, stderr); + signal(SIGABRT, SIG_DFL); + raise(SIGABRT); + break; + case SIGUSR1: + talloc_report(tall_vty_ctx, stderr); + talloc_report_full(g_hnbgw, stderr); + break; + default: + break; + } +} + static void print_usage(void) { printf("Usage: osmo-hnbgw\n"); @@ -313,6 +340,11 @@ } }
+ signal(SIGABRT, &signal_handler); + signal(SIGUSR1, &signal_handler); + signal(SIGUSR2, &signal_handler); + osmo_init_ignore_signals(); + while (1) { rc = osmo_select_main_ctx(0); if (rc < 0)