>From 0e3778b00c4e4705cccec9261ef36c66c400e1fe Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 26 Dec 2020 14:28:16 +0100 Subject: [PATCH 06/15] execvp: New module. * lib/execvp.c: New file. * m4/execvp.m4: New file. * modules/execvp: New file. * doc/posix-functions/execvp.texi: Mention more Windows problems and the new module. --- ChangeLog | 7 +++++++ doc/posix-functions/execvp.texi | 18 +++++++++++++----- lib/execvp.c | 35 +++++++++++++++++++++++++++++++++++ m4/execvp.m4 | 15 +++++++++++++++ modules/execvp | 29 +++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 lib/execvp.c create mode 100644 m4/execvp.m4 create mode 100644 modules/execvp diff --git a/ChangeLog b/ChangeLog index 1f9acd2..5d20495 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2020-12-26 Bruno Haible + execvp: New module. + * lib/execvp.c: New file. + * m4/execvp.m4: New file. + * modules/execvp: New file. + * doc/posix-functions/execvp.texi: Mention more Windows problems and the + new module. + execvpe: Add tests. * tests/test-execvpe-main.c: New file. * tests/test-execvpe.sh: New file. diff --git a/doc/posix-functions/execvp.texi b/doc/posix-functions/execvp.texi index 24a3f06..0c242b2 100644 --- a/doc/posix-functions/execvp.texi +++ b/doc/posix-functions/execvp.texi @@ -4,10 +4,22 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/execvp.html} -Gnulib module: --- +Gnulib module: execvp Portability problems fixed by Gnulib: @itemize +@item +On Windows platforms (excluding Cygwin), this function does not pass +command-line arguments correctly if they contain space, tab, backslash, +or double-quote characters. +@item +On Windows platforms (excluding Cygwin), this function spawns an asynchronous +child process and then exits the current process immediately. As a +consequence, the parent of the current process 1. may incorrectly proceed +as if its child had exited, and 2. will never see the child's exit status. +@item +On Windows platforms (excluding Cygwin), the return type of this function is +@code{intptr_t}, not @code{int}. @end itemize Portability problems not fixed by Gnulib: @@ -15,8 +27,4 @@ Portability problems not fixed by Gnulib: @item On some platforms, a script without executable permission is still run: Cygwin 1.5.x. -@item -On Windows platforms (excluding Cygwin), this function operates by spawning -and then by exiting the current process, which means the current -process's parent may incorrectly proceed as if its child had exited. @end itemize diff --git a/lib/execvp.c b/lib/execvp.c new file mode 100644 index 0000000..db0fcb7 --- /dev/null +++ b/lib/execvp.c @@ -0,0 +1,35 @@ +/* execvp() function: Execute a program, replacing the current process. + Copyright (C) 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2020. */ + +#include + +/* Specification. */ +#include + +int +execvp (const char *program, char * const *argv) +{ + /* Pass the environment explicitly. This is needed if the program has + modified the environment using putenv() or [un]setenv(). On Windows, + processes have two environments, one in the "environment block" of the + process and managed through SetEnvironmentVariable(), and one inside the + process, in the location retrieved by the 'environ' macro. If we were + to pass NULL, the child process would inherit a copy of the environment + block - ignoring the effects of putenv() and [un]setenv(). */ + return execvpe (program, argv, environ); +} diff --git a/m4/execvp.m4 b/m4/execvp.m4 new file mode 100644 index 0000000..833b987 --- /dev/null +++ b/m4/execvp.m4 @@ -0,0 +1,15 @@ +# execvp.m4 serial 1 +dnl Copyright (C) 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_EXECVP], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + case "$host_os" in + mingw*) REPLACE_EXECVP=1 ;; + esac +]) diff --git a/modules/execvp b/modules/execvp new file mode 100644 index 0000000..df2d313 --- /dev/null +++ b/modules/execvp @@ -0,0 +1,29 @@ +Description: +execvp() function: Execute a program, replacing the current process. + +Files: +lib/execvp.c +m4/execvp.m4 + +Depends-on: +unistd +environ [test $REPLACE_EXECVP = 1] +execvpe [test $REPLACE_EXECVP = 1] + +configure.ac: +gl_FUNC_EXECVP +if test $REPLACE_EXECVP = 1; then + AC_LIBOBJ([execvp]) +fi +gl_UNISTD_MODULE_INDICATOR([execvp]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +all -- 2.7.4