Skip to content

Commit

Permalink
libc: expose execvpe for Linux compat
Browse files Browse the repository at this point in the history
PR:		275370

(cherry picked from commit 8ccd0b8)
  • Loading branch information
brooksdavis authored and kostikbel committed Feb 18, 2024
1 parent 2d12098 commit 0667d0e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions cddl/lib/libzfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
CFLAGS+= -DHAVE_ISSETUGID
CFLAGS+= -DHAVE_EXECVPE
CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
CFLAGS+= -DSYSCONFDIR=\"/etc\"
CFLAGS+= -DPKGDATADIR=\"/usr/share/zfs\"
Expand Down
2 changes: 1 addition & 1 deletion cddl/usr.sbin/zfsd/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
CFLAGS+= -I${SRCTOP}/cddl/usr.sbin

# use issetugid(2)
CFLAGS+= -DHAVE_ISSETUGID
CFLAGS+= -DHAVE_EXECVPE

LIBADD+= devdctl zfs util geom bsdxml sbuf nvpair avl uutil zutil

Expand Down
1 change: 1 addition & 0 deletions include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ int eaccess(const char *, int);
void endusershell(void);
int exect(const char *, char * const *, char * const *);
int execvP(const char *, const char *, char * const *);
int execvpe(const char *, char * const *, char * const *);
int feature_present(const char *);
char *fflagstostr(u_long);
int getdomainname(char *, int);
Expand Down
4 changes: 4 additions & 0 deletions lib/libc/gen/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ FBSD_1.7 {
__cpuset_free;
};

FBSD_1.8 {
execvpe;
};

FBSDprivate_1.0 {
/* needed by thread libraries */
__thr_jtable;
Expand Down
26 changes: 20 additions & 6 deletions lib/libc/gen/exec.3
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)exec.3 8.3 (Berkeley) 1/24/94
.\"
.Dd March 22, 2020
.Dd December 11, 2023
.Dt EXEC 3
.Os
.Sh NAME
Expand All @@ -37,6 +35,7 @@
.Nm exect ,
.Nm execv ,
.Nm execvp ,
.Nm execvpe ,
.Nm execvP
.Nd execute a file
.Sh LIBRARY
Expand All @@ -58,6 +57,8 @@
.Ft int
.Fn execvp "const char *file" "char *const argv[]"
.Ft int
.Fn execvpe "const char *file" "char *const argv[]" "char *const envp[]"
.Ft int
.Fn execvP "const char *file" "const char *search_path" "char *const argv[]"
.Sh DESCRIPTION
The
Expand Down Expand Up @@ -99,6 +100,7 @@ The
.Fn exect ,
.Fn execv ,
.Fn execvp ,
.Fn execvpe ,
and
.Fn execvP
functions provide an array of pointers to null-terminated strings that
Expand All @@ -112,9 +114,10 @@ be terminated by a
pointer.
.Pp
The
.Fn execle
.Fn execle ,
.Fn exect ,
and
.Fn exect
.Fn execvpe
functions also specify the environment of the executed process by following
the
.Dv NULL
Expand All @@ -136,6 +139,7 @@ Some of these functions have special semantics.
The functions
.Fn execlp ,
.Fn execvp ,
.Fn execvpe ,
and
.Fn execvP
will duplicate the actions of the shell in searching for an executable file
Expand All @@ -146,6 +150,7 @@ For
.Fn execlp
and
.Fn execvp ,
.Fn execvpe ,
search path is the path specified in the environment by
.Dq Ev PATH
variable.
Expand Down Expand Up @@ -271,7 +276,8 @@ The
.Fn execl ,
.Fn execle ,
.Fn execlp ,
.Fn execvp
.Fn execvp ,
.Fn execvpe ,
and
.Fn execvP
functions
Expand Down Expand Up @@ -309,6 +315,9 @@ and
functions
conform to
.St -p1003.1-88 .
The
.Fn execvpe
function is a GNU extension.
.Sh HISTORY
The
.Fn exec
Expand All @@ -332,6 +341,10 @@ The
.Fn execvP
function first appeared in
.Fx 5.2 .
The
.Fn execvpe
function first appeared in
.Fx 15.0 .
.Sh BUGS
The type of the
.Fa argv
Expand All @@ -342,6 +355,7 @@ parameters to
.Fn exect ,
.Fn execv ,
.Fn execvp ,
.Fn execvpe ,
and
.Fn execvP
is a historical accident and no sane implementation should modify the provided
Expand Down
4 changes: 2 additions & 2 deletions lib/libc/gen/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ execv(const char *name, char * const *argv)
int
execvp(const char *name, char * const *argv)
{
return (_execvpe(name, argv, environ));
return (execvpe(name, argv, environ));
}

static int
Expand Down Expand Up @@ -290,7 +290,7 @@ execvP(const char *name, const char *path, char * const argv[])
}

int
_execvpe(const char *name, char * const argv[], char * const envp[])
execvpe(const char *name, char * const argv[], char * const envp[])
{
const char *path;

Expand Down
4 changes: 2 additions & 2 deletions lib/libc/gen/posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ struct posix_spawn_args {
#if defined(__i386__) || defined(__amd64__)
/*
* Below we'll assume that _RFORK_THREAD_STACK_SIZE is appropriately aligned for
* the posix_spawn() case where we do not end up calling _execvpe and won't ever
* the posix_spawn() case where we do not end up calling execvpe and won't ever
* try to allocate space on the stack for argv[].
*/
#define _RFORK_THREAD_STACK_SIZE 4096
Expand All @@ -253,7 +253,7 @@ _posix_spawn_thr(void *data)
}
envp = psa->envp != NULL ? psa->envp : environ;
if (psa->use_env_path)
_execvpe(psa->path, psa->argv, envp);
execvpe(psa->path, psa->argv, envp);
else
_execve(psa->path, psa->argv, envp);
psa->error = errno;
Expand Down
3 changes: 0 additions & 3 deletions lib/libc/include/libc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,6 @@ int __sys_futimens(int fd, const struct timespec *times) __hidden;
int __sys_utimensat(int fd, const char *path,
const struct timespec *times, int flag) __hidden;

/* execve() with PATH processing to implement posix_spawnp() */
int _execvpe(const char *, char * const *, char * const *);

int _elf_aux_info(int aux, void *buf, int buflen);
struct dl_phdr_info;
int __elf_phdr_match_addr(struct dl_phdr_info *, void *);
Expand Down

0 comments on commit 0667d0e

Please sign in to comment.