[Bug 264162] /bin/sleep: Add optional units (seconds, minutes, hours, days)
Date: Tue, 24 May 2022 07:55:40 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264162
Stefan Eßer <se@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |se@FreeBSD.org
Attachment #234127| |maintainer-approval+
Flags| |
--- Comment #1 from Stefan Eßer <se@FreeBSD.org> ---
Comment on attachment 234127
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=234127
Allow passing optional units (seconds, minutes, hours, days) to /bin/sleep
Thank you for the contribution!
The patch looks mostly OK. I would have used a variable to catch the number of
patterns parsed by sscanf() instead of duplicating that call, but this is a
technical detail.
There is one issue, though:
if (sscanf(argv[1], "%lf%c%1s", &d, &unit, buf) != 1)
should be:
if (sscanf(argv[1], "%lf%c%1s", &d, &unit, buf) == 2)
The != 1 test detects the presence of an extra argument following the number,
but does not reject the case of more than 1 character following.
Testing for 2 patterns matching makes sure that there was just a floating point
number followed by a single character. This catches the case of e.g. "1sx"
being passed as the argument, since the extra "s" would be parsed as a 3rd
match.
I'll commit the patch with the test of the first sscanf() changed to "== 2".
And I'm considering to add a loop to add up multiple delay values being passed
as is done by the coreutils version of sleep, for full functional compatibility
with that version, in a follow-up commit.
--
You are receiving this mail because:
You are the assignee for the bug.