>From 58ef9c2d18f3c158ff42cd3b7297f9e9bbc74738 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 26 Dec 2020 14:31:50 +0100 Subject: [PATCH 08/15] execv: New module. * lib/execv.c: New file. * m4/execv.m4: New file. * modules/execv: New file. * doc/posix-functions/execv.texi: Mention more Windows problems and the new module. --- ChangeLog | 7 +++++++ doc/posix-functions/execv.texi | 21 ++++++++++++++++----- lib/execv.c | 35 +++++++++++++++++++++++++++++++++++ m4/execv.m4 | 15 +++++++++++++++ modules/execv | 29 +++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 lib/execv.c create mode 100644 m4/execv.m4 create mode 100644 modules/execv diff --git a/ChangeLog b/ChangeLog index f7a0650..836a115 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2020-12-26 Bruno Haible + execv: New module. + * lib/execv.c: New file. + * m4/execv.m4: New file. + * modules/execv: New file. + * doc/posix-functions/execv.texi: Mention more Windows problems and the + new module. + execvp: Add tests. * tests/test-execvp-main.c: New file. * tests/test-execvp.sh: New file. diff --git a/doc/posix-functions/execv.texi b/doc/posix-functions/execv.texi index c18fce4..9dbea90 100644 --- a/doc/posix-functions/execv.texi +++ b/doc/posix-functions/execv.texi @@ -4,19 +4,30 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/execv.html} -Gnulib module: --- +Gnulib module: execv 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 +Note: The Gnulib replacement for this function is not async-safe, that is, +it must not be invoked from a signal handler. + Portability problems not fixed by Gnulib: @itemize @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/execv.c b/lib/execv.c new file mode 100644 index 0000000..d5c88a0 --- /dev/null +++ b/lib/execv.c @@ -0,0 +1,35 @@ +/* execv() 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 +execv (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 execve (program, argv, environ); +} diff --git a/m4/execv.m4 b/m4/execv.m4 new file mode 100644 index 0000000..8064482 --- /dev/null +++ b/m4/execv.m4 @@ -0,0 +1,15 @@ +# execv.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_EXECV], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + case "$host_os" in + mingw*) REPLACE_EXECV=1 ;; + esac +]) diff --git a/modules/execv b/modules/execv new file mode 100644 index 0000000..db64abb --- /dev/null +++ b/modules/execv @@ -0,0 +1,29 @@ +Description: +execv() function: Execute a program, replacing the current process. + +Files: +lib/execv.c +m4/execv.m4 + +Depends-on: +unistd +environ [test $REPLACE_EXECV = 1] +execve [test $REPLACE_EXECV = 1] + +configure.ac: +gl_FUNC_EXECV +if test $REPLACE_EXECV = 1; then + AC_LIBOBJ([execv]) +fi +gl_UNISTD_MODULE_INDICATOR([execv]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +all -- 2.7.4