[PATCHv3 5/7] nvme: add sigaction for SIGWINCH
Nilay Shroff
nilay at linux.ibm.com
Tue May 12 13:15:50 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 | 25 +++++++++++++++++++++++--
util/sighdl.h | 5 ++++-
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/util/sighdl.c b/util/sighdl.c
index 146591e5d..e40d896b1 100644
--- a/util/sighdl.c
+++ b/util/sighdl.c
@@ -5,16 +5,22 @@
#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)
{
nvme_sigint_received = true;
}
+static void nvme_sigwinch_handler(int signum)
+{
+ nvme_sigwinch_received = true;
+}
+
int nvme_install_sigint_handler(void)
{
- struct sigaction act;
+ struct sigaction act = {0};
sigemptyset(&act.sa_mask);
act.sa_handler = nvme_sigint_handler;
@@ -26,3 +32,18 @@ int nvme_install_sigint_handler(void)
return 0;
}
+
+int nvme_install_sigwinch_handler(void)
+{
+ struct sigaction act = {0};
+
+ sigemptyset(&act.sa_mask);
+ act.sa_handler = nvme_sigwinch_handler;
+ act.sa_flags = 0;
+
+ 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..b0c7869e0 100644
--- a/util/sighdl.h
+++ b/util/sighdl.h
@@ -3,9 +3,12 @@
#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);
+int nvme_install_sigwinch_handler(void);
#endif // __NVME_SIGHDL
--
2.53.0
More information about the Linux-nvme
mailing list