Date: Tue, 24 May 2022 07:55:40 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 264162] /bin/sleep: Add optional units (seconds, minutes, hours, days) Message-ID: <bug-264162-227-45Grwjimhu@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-264162-227@https.bugs.freebsd.org/bugzilla/> References: <bug-264162-227@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D264162 Stefan E=C3=9Fer <se@FreeBSD.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |se@FreeBSD.org Attachment #234127| |maintainer-approval+ Flags| | --- Comment #1 from Stefan E=C3=9Fer <se@FreeBSD.org> --- Comment on attachment 234127 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D234127 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) !=3D 1) should be: if (sscanf(argv[1], "%lf%c%1s", &d, &unit, buf) =3D=3D 2) The !=3D 1 test detects the presence of an extra argument following the num= ber, 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 p= oint 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 "=3D= =3D 2". And I'm considering to add a loop to add up multiple delay values being pas= sed as is done by the coreutils version of sleep, for full functional compatibi= lity with that version, in a follow-up commit. --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-264162-227-45Grwjimhu>