The SIGINT handler unregistered the vhost drivers and called exit(),
neither of which is async-signal-safe.

Set a flag, let switch_worker() return, and unregister the drivers in
main() after joining the lcores.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 examples/vhost/main.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 5978a50cfe..f768f0c5e0 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -79,6 +79,9 @@ static int dma_count;
 /* mask of enabled ports */
 static uint32_t enabled_port_mask = 0;
 
+/* Set by the SIGINT handler to stop the worker loops. */
+static volatile sig_atomic_t quit;
+
 /* Promiscuous mode */
 static uint32_t promiscuous;
 
@@ -1494,7 +1497,7 @@ switch_worker(void *arg)
                }
        }
 
-       while(1) {
+       while (!quit) {
                drain_mbuf_table(tx_q);
                drain_vhost_table();
                /*
@@ -1872,14 +1875,10 @@ unregister_drivers(int socket_num)
        }
 }
 
-/* When we receive a INT signal, unregister vhost driver */
 static void
 sigint_handler(__rte_unused int signum)
 {
-       /* Unregister vhost driver. */
-       unregister_drivers(nb_sockets);
-
-       exit(0);
+       quit = 1;
 }
 
 static void
@@ -2070,6 +2069,9 @@ main(int argc, char *argv[])
        RTE_LCORE_FOREACH_WORKER(lcore_id)
                rte_eal_wait_lcore(lcore_id);
 
+       /* Unregister vhost driver. */
+       unregister_drivers(nb_sockets);
+
        for (i = 0; i < dma_count; i++) {
                if (rte_vhost_async_dma_unconfigure(dmas_id[i], 0) < 0) {
                        RTE_LOG(ERR, VHOST_PORT,
-- 
2.53.0

Reply via email to