Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Feb 2002 13:59:35 +1100
From:      Tim Robbins <tim@robbins.dropbear.id.au>
To:        freebsd-standards@FreeBSD.ORG
Subject:   env(1) and P1003.2-1992 conformance
Message-ID:  <20020213135934.A4228@descent.robbins.dropbear.id.au>

next in thread | raw e-mail | index | archive | help
Here is a patch that corrects the exit status of the env utility to make
it compatible with P1003.2-1992. OpenBSD and NetBSD exit with the right
status (see NetBSD env.c revision 1.2 from 1993), FreeBSD does not.
This really is a trivial change.


Tim


Index: env/env.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/env/env.c,v
retrieving revision 1.5
diff -u -r1.5 env.c
--- env/env.c	1999/08/27 08:59:31	1.5
+++ env/env.c	2002/02/13 02:50:49
@@ -42,6 +42,7 @@
 #endif /* not lint */
 
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -75,7 +76,7 @@
 		(void)setenv(*argv, ++p, 1);
 	if (*argv) {
 		execvp(*argv, argv);
-		err(1, "%s", *argv);
+		err(errno == ENOENT ? 127 : 126, "%s", *argv);
 	}
 	for (ep = environ; *ep; ep++)
 		(void)printf("%s\n", *ep);


Index: printenv/printenv.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/printenv/printenv.1,v
retrieving revision 1.11
diff -u -r1.11 printenv.1
--- printenv/printenv.1	2001/07/05 06:35:03	1.11
+++ printenv/printenv.1	2002/02/13 02:51:01
@@ -57,12 +57,6 @@
 is specified, only
 its value is printed.
 .Pp
-If a
-.Ar name
-is specified and it is not defined in the environment,
-.Nm
-returns exit status 1, else it returns status 0.
-.Pp
 Some shells may provide a builtin
 .Nm
 command which is similar or identical to this utility.
@@ -122,11 +116,24 @@
 .Pa foo
 without the path,
 as well as set up the environment as desired.
+.Sh DIAGNOSTICS
+.Ex -std printenv
+.Pp
+.Ex -std env
+The
+.Nm env
+utility exits 126 if the requested utility was found but
+could not be executed and 127 if the utility could not be found.
 .Sh SEE ALSO
 .Xr csh 1 ,
 .Xr sh 1 ,
 .Xr execvp 3 ,
 .Xr environ 7
+.Sh STANDARDS
+The
+.Nm env
+utility is expected to be compatible with
+.St -p1003.2-92 .
 .Sh HISTORY
 The
 .Nm

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020213135934.A4228>