[PATCH v2 12/13] examples/vmdq_dcb: allow exit on signal
From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2026-09-07 17:06:08
Subsystem:
the rest · Maintainer:
Linus Torvalds
The forwarding loop never terminated, so the application could only be killed. There was also no wait for the worker lcores. Add a SIGINT and SIGTERM handler that sets a flag, return from lcore_main() when it is set, and join the workers before cleanup. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <redacted> --- examples/vmdq_dcb/main.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c
index d6f7b632b9..563b4f9ce1 100644
--- a/examples/vmdq_dcb/main.c
+++ b/examples/vmdq_dcb/main.c@@ -513,6 +513,15 @@ update_mac_address(struct rte_mbuf *m, unsigned dst_port) rte_ether_addr_copy(&vmdq_ports_eth_addr[dst_port], ð->src_addr); } +/* Set by the SIGINT and SIGTERM handler to stop the forwarding loops. */ +static volatile sig_atomic_t quit; + +static void +signal_handler(__rte_unused int signum) +{ + quit = 1; +} + /* When we receive a HUP signal, print out our stats */ static void sighup_handler(int signum)
@@ -567,7 +576,7 @@ lcore_main(void *arg) return 0; } - for (;;) { + while (!quit) { struct rte_mbuf *buf[MAX_PKT_BURST]; const uint16_t buf_size = RTE_DIM(buf); for (p = 0; p < num_ports; p++) {
@@ -598,6 +607,8 @@ lcore_main(void *arg) } } } + + return 0; } /*
@@ -640,6 +651,8 @@ main(int argc, char *argv[]) uint16_t portid; signal(SIGHUP, sighup_handler); + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); /* init EAL */ ret = rte_eal_init(argc, argv);
@@ -697,6 +710,11 @@ main(int argc, char *argv[]) /* call on main too */ (void) lcore_main((void*)i); + RTE_LCORE_FOREACH_WORKER(lcore_id) { + if (rte_eal_wait_lcore(lcore_id) < 0) + return -1; + } + /* clean up the EAL */ rte_eal_cleanup();
--
2.53.0