From b9ed9a2c260864ebcf5b5ccaed6b765760310262 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sat, 25 May 2019 08:03:18 -0500 Subject: bin/sleep: make buildable with libbsd, remove nonportable fractional extension --- bin/sleep/sleep.1 | 16 +---------- bin/sleep/sleep.c | 86 +++++++++---------------------------------------------- 2 files changed, 14 insertions(+), 88 deletions(-) (limited to 'bin/sleep') diff --git a/bin/sleep/sleep.1 b/bin/sleep/sleep.1 index 1ee73b3..155a494 100644 --- a/bin/sleep/sleep.1 +++ b/bin/sleep/sleep.1 @@ -51,18 +51,8 @@ It is usually used to schedule the execution of other commands (see .Sx EXAMPLES below). .Pp -Note: The -.Nx -.Nm -command will accept and honor a non-integer number of specified seconds. -Note however, that if the request is for much more than 2.5 hours, -any fractional seconds will be ignored. -Permitting non-integral delays is a non-portable extension, -and its use will decrease the probability that -a shell script will execute properly on another system. -.Pp When the -.Dv SIGINFO +.Dv SIGHUP signal is received, an estimate of the number of seconds remaining to sleep is printed on the standard output. .Sh EXIT STATUS @@ -154,10 +144,6 @@ A .Nm utility appeared in .At v4 . -Processing fractional seconds, and processing the -.Ic seconds -argument respecting the current locale, was added in -.Nx 1.3 . The ability to sleep for extended periods appeared in .Nx 9 . .Sh BUGS diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c index dfaf302..e8392e6 100644 --- a/bin/sleep/sleep.c +++ b/bin/sleep/sleep.c @@ -29,20 +29,6 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94"; -#else -__RCSID("$NetBSD: sleep.c,v 1.29 2019/01/27 02:00:45 christos Exp $"); -#endif -#endif /* not lint */ - #include #include #include @@ -50,17 +36,18 @@ __RCSID("$NetBSD: sleep.c,v 1.29 2019/01/27 02:00:45 christos Exp $"); #include #include #include +#include #include #include -__dead static void alarmhandle(int); -__dead static void usage(void); +static void alarmhandle(int); +static void usage(void); static void report(const time_t, const time_t, const char *const); static volatile sig_atomic_t report_requested; static void -report_request(int signo __unused) +report_request(int signo) { report_requested = 1; @@ -74,7 +61,7 @@ main(int argc, char *argv[]) double fval, ival, val; struct timespec ntime; time_t original; - int ch, fracflag; + int ch; unsigned delay; setprogname(argv[0]); @@ -93,66 +80,19 @@ main(int argc, char *argv[]) if (argc != 1) usage(); - /* - * Okay, why not just use atof for everything? Why bother - * checking if there is a fraction in use? Because the old - * sleep handled the full range of integers, that's why, and a - * double can't handle a large long. This is fairly useless - * given how large a number a double can hold on most - * machines, but now we won't ever have trouble. If you want - * 1000000000.9 seconds of sleep, well, that's your - * problem. Why use an isdigit() check instead of checking for - * a period? Because doing it this way means locales will be - * handled transparently by the atof code. - * - * Since fracflag is set for any non-digit, we also fall - * into the floating point conversion path if the input - * is hex (the 'x' in 0xA is not a digit). Then if - * strtod() handles hex (on NetBSD it does) so will we. - * That path is also taken for scientific notation (1.2e+3) - * and when the input is simply nonsense. - */ - fracflag = 0; arg = *argv; for (temp = arg; *temp != '\0'; temp++) if (!isdigit((unsigned char)*temp)) { - ch = *temp; - fracflag++; - } - - if (fracflag) { - /* - * If we cannot convert the value using the user's locale - * then try again using the C locale, so strtod() can always - * parse values like 2.5, even if the user's locale uses - * a different decimal radix character (like ',') - * - * (but only if that is the potential problem) - */ - val = strtod(arg, &temp); - if (*temp != '\0') - val = strtod_l(arg, &temp, LC_C_LOCALE); - if (val < 0 || temp == arg || *temp != '\0') usage(); + } - ival = floor(val); - fval = (1000000000 * (val-ival)); - ntime.tv_sec = ival; - if ((double)ntime.tv_sec != ival) - errx(1, "requested delay (%s) out of range", arg); - ntime.tv_nsec = fval; - - if (ntime.tv_sec == 0 && ntime.tv_nsec == 0) - return EXIT_SUCCESS; /* was 0.0 or underflowed */ - } else { - ntime.tv_sec = strtol(arg, &temp, 10); - if (ntime.tv_sec < 0 || temp == arg || *temp != '\0') - usage(); + ntime.tv_sec = strtol(arg, &temp, 10); + if (ntime.tv_sec < 0 || temp == arg || *temp != '\0') + usage(); - if (ntime.tv_sec == 0) - return EXIT_SUCCESS; - ntime.tv_nsec = 0; - } + if (ntime.tv_sec == 0) + return EXIT_SUCCESS; + ntime.tv_nsec = 0; original = ntime.tv_sec; if (ntime.tv_nsec != 0) @@ -160,7 +100,7 @@ main(int argc, char *argv[]) else msg = ""; - signal(SIGINFO, report_request); + signal(SIGHUP, report_request); if (ntime.tv_sec <= 10000) { /* arbitrary */ while (nanosleep(&ntime, &ntime) != 0) { -- cgit v1.2.3-60-g2f50