Module Name: src
Committed By: christos
Date: Fri Sep 26 19:28:03 UTC 2014
Modified Files:
src/include: unistd.h
src/lib/libc: shlib_version
src/lib/libc/gen: Makefile.inc exec.3 execlp.c execvp.c
src/lib/libc/include: namespace.h
Log Message:
add execvpe, execlpe (reviewed by phone)
To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/include/unistd.h
cvs rdiff -u -r1.255 -r1.256 src/lib/libc/shlib_version
cvs rdiff -u -r1.188 -r1.189 src/lib/libc/gen/Makefile.inc
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/gen/exec.3
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/gen/execlp.c
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/gen/execvp.c
cvs rdiff -u -r1.175 -r1.176 src/lib/libc/include/namespace.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/include/unistd.h
diff -u src/include/unistd.h:1.142 src/include/unistd.h:1.143
--- src/include/unistd.h:1.142 Fri Jul 25 04:30:47 2014
+++ src/include/unistd.h Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: unistd.h,v 1.142 2014/07/25 08:30:47 dholland Exp $ */
+/* $NetBSD: unistd.h,v 1.143 2014/09/26 19:28:03 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -328,6 +328,8 @@ int des_setkey(const char *);
int dup3(int, int, int);
void endusershell(void);
int exect(const char *, char * const *, char * const *);
+int execvpe(const char *, char * const *, char * const *);
+int execlpe(const char *, const char *, ...);
int fchroot(int);
int fdiscard(int, off_t, off_t);
int fsync_range(int, int, off_t, off_t);
Index: src/lib/libc/shlib_version
diff -u src/lib/libc/shlib_version:1.255 src/lib/libc/shlib_version:1.256
--- src/lib/libc/shlib_version:1.255 Wed Sep 24 14:16:37 2014
+++ src/lib/libc/shlib_version Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.255 2014/09/24 18:16:37 christos Exp $
+# $NetBSD: shlib_version,v 1.256 2014/09/26 19:28:03 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@@ -42,4 +42,4 @@
# - move gethostbyname to a compat library
# - remove arc4random(3) API
major=12
-minor=194
+minor=195
Index: src/lib/libc/gen/Makefile.inc
diff -u src/lib/libc/gen/Makefile.inc:1.188 src/lib/libc/gen/Makefile.inc:1.189
--- src/lib/libc/gen/Makefile.inc:1.188 Fri Jun 13 11:45:05 2014
+++ src/lib/libc/gen/Makefile.inc Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.188 2014/06/13 15:45:05 joerg Exp $
+# $NetBSD: Makefile.inc,v 1.189 2014/09/26 19:28:03 christos Exp $
# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
# gen sources
@@ -94,8 +94,8 @@ MLINKS+=endutxent.3 getutxent.3 endutxen
MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \
err.3 warnx.3 err.3 vwarnx.3 err.3 errc.3 err.3 verrc.3 err.3 warnc.3 \
err.3 vwarnc.3
-MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
- exec.3 execvp.3 exec.3 exect.3
+MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execlpe.3 \
+ exec.3 execv.3 exec.3 execvp.3 exec.3 execvpe.3 exec.3 exect.3
MLINKS+=extattr_namespace_to_string.3 extattr_string_to_namespace.3 \
extattr_copy_file.3 extattr_copy_fd.3 \
extattr_copy_file.3 extattr_copy_link.3 \
Index: src/lib/libc/gen/exec.3
diff -u src/lib/libc/gen/exec.3:1.22 src/lib/libc/gen/exec.3:1.23
--- src/lib/libc/gen/exec.3:1.22 Thu Nov 22 11:19:49 2012
+++ src/lib/libc/gen/exec.3 Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-.\" $NetBSD: exec.3,v 1.22 2012/11/22 16:19:49 abs Exp $
+.\" $NetBSD: exec.3,v 1.23 2014/09/26 19:28:03 christos Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)exec.3 8.3 (Berkeley) 1/24/94
.\"
-.Dd May 6, 2005
+.Dd September 26, 2014
.Dt EXEC 3
.Os
.Sh NAME
@@ -50,6 +50,8 @@
.Ft int
.Fn execlp "const char *file" "const char *arg" ...
.Ft int
+.Fn execlpe "const char *path" "const char *arg" ... "char *const envp[]"
+.Ft int
.Fn execle "const char *path" "const char *arg" ... "char *const envp[]"
.Ft int
.Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
@@ -57,6 +59,8 @@
.Fn execv "const char *path" "char *const argv[]"
.Ft int
.Fn execvp "const char *file" "char *const argv[]"
+.Ft int
+.Fn execvpe "const char *file" "char *const argv[], char *const envp[]"
.Sh DESCRIPTION
The
.Fn exec
@@ -80,6 +84,7 @@ The
and subsequent ellipses in the
.Fn execl ,
.Fn execlp ,
+.Fn execlpe ,
and
.Fn execle
functions can be thought of as
@@ -100,8 +105,9 @@ pointer.
The
.Fn exect ,
.Fn execv ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvpe
functions provide an array of pointers to null-terminated strings that
represent the argument list available to the new program.
The first argument, by convention, should point to the file name associated
@@ -135,9 +141,11 @@ in the current process.
Some of these functions have special semantics.
.Pp
The functions
-.Fn execlp
-and
+.Fn execlp ,
+.Fn execlpe ,
.Fn execvp
+and
+.Fn execvpe
will duplicate the actions of the shell in searching for an executable file
if the specified file name does not contain a slash
.Dq Li \&/
@@ -198,16 +206,20 @@ The shell.
.Sh COMPATIBILITY
Historically, the default path for the
.Fn execlp
+.Fn execlpe ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvpe
functions was
.Dq Pa :/bin:/usr/bin .
This was changed to improve security and behaviour.
.Pp
The behavior of
-.Fn execlp
+.Fn execlp ,
+.Fn execlpe ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvpe
when errors occur while attempting to execute the file is historic
practice, but has not traditionally been documented and is not specified
by the
@@ -215,9 +227,11 @@ by the
standard.
.Pp
Traditionally, the functions
-.Fn execlp
+.Fn execlp ,
+.Fn execlpe ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvpe
ignored all errors except for the ones described above and
.Er ENOMEM
and
@@ -227,9 +241,11 @@ They now return if any error other than
.Sh ERRORS
.Fn execl ,
.Fn execle ,
-.Fn execlp
-and
+.Fn execlp ,
+.Fn execlpe ,
.Fn execvp
+and
+.Fn execvpe
may fail and set
.Va errno
for any of the errors specified for the library functions
@@ -260,3 +276,11 @@ and
.Fn execvp
conform to
.St -p1003.1-90 .
+.Pp
+The
+.Fn execlpe
+function appeared first in QNX and the
+.Fn execvpe
+is on both
+.Lx
+and QNX.
Index: src/lib/libc/gen/execlp.c
diff -u src/lib/libc/gen/execlp.c:1.12 src/lib/libc/gen/execlp.c:1.13
--- src/lib/libc/gen/execlp.c:1.12 Thu Jun 30 15:46:07 2011
+++ src/lib/libc/gen/execlp.c Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: execlp.c,v 1.12 2011/06/30 19:46:07 joerg Exp $ */
+/* $NetBSD: execlp.c,v 1.13 2014/09/26 19:28:03 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: execlp.c,v 1.12 2011/06/30 19:46:07 joerg Exp $");
+__RCSID("$NetBSD: execlp.c,v 1.13 2014/09/26 19:28:03 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -42,9 +42,11 @@ __RCSID("$NetBSD: execlp.c,v 1.12 2011/0
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
#ifdef __weak_alias
__weak_alias(execlp,_execlp)
+__weak_alias(execlpe,_execlpe)
#endif
int
@@ -52,7 +54,7 @@ execlp(const char *name, const char *arg
{
va_list ap;
char **argv;
- int i;
+ size_t i;
va_start(ap, arg);
for (i = 2; va_arg(ap, char *) != NULL; i++)
@@ -69,3 +71,27 @@ execlp(const char *name, const char *arg
return execvp(name, argv);
}
+
+int
+execlpe(const char *name, const char *arg, ...)
+{
+ va_list ap;
+ char **argv, **envp;
+ size_t i;
+
+ va_start(ap, arg);
+ for (i = 2; va_arg(ap, char *) != NULL; i++)
+ continue;
+ va_end(ap);
+
+ argv = alloca(i * sizeof (char *));
+
+ va_start(ap, arg);
+ argv[0] = __UNCONST(arg);
+ for (i = 1; (argv[i] = va_arg(ap, char *)) != NULL; i++)
+ continue;
+ envp = va_arg(ap, char **);
+ va_end(ap);
+
+ return execvpe(name, argv, envp);
+}
Index: src/lib/libc/gen/execvp.c
diff -u src/lib/libc/gen/execvp.c:1.30 src/lib/libc/gen/execvp.c:1.31
--- src/lib/libc/gen/execvp.c:1.30 Fri Jul 20 08:41:07 2007
+++ src/lib/libc/gen/execvp.c Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: execvp.c,v 1.30 2007/07/20 12:41:07 yamt Exp $ */
+/* $NetBSD: execvp.c,v 1.31 2014/09/26 19:28:03 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: execvp.c,v 1.30 2007/07/20 12:41:07 yamt Exp $");
+__RCSID("$NetBSD: execvp.c,v 1.31 2014/09/26 19:28:03 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -51,12 +51,11 @@ __RCSID("$NetBSD: execvp.c,v 1.30 2007/0
#ifdef __weak_alias
__weak_alias(execvp,_execvp)
+__weak_alias(execvpe,_execvpe)
#endif
-extern char **environ;
-
int
-execvp(const char *name, char * const *argv)
+execvpe(const char *name, char * const *argv, char * const * envp)
{
const char **memp;
int cnt;
@@ -116,7 +115,7 @@ execvp(const char *name, char * const *a
memcpy(buf + lp + 1, name, ln);
buf[lp + ln + 1] = '\0';
-retry: (void)execve(bp, argv, environ);
+retry: (void)execve(bp, argv, envp);
switch (errno) {
case EACCES:
eacces = 1;
@@ -136,7 +135,7 @@ retry: (void)execve(bp, argv, environ);
memp[0] = _PATH_BSHELL;
memp[1] = bp;
(void)memcpy(&memp[2], &argv[1], cnt * sizeof(*memp));
- (void)execve(_PATH_BSHELL, __UNCONST(memp), environ);
+ (void)execve(_PATH_BSHELL, __UNCONST(memp), envp);
goto done;
case ETXTBSY:
if (etxtbsy < 3)
@@ -153,3 +152,11 @@ retry: (void)execve(bp, argv, environ);
done:
return (-1);
}
+
+extern char **environ;
+
+int
+execvp(const char *name, char * const *argv)
+{
+ return execvpe(name, argv, environ);
+}
Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.175 src/lib/libc/include/namespace.h:1.176
--- src/lib/libc/include/namespace.h:1.175 Thu Sep 25 11:08:29 2014
+++ src/lib/libc/include/namespace.h Fri Sep 26 15:28:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.175 2014/09/25 15:08:29 manu Exp $ */
+/* $NetBSD: namespace.h,v 1.176 2014/09/26 19:28:03 christos Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -278,8 +278,10 @@
#define execl _execl
#define execle _execle
#define execlp _execlp
+#define execlpe _execlpe
#define execv _execv
#define execvp _execvp
+#define execvpe _execvpe
#define explicit_memset _explicit_memset
#define fdiscard _fdiscard
#define fdopen _fdopen