]> Savannah Git Hosting - gnulib.git/commitdiff
execv: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2020 13:31:50 +0000 (14:31 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2020 13:31:50 +0000 (14:31 +0100)
* 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
doc/posix-functions/execv.texi
lib/execv.c [new file with mode: 0644]
m4/execv.m4 [new file with mode: 0644]
modules/execv [new file with mode: 0644]

index f7a06505069ab889fc372de82d96bea0ce9fe47b..836a1154c759f65f97fda0f721cec2575d1430dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-12-26  Bruno Haible  <bruno@clisp.org>
 
+       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.
index c18fce4c188a6a7d1efd0f1b7ae02bcb3b52fe3f..9dbea90f514e12c678e2186f427d00fb10398aa2 100644 (file)
@@ -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 (file)
index 0000000..d5c88a0
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+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 (file)
index 0000000..8064482
--- /dev/null
@@ -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 (file)
index 0000000..db64abb
--- /dev/null
@@ -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:
+<unistd.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all