The SIGHUP handler calls printf() which is not async-signal-safe.

Set a flag instead and print the stats from the main lcore in the
forwarding loop.

Signed-off-by: Stephen Hemminger <[email protected]>
Acked-by: Bruce Richardson <[email protected]>
---
 examples/vmdq/main.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c
index 8c9d885090..63ac44deba 100644
--- a/examples/vmdq/main.c
+++ b/examples/vmdq/main.c
@@ -465,18 +465,27 @@ update_mac_address(struct rte_mbuf *m, unsigned dst_port)
        rte_ether_addr_copy(&vmdq_ports_eth_addr[dst_port], &eth->src_addr);
 }
 
-/* When we receive a HUP signal, print out our stats */
+/* Set by the SIGHUP handler, consumed by the main lcore. */
+static volatile sig_atomic_t stats_requested;
+
+static void
+sighup_handler(__rte_unused int signum)
+{
+       stats_requested = 1;
+}
+
 static void
-sighup_handler(int signum)
+print_stats(void)
 {
        unsigned int q = vmdq_queue_base;
+
        for (; q < num_queues; q++) {
                if ((q - vmdq_queue_base) % (num_vmdq_queues / num_pools) == 0)
                        printf("\nPool %u: ", (q - vmdq_queue_base) /
                               (num_vmdq_queues / num_pools));
                printf("%lu ", rxPackets[q]);
        }
-       printf("\nFinished handling signal %d\n", signum);
+       putchar('\n');
 }
 
 /*
@@ -534,6 +543,11 @@ lcore_main(__rte_unused void *dummy)
                struct rte_mbuf *buf[MAX_PKT_BURST];
                const uint16_t buf_size = RTE_DIM(buf);
 
+               if (stats_requested && lcore_id == rte_get_main_lcore()) {
+                       stats_requested = 0;
+                       print_stats();
+               }
+
                for (p = 0; p < num_ports; p++) {
                        const uint8_t sport = ports[p];
                        /* 0 <-> 1, 2 <-> 3 etc */
-- 
2.53.0

Reply via email to