summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-11-04 14:41:28 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2022-11-04 14:41:28 +0900
commit5d30adb5ad376a07576b258b9395adadf5576867 (patch)
tree3639ded8cf8b7e237e3baeb9d5573fdfe0edb12a
parent6c20e8393eba4a9f330143b2158e28ea594cbadd (diff)
downloadlibgpg-error-5d30adb5ad376a07576b258b9395adadf5576867.tar.gz
spawn: Introduce gpgrt_process_t and use it for spawn API.
* configure.ac (AC_FUNC_FORK): No use. * src/gpg-error.h.in (@define:gpgrt_process_t@): New. (@define:pid_t@): Remove. (gpgrt_spawn_process, gpgrt_spawn_process_fd): Use gpgrt_process_t. (gpgrt_wait_process, gpgrt_wait_processes): Likewise. (gpgrt_kill_process, gpgrt_release_process): Likewise. * src/gpgrt-int.h (_gpgrt_spawn_process): Likewise. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. * src/mkheader.c (write_special): Handle @define:gpgrt_process_t@. Remove handling of @define:pid_t@. * src/spawn-posix.c (_gpgrt_spawn_process): Use gpgrt_process_t. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. * src/spawn-w32.c (_gpgrt_spawn_process): Use gpgrt_process_t. (_gpgrt_spawn_process_fd): Likewise. (_gpgrt_wait_process, _gpgrt_wait_processes): Likewise. (_gpgrt_kill_process, _gpgrt_release_process): Likewise. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--configure.ac5
-rw-r--r--src/gpg-error.h.in22
-rw-r--r--src/gpgrt-int.h35
-rw-r--r--src/mkheader.c27
-rw-r--r--src/spawn-posix.c101
-rw-r--r--src/spawn-w32.c101
-rw-r--r--src/visibility.c27
7 files changed, 191 insertions, 127 deletions
diff --git a/configure.ac b/configure.ac
index 5c3e47a..1779f7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -216,7 +216,10 @@ AC_MSG_WARN([[Without strerror_r, gpg_strerror_r might not be thread-safe]]))
esac
AC_SUBST(INSTALLSHELLPATH)
-AC_FUNC_FORK
+# We don't check 'fork' by configure script. Use of fork is inferred from by
+# the target system (POSIX or Windows).
+# AC_FUNC_FORK
+
AC_CHECK_FUNCS([flockfile vasprintf mmap rand strlwr stpcpy setenv stat \
getrlimit getpwnam getpwuid getpwnam_r getpwuid_r inet_pton])
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index ce5c76a..d9b2365 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -432,7 +432,7 @@ const char *gpgrt_check_version (const char *req_version);
const char *gpg_error_check_version (const char *req_version);
/* System specific type definitions. */
-@define:pid_t@
+@define:gpgrt_process_t@
@define:gpgrt_ssize_t@
@define:gpgrt_off_t@
@@ -1108,14 +1108,14 @@ gpg_err_code_t gpgrt_spawn_process (const char *pgmname, const char *argv[],
gpgrt_stream_t *r_infp,
gpgrt_stream_t *r_outfp,
gpgrt_stream_t *r_errfp,
- pid_t *pid);
+ gpgrt_process_t *r_process_id);
/* Fork and exec PGNNAME and connect the process to the given FDs. */
gpg_err_code_t gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
int infd, int outfd, int errfd,
int (*spawn_cb) (void *),
void *spawn_cb_arg,
- pid_t *pid);
+ gpgrt_process_t *r_process_id);
/* Fork and exec PGMNAME as a detached process. */
gpg_err_code_t gpgrt_spawn_process_detached (const char *pgmname,
@@ -1123,18 +1123,20 @@ gpg_err_code_t gpgrt_spawn_process_detached (const char *pgmname,
const char *envp[]);
/* Wait for a single process. */
-gpg_err_code_t gpgrt_wait_process (const char *pgmname, pid_t pid, int hang,
- int *r_exitcode);
+gpg_err_code_t gpgrt_wait_process (const char *pgmname,
+ gpgrt_process_t process_id,
+ int hang, int *r_exitcode);
/* Wait for a multiple processes. */
-gpg_err_code_t gpgrt_wait_processes (const char **pgmnames, pid_t *pids,
+gpg_err_code_t gpgrt_wait_processes (const char **pgmnames,
+ gpgrt_process_t *process_ids,
size_t count, int hang, int *r_exitcodes);
-/* Kill the process identified by PID. */
-void gpgrt_kill_process (pid_t pid);
+/* Kill the process identified by PROCESS_ID. */
+void gpgrt_kill_process (gpgrt_process_t process_id);
-/* Release process resources identified by PID. */
-void gpgrt_release_process (pid_t pid);
+/* Release process resources identified by PROCESS_ID. */
+void gpgrt_release_process (gpgrt_process_t process_id);
/* Close all file resources (descriptors), except KEEP_FDS. */
void gpgrt_close_all_fds (int from, int *keep_fds);
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index c414272..d2b5d1c 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -640,9 +640,9 @@ gpg_err_code_t _gpgrt_make_pipe (int filedes[2], estream_t *r_fp,
* /dev/null; if it is not NULL store the address of a pointer to a
* new estream there. If R_ERRFP is NULL connect stderr of the new
* process to /dev/null; if it is not NULL store the address of a
- * pointer to a new estream there. On success the pid of the new
- * process is stored at PID. On error -1 is stored at PID and if
- * R_OUTFP or R_ERRFP are not NULL, NULL is stored there.
+ * pointer to a new estream there. On success the process id of the
+ * new process is stored at R_PID. On error -1 is stored at R_PID and
+ * if R_OUTFP or R_ERRFP are not NULL, NULL is stored there.
*
* The arguments for the process are expected in the NULL terminated
* array ARGV. The program name itself should not be included there.
@@ -687,7 +687,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
estream_t *r_infp,
estream_t *r_outfp,
estream_t *r_errfp,
- pid_t *pid);
+ gpgrt_process_t *r_process_id);
/* Variant of gpgrt_spawn_process. This function forks and then execs
@@ -709,7 +709,7 @@ gpg_err_code_t _gpgrt_spawn_process_fd (const char *pgmname,
int infd, int outfd, int errfd,
int (*spawn_cb) (void *),
void *spawn_cb_arg,
- pid_t *pid);
+ gpgrt_process_t *r_process_id);
/* Spawn a new process and immediately detach from it. The name of
* the program to exec is PGMNAME and its arguments are in ARGV (the
@@ -721,8 +721,8 @@ gpg_err_code_t _gpgrt_spawn_process_detached (const char *pgmname,
const char *argv[],
const char *envp[]);
-/* If HANG is true, waits for the process identified by PID to exit;
- * if HANG is false, checks whether the process has terminated.
+/* If HANG is true, waits for the process identified by PROCESS_ID to
+ * exit; if HANG is false, checks whether the process has terminated.
* PGMNAME should be the same as supplied to the spawn function and is
* only used for diagnostics. Return values:
*
@@ -745,22 +745,25 @@ gpg_err_code_t _gpgrt_spawn_process_detached (const char *pgmname,
* if the exit code is not required (in that case an error message will
* be printed). Note that under Windows PID is not the process id but
* the handle of the process. */
-gpg_err_code_t _gpgrt_wait_process (const char *pgmname, pid_t pid, int hang,
+gpg_err_code_t _gpgrt_wait_process (const char *pgmname,
+ gpgrt_process_t process_id, int hang,
int *r_exitcode);
/* Like _gpgrt_wait_process, but for COUNT processes. */
-gpg_err_code_t _gpgrt_wait_processes (const char **pgmnames, pid_t *pids,
- size_t count, int hang, int *r_exitcodes);
+gpg_err_code_t _gpgrt_wait_processes (const char **pgmnames,
+ gpgrt_process_t *process_ids,
+ size_t count, int hang,
+ int *r_exitcodes);
/* Kill a process; that is send an appropriate signal to the process.
* gpgrt_wait_process must be called to actually remove the process
- * from the system. An invalid PID is ignored. */
-void _gpgrt_kill_process (pid_t pid);
+ * from the system. An invalid PROCESS_ID is ignored. */
+void _gpgrt_kill_process (gpgrt_process_t process_id);
-/* Release the process identified by PID. This function is actually
- * only required for Windows but it does not harm to always call it.
- * It is a nop if PID is invalid. */
-void _gpgrt_release_process (pid_t pid);
+/* Release the process identified by PROCESS_ID. This function is
+ * actually only required for Windows but it does not harm to always
+ * call it. It is a nop if PROCESS_ID is invalid. */
+void _gpgrt_release_process (gpgrt_process_t process_id);
/* Close all file resources (descriptors), except KEEP_FDS. */
void _gpgrt_close_all_fds (int from, int *keep_fds);
diff --git a/src/mkheader.c b/src/mkheader.c
index e05dafd..8fbfbd6 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -570,28 +570,23 @@ write_special (const char *fname, int lnr, const char *tag)
else
fputs ("int", stdout);
}
- else if (!strcmp (tag, "define:pid_t"))
+ else if (!strcmp (tag, "define:gpgrt_process_t"))
{
- if (have_sys_types_h)
+ if (have_w32_system || have_w64_system)
{
- if (!sys_types_h_included)
- {
- fputs ("#include <sys/types.h>\n", stdout);
- sys_types_h_included = 1;
- }
+ fputs ("typedef void *gpgrt_process_t;\n", stdout);
}
- else if (have_w64_system)
+ else
{
- if (!stdint_h_included && have_stdint_h)
+ if (have_sys_types_h)
{
- fputs ("#include <stdint.h>\n", stdout);
- stdint_h_included = 1;
+ if (!sys_types_h_included)
+ {
+ fputs ("#include <sys/types.h>\n", stdout);
+ sys_types_h_included = 1;
+ }
}
- fputs ("typedef int64_t pid_t\n", stdout);
- }
- else
- {
- fputs ("typedef int pid_t\n", stdout);
+ fputs ("typedef pid_t gpgrt_process_t;\n", stdout);
}
}
else if (!strcmp (tag, "include:err-sources"))
diff --git a/src/spawn-posix.c b/src/spawn-posix.c
index 6914b0b..8e36ee1 100644
--- a/src/spawn-posix.c
+++ b/src/spawn-posix.c
@@ -398,6 +398,35 @@ _gpgrt_make_pipe (int filedes[2], estream_t *r_fp, int direction,
return do_create_pipe (filedes);
}
+/*
+ * UNION PROCESS_ID:
+ *
+ * gpgrt_process_t object is an object which represents process handle.
+ * It must be same size as pid_t and must have same bit pattern.
+ */
+union process {
+ gpgrt_process_t process_id;
+ pid_t pid;
+};
+
+static gpgrt_process_t
+convert_from_pid (pid_t pid)
+{
+ union process u;
+
+ u.pid = pid;
+ return u.process_id;
+}
+
+static pid_t
+convert_from_process (gpgrt_process_t process_id)
+{
+ union process u;
+
+ u.process_id = process_id;
+ return u.pid;
+}
+
/* Fork and exec the PGMNAME, see gpgrt-int.h for details. */
gpg_err_code_t
@@ -406,7 +435,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
estream_t *r_infp,
estream_t *r_outfp,
estream_t *r_errfp,
- pid_t *pid)
+ gpgrt_process_t *r_process_id)
{
gpg_error_t err;
int inpipe[2] = {-1, -1};
@@ -416,6 +445,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
estream_t outfp = NULL;
estream_t errfp = NULL;
int nonblock = !!(flags & GPGRT_SPAWN_NONBLOCK);
+ pid_t pid;
if (r_infp)
*r_infp = NULL;
@@ -423,7 +453,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
*r_outfp = NULL;
if (r_errfp)
*r_errfp = NULL;
- *pid = (pid_t)(-1); /* Always required. */
+ *r_process_id = convert_from_pid (-1);
if (r_infp)
{
@@ -472,9 +502,9 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
}
_gpgrt_pre_syscall ();
- *pid = fork ();
+ pid = fork ();
_gpgrt_post_syscall ();
- if (*pid == (pid_t)(-1))
+ if (pid == (pid_t)(-1))
{
err = _gpg_err_code_from_syserror ();
_gpgrt_log_error (_("error forking process: %s\n"), _gpg_strerror (err));
@@ -502,7 +532,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
return err;
}
- if (!*pid)
+ if (!pid)
{
/* This is the child. */
_gpgrt_fclose (infp);
@@ -528,6 +558,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
if (r_errfp)
*r_errfp = errfp;
+ *r_process_id = convert_from_pid (pid);
return 0;
}
@@ -538,22 +569,24 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
int infd, int outfd, int errfd,
int (*spawn_cb) (void *),
void *spawn_cb_arg,
- pid_t *pid)
+ gpgrt_process_t *r_process_id)
{
gpg_error_t err;
int ask_inherit_fds = 0;
+ pid_t pid;
+ *r_process_id = convert_from_pid (-1);
_gpgrt_pre_syscall ();
- *pid = fork ();
+ pid = fork ();
_gpgrt_post_syscall ();
- if (*pid == (pid_t)(-1))
+ if (pid == (pid_t)(-1))
{
err = _gpg_err_code_from_syserror ();
_gpgrt_log_error (_("error forking process: %s\n"), _gpg_strerror (err));
return err;
}
- if (!*pid)
+ if (!pid)
{
if (spawn_cb)
ask_inherit_fds = (*spawn_cb) (spawn_cb_arg);
@@ -564,6 +597,7 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
/*NOTREACHED*/
}
+ *r_process_id = convert_from_pid (pid);
return 0;
}
@@ -630,10 +664,14 @@ get_result (pid_t pid, int *r_exitcode)
/* See gpgrt-int.h for a description. */
gpg_err_code_t
-_gpgrt_wait_process (const char *pgmname, pid_t pid, int hang, int *r_exitcode)
+_gpgrt_wait_process (const char *pgmname, gpgrt_process_t process_id, int hang,
+ int *r_exitcode)
{
gpg_err_code_t ec;
int i, status;
+ pid_t pid;
+
+ pid = convert_from_process (process_id);
if (r_exitcode)
*r_exitcode = -1;
@@ -696,12 +734,13 @@ _gpgrt_wait_process (const char *pgmname, pid_t pid, int hang, int *r_exitcode)
* and threads.
*/
gpg_err_code_t
-_gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
- int hang, int *r_exitcodes)
+_gpgrt_wait_processes (const char **pgmnames, gpgrt_process_t *process_ids,
+ size_t count, int hang, int *r_exitcodes)
{
gpg_err_code_t ec = 0;
size_t i, left;
int *dummy = NULL;
+ pid_t pid;
if (!r_exitcodes)
{
@@ -714,8 +753,10 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
{
int status = -1;
+ pid = convert_from_process (process_ids[i]);
+
/* Skip invalid PID. */
- if (pids[i] == (pid_t)(-1))
+ if (pid == (pid_t)(-1))
{
r_exitcodes[i] = -1;
left -= 1;
@@ -723,7 +764,7 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
}
/* See if there was a previously stored result for this pid. */
- if (get_result (pids[i], &status))
+ if (get_result (pid, &status))
left -= 1;
r_exitcodes[i] = status;
@@ -731,22 +772,22 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
while (left > 0)
{
- pid_t pid;
+ pid_t pid0;
int status;
_gpgrt_pre_syscall ();
- while ((pid = waitpid (-1, &status, hang ? 0 : WNOHANG)) == (pid_t)(-1)
+ while ((pid0 = waitpid (-1, &status, hang ? 0 : WNOHANG)) == (pid_t)(-1)
&& errno == EINTR);
_gpgrt_post_syscall ();
- if (pid == (pid_t)(-1))
+ if (pid0 == (pid_t)(-1))
{
ec = _gpg_err_code_from_syserror ();
_gpgrt_log_error (_("waiting for processes to terminate"
" failed: %s\n"), _gpg_strerror (ec));
break;
}
- else if (!pid)
+ else if (!pid0)
{
ec = GPG_ERR_TIMEOUT; /* Still running. */
break;
@@ -754,22 +795,25 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
else
{
for (i = 0; i < count; i++)
- if (pid == pids[i])
- break;
+ {
+ pid = convert_from_process (process_ids[i]);
+ if (pid0 == pid)
+ break;
+ }
if (i == count)
{
/* No match, store this result. */
- ec = store_result (pid, status);
+ ec = store_result (pid0, status);
if (ec)
break;
continue;
}
- /* Process PIDS[i] died. */
+ /* Process PROCESS_PIDS[i] died. */
if (r_exitcodes[i] != (pid_t) -1)
{
- _gpgrt_log_error ("PID %d was reused", (int)pid);
+ _gpgrt_log_error ("PID %d was reused", (int)pid0);
ec = GPG_ERR_GENERAL;
break;
}
@@ -815,7 +859,7 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
* callback. */
gpg_err_code_t
_gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
- const char *envp[] )
+ const char *envp[])
{
gpg_err_code_t ec;
pid_t pid;
@@ -884,8 +928,11 @@ _gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
* gnupg_wait_process must be called to actually remove the process
from the system. An invalid PID is ignored. */
void
-_gpgrt_kill_process (pid_t pid)
+_gpgrt_kill_process (gpgrt_process_t process_id)
{
+ pid_t pid;
+
+ pid = convert_from_process (process_id);
if (pid != (pid_t)(-1))
{
_gpgrt_pre_syscall ();
@@ -896,7 +943,7 @@ _gpgrt_kill_process (pid_t pid)
void
-_gpgrt_release_process (pid_t pid)
+_gpgrt_release_process (gpgrt_process_t process_id)
{
- (void)pid;
+ (void)process_id;
}
diff --git a/src/spawn-w32.c b/src/spawn-w32.c
index d17f971..324b5fe 100644
--- a/src/spawn-w32.c
+++ b/src/spawn-w32.c
@@ -65,24 +65,6 @@
#define fd_to_handle(a) ((HANDLE)(a))
#define handle_to_fd(a) ((intptr_t)(a))
-/* For pid_t and HANDLE:
-
- * We assume that a HANDLE can be represented by an int which should
- * be true for all i386 systems.
- *
- * On 64-bit machine, it is no longer true, as a type, however, as
- * long as the range of the value in the type HANDLE can be
- * represented by an int, it works.
- *
- * FIXME with original MinGW: Breaking ABI for pid_t will be needed
- * when the value won't fit within 32-bit range on 64-bit machine.
- *
- * Note that pid_t is 64-bit integer in sys/types.h with MinGW-w64.
- * So, no problem with MinGW-w64.
- */
-#define pid_to_handle(a) ((HANDLE)(a))
-#define handle_to_pid(a) ((pid_t)(a))
-
/* Return the maximum number of currently allowed open file
* descriptors. Only useful on POSIX systems but returns a value on
@@ -383,12 +365,42 @@ _gpgrt_make_pipe (int filedes[2], estream_t *r_fp, int direction, int nonblock)
}
+/*
+ * UNION PROCESS_ID:
+ *
+ * gpgrt_process_t is an object which represents process handle.
+ * It must be same size as HANDLE and must have same bit pattern.
+ */
+union process {
+ gpgrt_process_t process_id;
+ HANDLE process_handle;
+};
+
+static gpgrt_process_t
+convert_from_handle (HANDLE process_handle)
+{
+ union process u;
+
+ u.process_handle = process_handle;
+ return u.process_id;
+}
+
+static HANDLE
+convert_from_process (gpgrt_process_t process_id)
+{
+ union process u;
+
+ u.process_id = process_id;
+ return u.process_handle;
+}
+
+
/* Fork and exec the PGMNAME, see gpgrt-int.h for details. */
gpg_err_code_t
_gpgrt_spawn_process (const char *pgmname, const char *argv[],
int *except, unsigned int flags,
estream_t *r_infp, estream_t *r_outfp, estream_t *r_errfp,
- pid_t *pid)
+ gpgrt_process_t *r_process_id)
{
gpg_err_code_t err;
SECURITY_ATTRIBUTES sec_attr;
@@ -424,7 +436,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
*r_outfp = NULL;
if (r_errfp)
*r_errfp = NULL;
- *pid = (pid_t)INVALID_HANDLE_VALUE; /* Always required. */
+ *r_process_id = convert_from_handle (INVALID_HANDLE_VALUE);
if (r_infp)
{
@@ -633,7 +645,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[],
if (r_errfp)
*r_errfp = errfp;
- *pid = handle_to_pid (pi.hProcess);
+ *r_process_id = convert_from_handle (pi.hProcess);
return 0;
}
@@ -644,7 +656,7 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
int infd, int outfd, int errfd,
int (*spawn_cb) (void *),
void *spawn_cb_arg,
- pid_t *pid)
+ gpgrt_process_t *r_process_id)
{
gpg_err_code_t err;
SECURITY_ATTRIBUTES sec_attr;
@@ -659,7 +671,7 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
ask_inherit = (*spawn_cb) (spawn_cb_arg);
/* Setup return values. */
- *pid = (pid_t)INVALID_HANDLE_VALUE;
+ *r_process_id = convert_from_handle (INVALID_HANDLE_VALUE);
/* Prepare security attributes. */
memset (&sec_attr, 0, sizeof sec_attr );
@@ -727,23 +739,24 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
ResumeThread (pi.hThread);
CloseHandle (pi.hThread);
- *pid = handle_to_pid (pi.hProcess);
+ *r_process_id = convert_from_handle (pi.hProcess);
return 0;
}
/* See gpgrt-int.h for a description. */
gpg_err_code_t
-_gpgrt_wait_process (const char *pgmname, pid_t pid, int hang, int *r_exitcode)
+_gpgrt_wait_process (const char *pgmname, gpgrt_process_t process_id,
+ int hang, int *r_exitcode)
{
- return _gpgrt_wait_processes (&pgmname, &pid, 1, hang, r_exitcode);
+ return _gpgrt_wait_processes (&pgmname, &process_id, 1, hang, r_exitcode);
}
/* See gpgrt-int.h for a description. */
gpg_err_code_t
-_gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
- int hang, int *r_exitcodes)
+_gpgrt_wait_processes (const char **pgmnames, gpgrt_process_t *process_ids,
+ size_t count, int hang, int *r_exitcodes)
{
gpg_err_code_t ec = 0;
size_t i;
@@ -756,13 +769,15 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
for (i = 0; i < count; i++)
{
+ HANDLE process_handle = convert_from_process (process_ids[i]);
+
if (r_exitcodes)
r_exitcodes[i] = -1;
- if (pids[i] == (pid_t)INVALID_HANDLE_VALUE)
+ if (process_handle == INVALID_HANDLE_VALUE)
return GPG_ERR_INV_VALUE;
- procs[i] = pid_to_handle (pids[i]);
+ procs[i] = process_handle;
}
_gpgrt_pre_syscall ();
@@ -787,9 +802,9 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
if (! GetExitCodeProcess (procs[i], &exc))
{
- _gpgrt_log_error (_("error getting exit code of process %d:"
+ _gpgrt_log_error (_("error getting exit code of process %p:"
" ec=%d\n"),
- (int) pids[i], (int)GetLastError ());
+ process_ids[i], (int)GetLastError ());
ec = GPG_ERR_GENERAL;
}
else if (exc)
@@ -824,7 +839,7 @@ _gpgrt_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
/* See gpgrt-int.h for a description. */
gpg_err_code_t
_gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
- const char *envp[] )
+ const char *envp[])
{
gpg_err_code_t err;
SECURITY_ATTRIBUTES sec_attr;
@@ -907,29 +922,27 @@ _gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
gnupg_wait_process must be called to actually remove the process
from the system. An invalid PID is ignored. */
void
-_gpgrt_kill_process (pid_t pid)
+_gpgrt_kill_process (gpgrt_process_t process_id)
{
- if (pid != (pid_t)INVALID_HANDLE_VALUE)
- {
- HANDLE process = (HANDLE) pid;
+ HANDLE process_handle = convert_from_process (process_id);
+ if (process_handle != INVALID_HANDLE_VALUE)
+ {
/* Arbitrary error code. */
_gpgrt_pre_syscall ();
- TerminateProcess (process, 1);
+ TerminateProcess (process_handle, 1);
_gpgrt_post_syscall ();
}
}
void
-_gpgrt_release_process (pid_t pid)
+_gpgrt_release_process (gpgrt_process_t process_id)
{
- if (pid != (pid_t)INVALID_HANDLE_VALUE)
- {
- HANDLE process = (HANDLE)pid;
+ HANDLE process_handle = convert_from_process (process_id);
- CloseHandle (process);
- }
+ if (process_handle != INVALID_HANDLE_VALUE)
+ CloseHandle (process_handle);
}
void
diff --git a/src/visibility.c b/src/visibility.c
index 577a2be..dd1a6a8 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -1103,21 +1103,20 @@ gpg_err_code_t
gpgrt_spawn_process (const char *pgmname, const char *argv[],
int *except, unsigned int flags,
estream_t *r_infp, estream_t *r_outfp, estream_t *r_errfp,
- pid_t *pid)
+ gpgrt_process_t *r_process_id)
{
return _gpgrt_spawn_process (pgmname, argv, except, flags,
- r_infp, r_outfp, r_errfp, pid);
+ r_infp, r_outfp, r_errfp, r_process_id);
}
gpg_err_code_t
gpgrt_spawn_process_fd (const char *pgmname, const char *argv[],
int infd, int outfd, int errfd,
int (*spawn_cb)(void *),
- void *spawn_cb_arg,
- pid_t *pid)
+ void *spawn_cb_arg, gpgrt_process_t *r_process_id)
{
return _gpgrt_spawn_process_fd (pgmname, argv, infd, outfd, errfd,
- spawn_cb, spawn_cb_arg, pid);
+ spawn_cb, spawn_cb_arg, r_process_id);
}
gpg_err_code_t
@@ -1128,28 +1127,30 @@ gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
}
gpg_err_code_t
-gpgrt_wait_process (const char *pgmname, pid_t pid, int hang, int *r_exitcode)
+gpgrt_wait_process (const char *pgmname, gpgrt_process_t process_id, int hang,
+ int *r_exitcode)
{
- return _gpgrt_wait_process (pgmname, pid, hang, r_exitcode);
+ return _gpgrt_wait_process (pgmname, process_id, hang, r_exitcode);
}
gpg_err_code_t
-gpgrt_wait_processes (const char **pgmnames, pid_t *pids,
+gpgrt_wait_processes (const char **pgmnames, gpgrt_process_t *process_ids,
size_t count, int hang, int *r_exitcodes)
{
- return _gpgrt_wait_processes (pgmnames, pids, count, hang, r_exitcodes);
+ return _gpgrt_wait_processes (pgmnames, process_ids, count, hang,
+ r_exitcodes);
}
void
-gpgrt_kill_process (pid_t pid)
+gpgrt_kill_process (gpgrt_process_t process_id)
{
- _gpgrt_kill_process (pid);
+ _gpgrt_kill_process (process_id);
}
void
-gpgrt_release_process (pid_t pid)
+gpgrt_release_process (gpgrt_process_t process_id)
{
- _gpgrt_release_process (pid);
+ _gpgrt_release_process (process_id);
}
void