mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] commands: dmesg: support aborting dmesg output with ctrl-c
Date: Wed,  6 Mar 2024 19:45:19 +0100	[thread overview]
Message-ID: <20240306184519.626594-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240306184519.626594-1-a.fatoum@pengutronix.de>

dmesg output can get very long, especially if debug messages are
compiled in and the maximum number of retained log messages is
increased.

Therefore, follow what we do for other potentially long-running
commands and allow the user to abort it with ctrl+c.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/dmesg.c        | 6 ++++--
 common/console_common.c | 6 +++++-
 include/linux/printk.h  | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/commands/dmesg.c b/commands/dmesg.c
index 83410234e1d6..8a60f075076e 100644
--- a/commands/dmesg.c
+++ b/commands/dmesg.c
@@ -76,7 +76,7 @@ static unsigned dmesg_get_levels(const char *__args)
 
 static int do_dmesg(int argc, char *argv[])
 {
-	int opt, i;
+	int opt, ret, i;
 	int delete_buf = 0, emit = 0;
 	unsigned flags = 0, levels = 0;
 	char *set = NULL;
@@ -148,7 +148,9 @@ static int do_dmesg(int argc, char *argv[])
 		return 0;
 	}
 
-	log_print(flags, levels);
+	ret = log_print(flags, levels);
+	if (ret)
+		return 1;
 
 	if (delete_buf)
 		log_clean(10);
diff --git a/common/console_common.c b/common/console_common.c
index d25fb0dc5dde..631756e4800c 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -208,7 +208,7 @@ int log_writefile(const char *filepath)
 	return ret < 0 ? ret : nbytes;
 }
 
-void log_print(unsigned flags, unsigned levels)
+int log_print(unsigned flags, unsigned levels)
 {
 	struct log_entry *log;
 	unsigned long last = 0;
@@ -219,6 +219,8 @@ void log_print(unsigned flags, unsigned levels)
 
 		if (levels && !(levels & (1 << log->level)))
 			continue;
+		if (ctrlc())
+			return -EINTR;
 
 		if (!(flags & (BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME
 			       | BAREBOX_LOG_DIFF_TIME)))
@@ -247,6 +249,8 @@ void log_print(unsigned flags, unsigned levels)
 
 		printf("%s", log->msg);
 	}
+
+	return 0;
 }
 
 int printf(const char *fmt, ...)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 0e9604bbe967..07403ea60cb7 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -189,7 +189,7 @@ extern void log_clean(unsigned int limit);
 #define BAREBOX_LOG_PRINT_TIME		BIT(0)
 
 int log_writefile(const char *filepath);
-void log_print(unsigned flags, unsigned levels);
+int log_print(unsigned flags, unsigned levels);
 
 struct va_format {
 	const char *fmt;
-- 
2.39.2




  reply	other threads:[~2024-03-06 18:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 18:45 [PATCH 1/2] console: scale number of log messages with available RAM Ahmad Fatoum
2024-03-06 18:45 ` Ahmad Fatoum [this message]
2024-03-08  7:02 ` Sascha Hauer

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=20240306184519.626594-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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