summaryrefslogtreecommitdiff
path: root/src/sleep.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-11-28 08:00:58 +0000
committerJim Meyering <jim@meyering.net>1999-11-28 08:00:58 +0000
commit4c05896b205ea872c07d9d17db66e09a5f06f0d2 (patch)
tree032132d2eb38cf27492cae339904479c1d4408d7 /src/sleep.c
parentec974f5c39fa3a26bd32682762b627456c5d969e (diff)
downloadcoreutils-4c05896b205ea872c07d9d17db66e09a5f06f0d2.tar.xz
better error checking
add FIXME comments for non-portable constructs
Diffstat (limited to 'src/sleep.c')
-rw-r--r--src/sleep.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/sleep.c b/src/sleep.c
index a5990bd1a..a96b80c00 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -170,14 +170,15 @@ main (int argc, char **argv)
int c;
int fail = 0;
struct timeval tv_start;
- struct timeval tv_done;
+ struct timeval tv_stop;
int i_sec;
int i_usec;
#ifdef SA_INTERRUPT
struct sigaction oldact, newact;
#endif
- /* FIXME */
+ /* Record start time. */
+ /* FIXME: this is not portable. write replacement based on times? */
gettimeofday (&tv_start, NULL);
program_name = argv[0];
@@ -210,12 +211,20 @@ main (int argc, char **argv)
{
double s;
const char *p;
- if (xstrtod (argv[i], &p, &s) || s < 0 || apply_suffix (&s, *p))
+ if (xstrtod (argv[i], &p, &s)
+ /* No negative intervals. */
+ || s < 0
+ /* No extra chars after number and optional s,m,h,d char. */
+ || (*p && *(p+1))
+ /* Update S based on suffix char. */
+ || apply_suffix (&s, *p))
{
error (0, 0, _("invalid time interval `%s'"), argv[i]);
fail = 1;
continue;
}
+
+ /* FIXME-maybe: This could overflow. */
seconds += s;
}
@@ -231,21 +240,22 @@ main (int argc, char **argv)
sigaction (SIGCONT, NULL, &oldact);
if (oldact.sa_handler != SIG_IGN)
sigaction (SIGCONT, &newact, NULL);
-#else /* !SA_INTERRUPT */
+#else
if (signal (SIGCONT, SIG_IGN) != SIG_IGN)
signal (SIGCONT, sighandler);
-#endif /* !SA_INTERRUPT */
+#endif
i_sec = floor (seconds);
sleep (i_sec);
i_usec = (int) ((seconds - i_sec) * 1000000);
+ /* FIXME: not portable: write replacement based on select. */
usleep (i_usec);
if (!suspended)
exit (0);
- tv_done.tv_sec = tv_start.tv_sec + i_sec;
- tv_done.tv_usec = tv_start.tv_usec + i_usec;
+ tv_stop.tv_sec = tv_start.tv_sec + i_sec;
+ tv_stop.tv_usec = tv_start.tv_usec + i_usec;
while (1)
{
@@ -253,7 +263,7 @@ main (int argc, char **argv)
struct timeval tv_now;
int negative;
gettimeofday (&tv_now, NULL);
- negative = timeval_subtract (&diff, &tv_done, &tv_now);
+ negative = timeval_subtract (&diff, &tv_stop, &tv_now);
if (negative)
break;
sleep (diff.tv_sec);