summaryrefslogtreecommitdiff
path: root/lib/windows-spawn.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/windows-spawn.h')
-rw-r--r--lib/windows-spawn.h62
1 files changed, 45 insertions, 17 deletions
diff --git a/lib/windows-spawn.h b/lib/windows-spawn.h
index 0be407bf9..42c5af771 100644
--- a/lib/windows-spawn.h
+++ b/lib/windows-spawn.h
@@ -1,5 +1,5 @@
/* Auxiliary functions for the creation of subprocesses. Native Windows API.
- Copyright (C) 2001, 2003-2022 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2003-2023 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This file is free software: you can redistribute it and/or modify
@@ -18,7 +18,6 @@
#ifndef _WINDOWS_SPAWN_H
#define _WINDOWS_SPAWN_H
-#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -85,10 +84,43 @@ extern char * compose_envblock (const char * const *envp)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
-/* This struct keeps track of which handles to pass to a subprocess, and with
- which flags. All of the handles here are inheritable.
+/* An inheritable handle with some additional information. */
+struct IHANDLE
+{
+ /* Either INVALID_HANDLE_VALUE or an inheritable handle. */
+ HANDLE handle;
+ /* Only relevant if handle != INVALID_HANDLE_VALUE.
+ It is a bit mask consisting of:
+ - 32 for O_APPEND.
+ - KEEP_OPEN_IN_CHILD if the handle is scheduled to be preserved in the
+ child process.
+ - KEEP_OPEN_IN_PARENT if the handle is shared with (and needs to be kept
+ open in) the parent process.
+ - DELAYED_DUP2_OLDFD if there is a delayed dup2 (oldfd, newfd) and
+ this IHANDLE is at position oldfd.
+ - DELAYED_DUP2_NEWFD if there is a delayed dup2 (oldfd, newfd) and
+ this IHANDLE is at position newfd.
+ Note that DELAYED_DUP2_OLDFD and DELAYED_DUP2_NEWFD cannot be set in the
+ same IHANDLE. */
+ unsigned short flags;
+ #define KEEP_OPEN_IN_CHILD 0x100
+ #define KEEP_OPEN_IN_PARENT 0x200
+ #define DELAYED_DUP2_OLDFD 0x400
+ #define DELAYED_DUP2_NEWFD 0x800
+ /* Only relevant if handle != INVALID_HANDLE_VALUE and flags contains
+ either DELAYED_DUP2_OLDFD or DELAYED_DUP2_NEWFD.
+ It is the other fd of the delayed dup2 (oldfd, newfd), i.e.
+ - for DELAYED_DUP2_OLDFD, the newfd,
+ - for DELAYED_DUP2_NEWFD, the oldfd. */
+ int linked_fd;
+};
+
+/* This struct keeps track of which handles to potentially pass to a subprocess,
+ and with which flags. All of the handles here are inheritable.
Regarding handle inheritance, see
- <https://docs.microsoft.com/en-us/windows/win32/sysinfo/handle-inheritance> */
+ <https://docs.microsoft.com/en-us/windows/win32/sysinfo/handle-inheritance>.
+ Whether a handle is actually scheduled for being preserved in the child
+ process is determined by the KEEP_OPEN_IN_CHILD bit in the flags. */
struct inheritable_handles
{
/* The number of occupied entries in the two arrays below.
@@ -96,20 +128,16 @@ struct inheritable_handles
size_t count;
/* The number of allocated entries in the two arrays below. */
size_t allocated;
- /* handles[0..count-1] are the occupied entries.
- handles[fd] is either INVALID_HANDLE_VALUE or an inheritable handle. */
- HANDLE *handles;
- /* flags[0..count-1] are the occupied entries.
- flags[fd] is only relevant if handles[fd] != INVALID_HANDLE_VALUE.
- It is a bit mask consisting of:
- - 32 for O_APPEND.
- */
- unsigned char *flags;
+ /* ih[0..count-1] are the occupied entries. */
+ struct IHANDLE *ih;
};
-/* Initializes a set of inheritable handles, filling in all inheritable handles
- assigned to file descriptors.
- If DUPLICATE is true, the handles stored in the set are duplicates.
+/* Initializes a set of inheritable handles, filling in all or part of the
+ file descriptors of the current process.
+ If DUPLICATE is true, the handles stored are those of all file descriptors,
+ and we use DuplicateHandle to make sure that they are all inheritable.
+ If DUPLICATE is false, the handles stored are only the inheritables ones;
+ this is a shortcut for spawnpvech().
Returns 0 upon success. In case of failure, -1 is returned, with errno set.
*/
extern int init_inheritable_handles (struct inheritable_handles *inh_handles,