summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpjanzen <pjanzen@openbsd.org>2000-01-05 01:58:03 +0000
committerpjanzen <pjanzen@openbsd.org>2000-01-05 01:58:03 +0000
commita941662cf720ab898faaa376ce4193ba744aa806 (patch)
tree5e64f5b9eedb9e31a315b74c649bead3a0e8e147
parentavoid use of kvm (sync with latest kame) (diff)
downloadwireguard-openbsd-a941662cf720ab898faaa376ce4193ba744aa806.tar.xz
wireguard-openbsd-a941662cf720ab898faaa376ce4193ba744aa806.zip
Return EINVAL if we can't sleep for the specified time interval (i.e. it's
too long); problem noted by viha@vip.fi
-rw-r--r--bin/sleep/sleep.18
-rw-r--r--bin/sleep/sleep.c27
2 files changed, 20 insertions, 15 deletions
diff --git a/bin/sleep/sleep.1 b/bin/sleep/sleep.1
index 332ecfce7c4..5bb4a0f5114 100644
--- a/bin/sleep/sleep.1
+++ b/bin/sleep/sleep.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sleep.1,v 1.9 1999/12/06 20:27:38 espie Exp $
+.\" $OpenBSD: sleep.1,v 1.10 2000/01/05 01:58:03 pjanzen Exp $
.\" $NetBSD: sleep.1,v 1.9 1995/07/25 19:37:43 jtc Exp $
.\"
.\" Copyright (c) 1990, 1993, 1994
@@ -52,6 +52,8 @@ The
utility
suspends execution for a minimum of
.Ar seconds .
+.Ar seconds
+must be positive and may contain a decimal fraction.
.Nm
is used to schedule the execution of other commands (see
.Sx EXAMPLES
@@ -73,10 +75,6 @@ An error occurred.
handles fractional arguments as an extension to
.St -p1003.2 .
.Sh EXAMPLES
-To schedule the execution of a command for
-.Va x
-seconds later:
-.Pp
.Dl (sleep 1800; sh command_file >& errors)&
.Pp
This incantation would wait a half hour before
diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c
index 91b9fe04839..9b91c13674c 100644
--- a/bin/sleep/sleep.c
+++ b/bin/sleep/sleep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sleep.c,v 1.8 1997/09/12 04:44:32 millert Exp $ */
+/* $OpenBSD: sleep.c,v 1.9 2000/01/05 01:58:03 pjanzen Exp $ */
/* $NetBSD: sleep.c,v 1.8 1995/03/21 09:11:11 cgd Exp $ */
/*
@@ -44,17 +44,18 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: sleep.c,v 1.8 1997/09/12 04:44:32 millert Exp $";
+static char rcsid[] = "$OpenBSD: sleep.c,v 1.9 2000/01/05 01:58:03 pjanzen Exp $";
#endif
#endif /* not lint */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#include <ctype.h>
+#include <errno.h>
#include <locale.h>
-#include <time.h>
#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
void usage __P((void));
void alarmh __P((int));
@@ -65,7 +66,7 @@ main(argc, argv)
char *argv[];
{
int ch;
- int secs = 0;
+ time_t secs = 0, t;
unsigned char *cp;
long nsecs = 0;
struct timespec rqtp;
@@ -77,6 +78,8 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
+ case '?':
+ case 'h':
default:
usage();
}
@@ -89,7 +92,10 @@ main(argc, argv)
cp = *argv;
while ((*cp != '\0') && (*cp != '.')) {
if (!isdigit(*cp)) usage();
- secs = (secs * 10) + (*cp++ - '0');
+ t = (secs * 10) + (*cp++ - '0');
+ if (t / 10 != secs) /* oflow */
+ exit(EINVAL);
+ secs = t;
}
/* Handle fractions of a second */
@@ -111,11 +117,12 @@ main(argc, argv)
}
}
- rqtp.tv_sec = (time_t) secs;
+ rqtp.tv_sec = secs;
rqtp.tv_nsec = nsecs;
if ((secs > 0) || (nsecs > 0))
- (void)nanosleep(&rqtp, NULL);
+ if (nanosleep(&rqtp, NULL))
+ exit(errno);
exit(0);
}