mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] commands: sleep: add msleep support
Date: Wed, 18 Jun 2025 14:37:27 +0200	[thread overview]
Message-ID: <20250618123727.2110575-1-s.hauer@pengutronix.de> (raw)

Sometimes it's useful to delay execution for less than a second. Add
support for msleep command which is implemented as an alias to the sleep
command.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/sleep.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/commands/sleep.c b/commands/sleep.c
index b462ef4413..641dbb230a 100644
--- a/commands/sleep.c
+++ b/commands/sleep.c
@@ -10,16 +10,20 @@
 
 static int do_sleep(int argc, char *argv[])
 {
-	uint64_t start;
-	ulong delay;
+	uint64_t start, delay;
 
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
 
 	delay = simple_strtoul(argv[1], NULL, 10);
 
+	if (!strcmp(argv[0], "msleep"))
+		delay *= MSECOND;
+	else
+		delay *= SECOND;
+
 	start = get_time_ns();
-	while (!is_timeout(start, delay * SECOND)) {
+	while (!is_timeout(start, delay)) {
 		if (ctrlc())
 			return 1;
 	}
@@ -27,9 +31,12 @@ static int do_sleep(int argc, char *argv[])
 	return 0;
 }
 
+static const char * const sleep_aliases[] = { "msleep", NULL};
+
 BAREBOX_CMD_START(sleep)
 	.cmd		= do_sleep,
-	BAREBOX_CMD_DESC("delay execution for n seconds")
+	.aliases	= sleep_aliases,
+	BAREBOX_CMD_DESC("delay execution for n seconds or n mseconds if invoked as msleep")
 	BAREBOX_CMD_OPTS("SECONDS")
 	BAREBOX_CMD_GROUP(CMD_GRP_SCRIPT)
 	BAREBOX_CMD_COMPLETE(command_var_complete)
-- 
2.39.5




                 reply	other threads:[~2025-06-18 15:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250618123727.2110575-1-s.hauer@pengutronix.de \
    --to=s.hauer@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