FreeBSD Bugzilla – Attachment 234127 Details for
Bug 264162
/bin/sleep: Add optional units (seconds, minutes, hours, days)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Allow passing optional units (seconds, minutes, hours, days) to /bin/sleep
patch-add-units-to-sleep.diff (text/plain), 1.50 KB, created by
Mallory
on 2022-05-22 22:21:24 UTC
(
hide
)
Description:
Allow passing optional units (seconds, minutes, hours, days) to /bin/sleep
Filename:
MIME Type:
Creator:
Mallory
Created:
2022-05-22 22:21:24 UTC
Size:
1.50 KB
patch
obsolete
>diff --git a/bin/sleep/sleep.1 b/bin/sleep/sleep.1 >index 924bc732a0d..3ce82936a0e 100644 >--- a/bin/sleep/sleep.1 >+++ b/bin/sleep/sleep.1 >@@ -40,13 +40,21 @@ > .Nd suspend execution for an interval of time > .Sh SYNOPSIS > .Nm >-.Ar seconds >+.Ar number[unit] > .Sh DESCRIPTION > The > .Nm > command > suspends execution for a minimum of >-.Ar seconds . >+.Ar number >+seconds (the default, or unit >+.Ar s ) , >+or minutes (unit >+.Ar m ) , >+hours (unit >+.Ar h ) , >+or days (unit >+.Ar d ) . > .Pp > If the > .Nm >diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c >index b4b54a33610..02860166c68 100644 >--- a/bin/sleep/sleep.c >+++ b/bin/sleep/sleep.c >@@ -66,6 +66,7 @@ main(int argc, char *argv[]) > struct timespec time_to_sleep; > double d; > time_t original; >+ char unit; > char buf[2]; > > if (caph_limit_stdio() < 0 || caph_enter() < 0) >@@ -74,8 +75,17 @@ main(int argc, char *argv[]) > if (argc != 2) > usage(); > >- if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) >- usage(); >+ if (sscanf(argv[1], "%lf%c%1s", &d, &unit, buf) != 1) >+ switch(unit) { >+ case 'd': d *= 24; >+ case 'h': d *= 60; >+ case 'm': d *= 60; >+ case 's': break; >+ default: usage(); >+ } >+ else >+ if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) >+ usage(); > if (d > INT_MAX) > usage(); > if (d <= 0) >@@ -106,6 +116,8 @@ static void > usage(void) > { > >- fprintf(stderr, "usage: sleep seconds\n"); >+ fprintf(stderr, "usage: sleep number[unit]\n"); >+ fprintf(stderr, "Unit can be 's' (seconds, the default), " >+ "m (minutes), h (hours), or d (days).\n"); > exit(1); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
se
:
maintainer-approval+
Actions:
View
|
Diff
Attachments on
bug 264162
: 234127