Hi Scott,

Scott Cheloha wrote on Sat, Feb 03, 2018 at 10:08:46AM -0600:

> This adds strtonum(3)-style error messages to sleep(1).  They're
> more informative than the usage statement and they're idiomatic
> for numeric input.
> 
> Exiting with EINVAL is really unusual.  It went into r1.9.  Unless
> I'm missing something I think we can just exit with 1, which is
> consistent with what other utilities do.

I consider this an improvement.  POSIX neither restricts the error
message format nor mandates specific non-zero EXIT STATUS values.
I can't see how it might break anyone's scripts either, unless those
are poorly written and rely on undocumented features.

In general, don't abuse errno(2) constants for the EXIT STATUS,
and don't use EXIT STATUS values other than 1 unless the utility
is unusually complicated, which sleep(1) certainly isn't.

OK schwarze@
  Ingo


> Index: bin/sleep/sleep.c
> ===================================================================
> RCS file: /cvs/src/bin/sleep/sleep.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 sleep.c
> --- bin/sleep/sleep.c 2 Feb 2018 16:46:37 -0000       1.25
> +++ bin/sleep/sleep.c 2 Feb 2018 17:20:58 -0000
> @@ -31,7 +31,6 @@
>   */
>  
>  #include <ctype.h>
> -#include <errno.h>
>  #include <signal.h>
>  #include <stdio.h>
>  #include <stdlib.h>
> @@ -73,10 +72,10 @@ main(int argc, char *argv[])
>       cp = *argv;
>       while ((*cp != '\0') && (*cp != '.')) {
>               if (!isdigit((unsigned char)*cp))
> -                     usage();
> +                     errx(1, "seconds is invalid: %s", *argv);
>               t = (secs * 10) + (*cp++ - '0');
>               if (t / 10 != secs)     /* oflow */
> -                     return (EINVAL);
> +                     errx(1, "seconds is too large: %s", *argv);
>               secs = t;
>       }
>  
> @@ -87,7 +86,7 @@ main(int argc, char *argv[])
>                       if (*cp == '\0')
>                               break;
>                       if (!isdigit((unsigned char)*cp))
> -                             usage();
> +                             errx(1, "seconds is invalid: %s", *argv);
>                       nsecs += (*cp++ - '0') * i;
>               }
>  
> @@ -98,7 +97,7 @@ main(int argc, char *argv[])
>                */
>               while (*cp != '\0') {
>                       if (!isdigit((unsigned char)*cp++))
> -                             usage();
> +                             errx(1, "seconds is invalid: %s", *argv);
>               }
>       }
>  
> 

Reply via email to