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 <[email protected]>
Acked-by: Bruce Richardson <[email protected]>
---
 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

Reply via email to