Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add execvpe, execlpe (reviewed by phone)



details:   https://anonhg.NetBSD.org/src/rev/1ee8e21c4b72
branches:  trunk
changeset: 332539:1ee8e21c4b72
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 26 19:28:03 2014 +0000

description:
add execvpe, execlpe (reviewed by phone)

diffstat:

 include/unistd.h             |   4 ++-
 lib/libc/gen/Makefile.inc    |   6 ++--
 lib/libc/gen/exec.3          |  48 +++++++++++++++++++++++++++++++++-----------
 lib/libc/gen/execlp.c        |  32 ++++++++++++++++++++++++++--
 lib/libc/gen/execvp.c        |  21 ++++++++++++------
 lib/libc/include/namespace.h |   4 ++-
 lib/libc/shlib_version       |   4 +-
 7 files changed, 90 insertions(+), 29 deletions(-)

diffs (truncated from 336 to 300 lines):

diff -r 44ceb351ac73 -r 1ee8e21c4b72 include/unistd.h
--- a/include/unistd.h  Fri Sep 26 19:27:05 2014 +0000
+++ b/include/unistd.h  Fri Sep 26 19:28:03 2014 +0000
@@ -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     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);
diff -r 44ceb351ac73 -r 1ee8e21c4b72 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Fri Sep 26 19:27:05 2014 +0000
+++ b/lib/libc/gen/Makefile.inc Fri Sep 26 19:28:03 2014 +0000
@@ -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+=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 \
diff -r 44ceb351ac73 -r 1ee8e21c4b72 lib/libc/gen/exec.3
--- a/lib/libc/gen/exec.3       Fri Sep 26 19:27:05 2014 +0000
+++ b/lib/libc/gen/exec.3       Fri Sep 26 19:28:03 2014 +0000
@@ -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 @@
 and subsequent ellipses in the
 .Fn execl ,
 .Fn execlp ,
+.Fn execlpe ,
 and
 .Fn execle
 functions can be thought of as
@@ -100,8 +105,9 @@
 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 @@
 Some of these functions have special semantics.
 .Pp
 The functions
-.Fn execlp
+.Fn execlp ,
+.Fn execlpe ,
+.Fn execvp
 and
-.Fn execvp
+.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 @@
 .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 @@
 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 @@
 .Sh ERRORS
 .Fn execl ,
 .Fn execle ,
-.Fn execlp
+.Fn execlp ,
+.Fn execlpe ,
+.Fn execvp
 and
-.Fn execvp
+.Fn execvpe
 may fail and set
 .Va errno
 for any of the errors specified for the library functions
@@ -260,3 +276,11 @@
 .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.
diff -r 44ceb351ac73 -r 1ee8e21c4b72 lib/libc/gen/execlp.c
--- a/lib/libc/gen/execlp.c     Fri Sep 26 19:27:05 2014 +0000
+++ b/lib/libc/gen/execlp.c     Fri Sep 26 19:28:03 2014 +0000
@@ -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 @@
 #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 @@
 {
        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 @@
        
        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);
+}
diff -r 44ceb351ac73 -r 1ee8e21c4b72 lib/libc/gen/execvp.c
--- a/lib/libc/gen/execvp.c     Fri Sep 26 19:27:05 2014 +0000
+++ b/lib/libc/gen/execvp.c     Fri Sep 26 19:28:03 2014 +0000
@@ -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 @@
 
 #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 @@
                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 @@
                        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 @@
 done:
        return (-1);
 }
+
+extern char **environ;
+
+int
+execvp(const char *name, char * const *argv)
+{
+       return execvpe(name, argv, environ);



Home | Main Index | Thread Index | Old Index