[PATCH v2 07/13] examples/vhost_blk: do not tear down from signal handler
Stephen Hemminger
stephen at networkplumber.org
Mon Sep 7 19:03:25 CEST 2026
The SIGINT handler destroyed the controller and called exit() from
signal context.
Set a flag, break the sleep loop, and destroy the controller in main().
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
examples/vhost_blk/vhost_blk.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index 9c9e326949..0665d9fb51 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -850,24 +850,18 @@ vhost_blk_ctrlr_destroy(struct vhost_blk_ctrlr *ctrlr)
rte_vhost_driver_unregister(dev_pathname);
}
+/* Set by the SIGINT handler to break the main loop. */
+static volatile sig_atomic_t quit;
+
static void
signal_handler(__rte_unused int signum)
{
- struct vhost_blk_ctrlr *ctrlr;
-
- ctrlr = vhost_blk_ctrlr_find(dev_pathname);
- if (ctrlr == NULL)
- return;
-
- if (ctrlr->started)
- destroy_device(ctrlr->vid);
-
- vhost_blk_ctrlr_destroy(ctrlr);
- exit(0);
+ quit = 1;
}
int main(int argc, char *argv[])
{
+ struct vhost_blk_ctrlr *ctrlr;
int ret;
/* init EAL */
@@ -895,9 +889,17 @@ int main(int argc, char *argv[])
}
/* loop for exit the application */
- while (1)
+ while (!quit)
sleep(1);
+ ctrlr = vhost_blk_ctrlr_find(dev_pathname);
+ if (ctrlr != NULL) {
+ if (ctrlr->started)
+ destroy_device(ctrlr->vid);
+
+ vhost_blk_ctrlr_destroy(ctrlr);
+ }
+
/* clean up the EAL */
rte_eal_cleanup();
--
2.53.0
More information about the dev
mailing list