summaryrefslogtreecommitdiff
path: root/usr.bin/env
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-09-15 07:13:52 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-09-15 07:13:52 +0000
commit42a3e69c05af72afbc1d37574fba7729b828289b (patch)
treebecf08be7a11e201542de4de93b8cd0f8650f9e1 /usr.bin/env
parentb74ef7bac5077f29fc1c12e8b5ccaf0e2f1f8fdc (diff)
check return value for setenv(3) for failure, and deal appropriately
Diffstat (limited to 'usr.bin/env')
-rw-r--r--usr.bin/env/env.17
-rw-r--r--usr.bin/env/env.c25
2 files changed, 18 insertions, 14 deletions
diff --git a/usr.bin/env/env.1 b/usr.bin/env/env.1
index 2e24aaf0a31..5f1ac9f5531 100644
--- a/usr.bin/env/env.1
+++ b/usr.bin/env/env.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: env.1,v 1.6 2000/03/05 20:09:22 aaron Exp $
+.\" $OpenBSD: env.1,v 1.7 2000/09/15 07:13:48 deraadt Exp $
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" All rights reserved.
.\"
@@ -96,9 +96,8 @@ The
.Nm
utility completed successfully.
.It 1-125
-An error occurred in the
-.Nm
-utility.
+The exit code returned from the
+.Ar utility.
.It 126
The utility specified by
.Ar utility
diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c
index 087fbba09dc..2180a82617c 100644
--- a/usr.bin/env/env.c
+++ b/usr.bin/env/env.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $ */
+/* $OpenBSD: env.c,v 1.5 2000/09/15 07:13:48 deraadt Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/
-static char rcsid[] = "$OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: env.c,v 1.5 2000/09/15 07:13:48 deraadt Exp $";
#endif /* not lint */
#include <err.h>
@@ -52,7 +52,7 @@ static char rcsid[] = "$OpenBSD: env.c,v 1.4 1997/06/20 04:54:59 deraadt Exp $";
#include <locale.h>
#include <errno.h>
-static void usage __P((void));
+void usage __P((void));
int
main(argc, argv)
@@ -71,7 +71,7 @@ main(argc, argv)
case '-': /* obsolete */
case 'i':
if ((environ = (char **)calloc(1, sizeof(char *))) == NULL)
- err(1, "calloc");
+ err(126, "calloc");
break;
case '?':
default:
@@ -79,12 +79,17 @@ main(argc, argv)
}
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
- (void)setenv(*argv, ++p, 1);
+ if (setenv(*argv, ++p, 1) == -1) {
+ /* reuse 126, it matches the problem most */
+ exit(126);
+ }
if (*argv) {
- /* return 127 if the command to be run could not be found; 126
- if the command was was found but could not be invoked */
-
+ /*
+ * return 127 if the command to be run could not be
+ * found; 126 if the command was found but could
+ * not be invoked
+ */
execvp(*argv, argv);
err((errno == ENOENT) ? 127 : 126, "%s", *argv);
/* NOTREACHED */
@@ -96,8 +101,8 @@ main(argc, argv)
exit(0);
}
-static void
-usage ()
+void
+usage()
{
(void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n");
exit (1);