Hi Ingo,

Thanks for taking a look.

> > 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 think the man page is bit confusing. Note that I sent jmc@ the patch 
below for the man page to try to clear things up a bit there as well. The 
main point is that 1-125 is an error range reserved for any errors that 
happens within env itself.

However the entire range of exit codes is _REUSED_ in the case that 
utility was (1) specified, (2) successfully located and (3) succesfully 
invoked. In that case, the return code from env is whatever the underlying 
utility returns.

But as I said, any errors in env itself (as opposed to the underlying 
utility) should be in the range 1-125 (at least that's my reading of 
posix).

In particular, think about the case when utility is not specified at all.
I don't think it would make sense to return 126 in that case.

> 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.

Unfortunately, the exit codes are already ambiguous. What happens when 1 
is returned? Was this from the underlying utility that exited with return 
code 1 or did I specify something incorrectly on the command-line? (Note 
my addition to the BUGS section in my patch below).

  # cat ./test.sh
  #!/bin/sh
  exit 1
  # env ./test.sh
  # echo $?
  1
  # env -t
  env: unknown option -- t
  usage: env [-i] [name=value ...] [utility [argument ...]]
  # echo $?
  1

In any case, patch to env.1 man page follows as well in case you have some 
feedback there as well.


Index: env.1
===================================================================
RCS file: /usr/cvs/src/usr.bin/env/env.1,v
retrieving revision 1.17
diff -u -r1.17 env.1
--- env.1       8 Feb 2009 17:15:09 -0000       1.17
+++ env.1       22 Jul 2010 20:30:20 -0000
@@ -76,27 +76,25 @@
 of the variables in the environment, with one
 .Ar name Ns = Ns Ar value
 pair per line.
-.Sh DIAGNOSTICS
+.Pp
+If
+.Ar utility
+is specified and was successfully invoked, the exit code returned by
 .Nm
-exits with one of the following values:
-.Bl -tag -width Ds
+is the exit code of
+.Ar utility .
+.Pp
+Otherwise, the
+.Nm
+utility exits with one of the following values:
+.Bl -tag -width Ds -compact -offset indent
 .It 0
-.Ar utility
-was invoked and completed successfully.
-In this case the exit code is returned by the utility itself, not
-.Nm .
-If no utility was specified, then
-.Nm
-completed successfully and returned the exit code itself.
-.It 1
-An invalid command line option was passed to
-.Nm .
+.Nm
+completed successfully.
 .It 1\(en125
-.Ar 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
-.Nm .
+An error occurred in the
+.Nm
+utility.
 .It 126
 .Ar utility
 was found but could not be invoked.
@@ -123,3 +121,8 @@
 .Pq Sq =
 signs in their
 names, for obvious reasons.
+.Pp
+There is no way to determine whether an exit code was returned by
+.Nm
+or by the underlying
+.Ar utility .

Reply via email to