Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, hare@suse.com, kbusch@kernel.org, hch@lst.de,
	sagi@grimberg.me, gjoyce@linux.ibm.com, wenxiong@linux.ibm.com
Subject: [PATCHv3 5/7] nvme: add sigaction for SIGWINCH
Date: Wed, 13 May 2026 01:45:50 +0530	[thread overview]
Message-ID: <20260512201559.3057514-6-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260512201559.3057514-1-nilay@linux.ibm.com>

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@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



  parent reply	other threads:[~2026-05-12 20:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 20:15 [PATCHv3 0/7] nvme-cli: add nvme top command for real-time monitoring Nilay Shroff
2026-05-12 20:15 ` [PATCHv3 1/7] nvme: add support for unsigned and long types in table_get_value_width() Nilay Shroff
2026-05-12 20:15 ` [PATCHv3 2/7] nvme: use table_get_value_width() in table_print_centered() Nilay Shroff
2026-05-12 20:15 ` [PATCHv3 3/7] nvme: add support for float and double types in table_print_XXX() Nilay Shroff
2026-05-12 20:15 ` [PATCHv3 4/7] nvme: allow table output to be directed to a FILE stream Nilay Shroff
2026-05-12 20:15 ` Nilay Shroff [this message]
2026-05-12 20:15 ` [PATCHv3 6/7] nvme: add generic top-like dashboard framework Nilay Shroff
2026-05-12 20:15 ` [PATCHv3 7/7] nvme: add nvme top command Nilay Shroff
2026-05-13 14:22 ` [PATCHv3 0/7] nvme-cli: add nvme top command for real-time monitoring Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260512201559.3057514-6-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=dwagner@suse.de \
    --cc=gjoyce@linux.ibm.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=wenxiong@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox