* [PATCH] commands: sleep: add msleep support
@ 2025-06-18 12:37 Sascha Hauer
0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2025-06-18 12:37 UTC (permalink / raw)
To: Barebox List
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-18 15:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18 12:37 [PATCH] commands: sleep: add msleep support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox