[PATCHv2 5/7] nvme: add sigaction for SIGWINCH
Nilay Shroff
nilay at linux.ibm.com
Mon May 11 04:55:45 PDT 2026
Add a sigaction handler for SIGWINCH so that nvme-top can detect
terminal window size changes.
This allows the dashboard layout to be adjusted and redrawn when the
terminal is resized. To avoid undefined behavior and async-signal-safety
the data type for nvme_sigwinch_received is defined as volatile
sig_atomic_t.
While we are at it, also update the data type of nvme_sigint_received
to volatile sig_atomic_t.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
util/sighdl.c | 16 ++++++++++++----
util/sighdl.h | 4 +++-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/util/sighdl.c b/util/sighdl.c
index 146591e5d..2899e9cb3 100644
--- a/util/sighdl.c
+++ b/util/sighdl.c
@@ -5,11 +5,15 @@
#include "sighdl.h"
-bool nvme_sigint_received;
+volatile sig_atomic_t nvme_sigint_received;
+volatile sig_atomic_t nvme_sigwinch_received;
-static void nvme_sigint_handler(int signum)
+static void nvme_sig_handler(int signum)
{
- nvme_sigint_received = true;
+ if (signum == SIGINT)
+ nvme_sigint_received = true;
+ else if (signum == SIGWINCH)
+ nvme_sigwinch_received = true;
}
int nvme_install_sigint_handler(void)
@@ -17,12 +21,16 @@ int nvme_install_sigint_handler(void)
struct sigaction act;
sigemptyset(&act.sa_mask);
- act.sa_handler = nvme_sigint_handler;
+ act.sa_handler = nvme_sig_handler;
act.sa_flags = 0;
nvme_sigint_received = false;
if (sigaction(SIGINT, &act, NULL) == -1)
return -errno;
+ nvme_sigwinch_received = false;
+ if (sigaction(SIGWINCH, &act, NULL) == -1)
+ return -errno;
+
return 0;
}
diff --git a/util/sighdl.h b/util/sighdl.h
index 8d5d1c126..41c823abe 100644
--- a/util/sighdl.h
+++ b/util/sighdl.h
@@ -3,8 +3,10 @@
#define __NVME_SIGHDL
#include <stdbool.h>
+#include <signal.h>
-extern bool nvme_sigint_received;
+extern volatile sig_atomic_t nvme_sigint_received;
+extern volatile sig_atomic_t nvme_sigwinch_received;
int nvme_install_sigint_handler(void);
--
2.53.0
More information about the Linux-nvme
mailing list