diff options
author | Bruno Haible <bruno@clisp.org> | 2020-11-30 17:58:57 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-11-30 17:58:57 +0100 |
commit | c5388bad32e897c410336d6a3d8258cea2e9a6ad (patch) | |
tree | 2071f5a38cc34eacc334bc2d4ad513bc14acbb9e /lib/windows-spawn.h | |
parent | c48f7d3e9dae0d7649ebf589d5202e997a89ac42 (diff) | |
download | gnulib-c5388bad32e897c410336d6a3d8258cea2e9a6ad.tar.gz |
execute, spawn-pipe: Make multithread-safe on native Windows.
* lib/windows-spawn.h: Include <stdint.h>, <windows.h>.
(dup_safer_noinherit, undup_safer_noinherit): Remove declarations.
(spawnpvech): New declaration.
* lib/windows-spawn.c: Include <stdio.h>, <process.h>, findprog.h.
Don't include <unistd.h>, cloexec.h, error.h, gettext.h.
(_): Remove macro.
(dup_noinherit, fd_safer_noinherit, dup_safer_noinherit,
undup_safer_noinherit): Remove functions.
(spawnpvech): New function.
* modules/windows-spawn (Depends-on): Add findprog-in, stdint. Remove
cloexec, dup2, error, gettext-h.
* lib/execute.c: Include msvc-nothrow.h.
(execute) [WIN32]: Use _get_osfhandle, spawnpvech instead of _spawnvpe.
* lib/spawn-pipe.c: Include msvc-nothrow.h.
(create_pipe) [WIN32]: Use _get_osfhandle, DuplicateHandle, spawnpvech
instead of _spawnvpe.
* modules/execute (Depends-on): Add msvc-nothrow.
* modules/spawn-pipe (Depends-on): Likewise.
Diffstat (limited to 'lib/windows-spawn.h')
-rw-r--r-- | lib/windows-spawn.h | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/windows-spawn.h b/lib/windows-spawn.h index 200f321b5a..8801f83e19 100644 --- a/lib/windows-spawn.h +++ b/lib/windows-spawn.h @@ -18,13 +18,11 @@ #ifndef _WINDOWS_SPAWN_H #define _WINDOWS_SPAWN_H -/* Duplicates a file handle, making the copy uninheritable and ensuring the - result is none of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO. - Returns -1 for a file handle that is equivalent to closed. */ -extern int dup_safer_noinherit (int fd); +#include <stdint.h> -/* Undoes the effect of TEMPFD = dup_safer_noinherit (ORIGFD); */ -extern void undup_safer_noinherit (int tempfd, int origfd); +/* Get declarations of the native Windows API functions. */ +#define WIN32_LEAN_AND_MEAN +#include <windows.h> /* Prepares an argument vector before calling spawn(). Note that spawn() does not by itself call the command interpreter @@ -58,4 +56,28 @@ extern void undup_safer_noinherit (int tempfd, int origfd); */ extern char ** prepare_spawn (char **argv); +/* Creates a subprocess. + MODE is either P_WAIT or P_NOWAIT. + PROGNAME is the program to invoke. + ARGV is the NULL-terminated array of arguments, ARGV[0] being PROGNAME by + convention. + ENVP is the NULL-terminated set of environment variable assignments, or NULL + to inherit the initial environ variable assignments from the caller and + ignore all calls to putenv(), setenv(), unsetenv() done in the caller. + CURRDIR is the directory in which to start the program, or NULL to inherit + the working directory from the caller. + STDIN_HANDLE, STDOUT_HANDLE, STDERR_HANDLE are the handles to use for the + first three file descriptors in the callee process. + Returns + - 0 for success (if MODE is P_WAIT), or + - a handle that be passed to _cwait (on Windows) or waitpid (on OS/2), or + - -1 upon error, with errno set. + */ +extern intptr_t spawnpvech (int mode, + const char *progname, const char * const *argv, + const char * const *envp, + const char *currdir, + HANDLE stdin_handle, HANDLE stdout_handle, + HANDLE stderr_handle); + #endif /* _WINDOWS_SPAWN_H */ |