vlib: add graceful termination with status 19/33719/4
authorPierre Pfister <ppfister@cisco.com>
Fri, 10 Sep 2021 14:38:03 +0000 (16:38 +0200)
committerDamjan Marion <dmarion@me.com>
Tue, 14 Sep 2021 14:42:07 +0000 (14:42 +0000)
This commit allows a non-VPP thread to request VPP to gracefully
shutdown and return a specific process status value.

Type: improvement
Change-Id: I9bf52b789e7ee28eb272630eaea495fd94349f79
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
src/vlib/main.c
src/vlib/main.h

index c7c4aba..2f21995 100644 (file)
@@ -2079,7 +2079,7 @@ done:
   if (error)
     clib_error_report (error);
 
-  return 0;
+  return vm->main_loop_exit_status;
 }
 
 vlib_main_t *
@@ -2094,6 +2094,13 @@ vlib_get_elog_main_not_inline ()
   return &vlib_global_main.elog_main;
 }
 
+void
+vlib_exit_with_status (vlib_main_t *vm, int status)
+{
+  vm->main_loop_exit_status = status;
+  __atomic_store_n (&vm->main_loop_exit_now, 1, __ATOMIC_RELEASE);
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index c655560..a16f603 100644 (file)
@@ -143,6 +143,8 @@ typedef struct vlib_main_t
   u32 main_loop_exit_set;
   /* Set e.g. in the SIGTERM signal handler, checked in a safe place... */
   volatile u32 main_loop_exit_now;
+  /* Exit status that will be returned by the process upon exit. */
+  volatile int main_loop_exit_status;
   clib_longjmp_t main_loop_exit;
 #define VLIB_MAIN_LOOP_EXIT_NONE 0
 #define VLIB_MAIN_LOOP_EXIT_PANIC 1
@@ -389,6 +391,8 @@ vlib_panic (vlib_main_t * vm)
   vlib_panic_with_error (vm, 0);
 }
 
+/* Asynchronously requests exit with the given status. */
+void vlib_exit_with_status (vlib_main_t *vm, int status);
 
 always_inline f64
 vlib_internal_node_vector_rate (vlib_main_t * vm)