Change in libosmo-sccp[master]: osmo-stp: refactor handling of both SIGINT and SIGTERM

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/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Fri May 10 18:05:34 UTC 2019


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13971


Change subject: osmo-stp: refactor handling of both SIGINT and SIGTERM
......................................................................

osmo-stp: refactor handling of both SIGINT and SIGTERM

On reception of one of the mentioned signals, we should gracefully
shutdown established SIGTRAN links by sending S_L_GLOBAL_SHUTDOWN.
As a bonus, let's report heap state of the root talloc-context.

Change-Id: I5d8618857c5119d4acca5d65cf1276ab02889c84
---
M stp/stp_main.c
1 file changed, 18 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/71/13971/1

diff --git a/stp/stp_main.c b/stp/stp_main.c
index 6a47403..3127321 100644
--- a/stp/stp_main.c
+++ b/stp/stp_main.c
@@ -48,6 +48,7 @@
 #include <osmocom/sigtran/protocol/m3ua.h>
 
 static void *tall_stp_ctx;
+static int quit = 0;
 
 /* we only use logging sub-systems of the various libraries so far */
 static const struct log_info_cat log_info_cat[] = {
@@ -136,11 +137,8 @@
 	switch (signal) {
 	case SIGINT:
 	case SIGTERM:
-		/* FIXME: handle the signal somewhere else and gracefully shut down
-		 * SIGTRAN links
-		osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
-		sleep(1); */
-		exit(0);
+		fprintf(stderr, "Terminating due to signal %d\n", signal);
+		quit++;
 		break;
 	case SIGABRT:
 		osmo_generate_backtrace();
@@ -214,9 +212,23 @@
 		}
 	}
 
-	while (1) {
+	while (!quit) {
 		rc = osmo_select_main(0);
 		if (rc < 0)
 			exit(3);
 	}
+
+	/* Gracefully shut down SIGTRAN links */
+	osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
+	sleep(1); /* FIXME: do we really need to sleep() here? */
+
+	/* Deinitialize logging */
+	log_fini();
+
+	/* Report state of the root talloc-context, then free,
+	 * so both ASAN and Valgrind are happy... */
+	talloc_report_full(tall_stp_ctx, stderr);
+	talloc_free(tall_stp_ctx);
+
+	return 0;
 }

-- 
To view, visit https://gerrit.osmocom.org/13971
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d8618857c5119d4acca5d65cf1276ab02889c84
Gerrit-Change-Number: 13971
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190510/d76e1b20/attachment.htm>


More information about the gerrit-log mailing list