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
This commit is contained in:
Harald Welte 2024-03-07 17:26:36 +01:00
parent 046ba3d27d
commit 05605354ef
1 changed files with 33 additions and 1 deletions

View File

@ -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 @@ static struct {
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 @@ int main(int argc, char **argv)
}
}
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)