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,
	gjoyce@linux.ibm.com, wenxiong@linux.ibm.com
Subject: [PATCHv2 5/7] nvme: add sigaction for SIGWINCH
Date: Mon, 11 May 2026 17:25:45 +0530	[thread overview]
Message-ID: <20260511115555.2638335-6-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260511115555.2638335-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 | 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



  parent reply	other threads:[~2026-05-11 11:56 UTC|newest]

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

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=20260511115555.2638335-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=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