[PATCH v2 05/13] examples/vdpa: make signal handler safe
Stephen Hemminger
stephen at networkplumber.org
Mon Sep 7 19:03:23 CEST 2026
The handler called printf(), the vhost library teardown path and
exit(), none of which are async-signal-safe.
Set a flag and do the teardown in main() once the input loop returns.
This also closes the vDPA devices on exit from interactive mode, which
was missing before.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
examples/vdpa/main.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
index ac6da79b05..1b989fc6e5 100644
--- a/examples/vdpa/main.c
+++ b/examples/vdpa/main.c
@@ -288,14 +288,13 @@ vdpa_sample_quit(void)
}
}
+/* Set by SIGINT and SIGTERM handler, consumed by main(). */
+static volatile sig_atomic_t quit;
+
static void
-signal_handler(int signum)
+signal_handler(__rte_unused int signum)
{
- if (signum == SIGINT || signum == SIGTERM) {
- printf("\nSignal %d received, preparing to exit...\n", signum);
- vdpa_sample_quit();
- exit(0);
- }
+ quit = 1;
}
/* interactive cmd functions */
@@ -513,7 +512,7 @@ main(int argc, char *argv[])
}
printf("enter \'q\' to quit\n");
- while (scanf("%c", &ch)) {
+ while (!quit && scanf("%c", &ch)) {
if (ch == 'q')
break;
while (ch != '\n') {
@@ -522,9 +521,10 @@ main(int argc, char *argv[])
}
printf("enter \'q\' to quit\n");
}
- vdpa_sample_quit();
}
+ vdpa_sample_quit();
+
/* clean up the EAL */
rte_eal_cleanup();
--
2.53.0
More information about the dev
mailing list