This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
osmith gerrit-no-reply at lists.osmocom.orgosmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26661 ) Change subject: Add signal handler ...................................................................... Add signal handler Related: OS#2545 Change-Id: I303e9275a2f1f6f2da742089d079ba604ee5a36b --- M src/osmo-bsc-nat/main.c 1 file changed, 44 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc-nat refs/changes/61/26661/1 diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c index 1edc134..a37d3cb 100644 --- a/src/osmo-bsc-nat/main.c +++ b/src/osmo-bsc-nat/main.c @@ -131,6 +131,49 @@ } } +static void signal_handler(int signum) +{ + fprintf(stdout, "signal %u received\n", signum); + + switch (signum) { + case SIGINT: + case SIGTERM: + /* If SIGTERM was already sent before, just terminate immediately. */ + if (osmo_select_shutdown_requested()) + exit(-1); + osmo_select_shutdown_request(); + break; + 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(tall_bsc_nat_ctx, stderr); + signal(SIGABRT, SIG_DFL); + raise(SIGABRT); + break; + case SIGUSR1: + talloc_report(tall_vty_ctx, stderr); + talloc_report_full(tall_bsc_nat_ctx, stderr); + break; + default: + break; + } +} + +static void signal_handler_init(void) +{ + signal(SIGINT, &signal_handler); + signal(SIGTERM, &signal_handler); + signal(SIGABRT, &signal_handler); + signal(SIGUSR1, &signal_handler); + signal(SIGUSR2, &signal_handler); + osmo_init_ignore_signals(); +} + int main(int argc, char **argv) { int rc; @@ -145,6 +188,7 @@ g_bsc_nat = bsc_nat_alloc(tall_bsc_nat_ctx); main_vty_init(argc, argv); + signal_handler_init(); while (!osmo_select_shutdown_done()) osmo_select_main_ctx(0); -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26661 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc-nat Gerrit-Branch: master Gerrit-Change-Id: I303e9275a2f1f6f2da742089d079ba604ee5a36b Gerrit-Change-Number: 26661 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211221/6e5bc13d/attachment.htm>