Change in libosmocore[master]: vty: add "shutdown"

osmith gerrit-no-reply at lists.osmocom.org
Mon Jul 12 16:26:05 UTC 2021


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/24926 )


Change subject: vty: add "shutdown"
......................................................................

vty: add "shutdown"

Call osmo_select_shutdown_request() internally after user runs the
new shutdown command.

Lots of Osmocom applications don't use the osmo_select_shutdown_done()
command in their main loop (e.g. OsmoMSC, OsmoHLR, ...) so add a code
path for that case.

Closes: OS#4609
Change-Id: I3596a35b0f4a24e49484ec3f24a98e4d4f583e1e
---
M src/select.c
M src/vty/command.c
2 files changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/26/24926/1

diff --git a/src/select.c b/src/select.c
index f7eb5ea..843bda4 100644
--- a/src/select.c
+++ b/src/select.c
@@ -73,6 +73,11 @@
 static int _osmo_select_shutdown_requested = 0;
 /*! See osmo_select_shutdown_request() */
 static bool _osmo_select_shutdown_done = false;
+/*! For proper shutdown handling we expect osmo_select_shutdown_done() to be
+ * called in a program's main loop and clean up done afterwards. If the
+ * function never gets called, the VTY command "shutdown" needs to call exit()
+ * instead. */
+bool _osmo_select_shutdown_done_called = false;
 
 /*! Set up an osmo-fd. Will not register it.
  *  \param[inout] ofd Osmo FD to be set-up
@@ -661,6 +666,7 @@
 /*! Return true after osmo_select_shutdown_requested() was called, and after an osmo_select poll loop found no more
  * pending OSMO_FD_WRITE on any registered socket. */
 bool osmo_select_shutdown_done() {
+	_osmo_select_shutdown_done_called = true;
 	return _osmo_select_shutdown_done;
 };
 
diff --git a/src/vty/command.c b/src/vty/command.c
index e747add..fdc19ed 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -45,6 +45,8 @@
 #include <osmocom/vty/vty.h>
 #include <osmocom/vty/command.h>
 
+#include <osmocom/core/logging.h>
+#include <osmocom/core/select.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
 
@@ -61,6 +63,8 @@
 
 #define CONFIGFILE_MASK 022
 
+extern bool _osmo_select_shutdown_done_called;
+
 void *tall_vty_cmd_ctx;
 
 /* When cmd_init() was called, for the "show uptime". */
@@ -3021,6 +3025,25 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(shutdown,
+      shutdown_cmd, "shutdown", "Request a graceful shutdown of the program\n")
+{
+	LOGP(DLGLOBAL, LOGL_INFO, "Shutdown requested from telnet\n");
+	vty_out(vty, "%s is shutting down. Bye!%s", host.app_info->name, VTY_NEWLINE);
+	osmo_select_shutdown_request();
+
+	/* Call exit() from here if program won't stop on its own */
+	if (!_osmo_select_shutdown_done_called) {
+		LOGP(DLGLOBAL, LOGL_INFO, "Skipping %s main loop during shutdown\n", host.app_info->name);
+
+		while (!osmo_select_shutdown_done())
+			osmo_select_main_ctx(0);
+
+		exit(0);
+	}
+	return CMD_SUCCESS;
+}
+
 /* Show version. */
 DEFUN(show_version,
       show_version_cmd, "show version", SHOW_STR "Displays program version\n")
@@ -4392,6 +4415,7 @@
 		install_lib_element(ENABLE_NODE, &config_disable_cmd);
 		install_lib_element(ENABLE_NODE, &config_terminal_cmd);
 		install_lib_element(ENABLE_NODE, &copy_runningconfig_startupconfig_cmd);
+		install_lib_element(ENABLE_NODE, &shutdown_cmd);
 	}
 	install_lib_element(ENABLE_NODE, &show_startup_config_cmd);
 	install_lib_element(ENABLE_NODE, &show_version_cmd);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I3596a35b0f4a24e49484ec3f24a98e4d4f583e1e
Gerrit-Change-Number: 24926
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/20210712/7064f5b8/attachment.htm>


More information about the gerrit-log mailing list