Hi Daniel,

Daniel Dickman wrote on Thu, Jul 22, 2010 at 04:47:59PM -0400:

> exit 126 means "utility was found but could not be invoked".
> exit 1-125 means some other error in env(1)

Not quite; the -current manual says:

  1-125  utility was invoked but failed in some way; see its manual page
         for more information.  In this case the exit code is returned by
         the utility itself, not env.

Note the last line; so this diff looks wrong.

I agree 126 is not absolutely precise, because the utility was not
found, and the failure occurred before searching could even start.
But there is no better code.

When you can't even search for it, lying that you found it, but
cound not run it is less of a lie than saying that you ran it and
it failed.

POSIX would allow to redefine 125 to mean "env failed before it
could start searching for the utility", but this would change
existing OpenBSD behaviour, in particular make the meaning of 125
ambiguous, and i don't think that is an improvement.

Yours,
  Ingo

> So change 2 places to return an exit code of 125 instead.
> 
> Index: env.c
> ===================================================================
> RCS file: /usr/cvs/src/usr.bin/env/env.c,v
> retrieving revision 1.14
> diff -u -r1.14 env.c
> --- env.c     27 Oct 2009 23:59:37 -0000      1.14
> +++ env.c     22 Jul 2010 20:42:41 -0000
> @@ -54,7 +54,7 @@
>               case '-':                       /* obsolete */
>               case 'i':
>                       if ((environ = calloc(1, sizeof(char *))) == NULL)
> -                             err(126, "calloc");
> +                             err(125, "calloc");
>                       break;
>               default:
>                       usage();
> @@ -65,8 +65,7 @@
>       for (; *argv && (p = strchr(*argv, '=')); ++argv) {
>               *p++ = '\0';
>               if (setenv(*argv, p, 1) == -1) {
> -                     /* reuse 126, it matches the problem most */
> -                     exit(126);
> +                     err(125, "setenv");
>               }
>       }

Reply via email to