aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2024-06-05 06:07:01 +0000
committerNIIBE Yutaka <[email protected]>2024-06-05 06:16:26 +0000
commit2caaef8f6b89d7fcbbe3d480d192fe1952576942 (patch)
treefddcb729218d31738937481882b8f7cc8736f3e5
parentspawn:w32: Fix setting of dwFlags for CreateProcess. (diff)
downloadlibgpg-error-2caaef8f6b89d7fcbbe3d480d192fe1952576942.tar.gz
libgpg-error-2caaef8f6b89d7fcbbe3d480d192fe1952576942.zip
spawn: Expose spawn functions API.
* src/gpg-error.def.in: Update. * src/gpg-error.vers: Update. * src/gpg-error.h.in: Add declarations. * src/visibility.c: Add implementations. * src/visibility.h: Expose them. -- GnuPG-bug-id: 6249 Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r--src/gpg-error.def.in23
-rw-r--r--src/gpg-error.h.in56
-rw-r--r--src/gpg-error.vers20
-rw-r--r--src/gpgrt-int.h8
-rw-r--r--src/mkheader.c3
-rw-r--r--src/spawn-posix.c17
-rw-r--r--src/spawn-w32.c17
-rw-r--r--src/visibility.c116
-rw-r--r--src/visibility.h53
9 files changed, 184 insertions, 129 deletions
diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in
index a7525a8..91ba69a 100644
--- a/src/gpg-error.def.in
+++ b/src/gpg-error.def.in
@@ -195,13 +195,15 @@ EXPORTS
;; API not yet finished for:
;; gpgrt_make_pipe @152
-;; gpgrt_spawn_process @153
-;; gpgrt_spawn_process_fd @154
-;; gpgrt_spawn_process_detached @155
-;; gpgrt_wait_process @156
-;; gpgrt_wait_processes @157
-;; gpgrt_kill_process @158
-;; gpgrt_release_process @159
+;; gpgrt_close_all_fds @188
+
+ gpgrt_process_spawn @153
+ gpgrt_process_terminate @154
+ gpgrt_process_get_fds @155
+ gpgrt_process_get_streams @156
+ gpgrt_process_ctl @157
+ gpgrt_process_wait @158
+ gpgrt_process_release @159
gpgrt_argparse @160
gpgrt_usage @161
@@ -243,11 +245,12 @@ EXPORTS
gpgrt_utf8_to_wchar @186
gpgrt_wchar_to_utf8 @187
-;; API not yet finished for:
-;; gpgrt_close_all_fds @188
-
gpgrt_wipememory @189
gpgrt_add_post_log_func @190
gpgrt_logv_domain @191
+ gpgrt_spawn_actions_set_envvars @192
+ gpgrt_spawn_actions_set_redirect @193
+ gpgrt_spawn_actions_set_inherit_handles @194
+
;; end of file with public symbols for Windows.
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index d38696a..0c56436 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -1087,7 +1087,7 @@ void _gpgrt_log_assert (const char *expr, const char *file, int line,
/*
- * Spawn functions (Not yet available)
+ * Spawn functions
*/
#define GPGRT_PROCESS_DETACHED (1 << 1)
@@ -1137,46 +1137,34 @@ gpg_err_code_t gpgrt_make_pipe (int filedes[2], gpgrt_stream_t *r_fp,
#define gpgrt_create_inbound_pipe(a,b,c) gpgrt_make_pipe ((a), (b), -1,(c));
#define gpgrt_create_outbound_pipe(a,b,c) gpgrt_make_pipe ((a), (b), 1,(c));
+/* Close all file resources (descriptors), except KEEP_FDS. */
+void gpgrt_close_all_fds (int from, int *keep_fds);
+#endif /*0*/
-/* Fork and exec PGMNAME. */
-gpg_err_code_t gpgrt_spawn_process (const char *pgmname, const char *argv[],
- int *execpt, unsigned int flags,
- gpgrt_stream_t *r_infp,
- gpgrt_stream_t *r_outfp,
- gpgrt_stream_t *r_errfp,
- 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,
- gpgrt_process_t *r_process_id);
+gpg_err_code_t gpgrt_process_spawn (const char *pgmname, const char *argv1[],
+ unsigned int flags,
+ gpgrt_spawn_actions_t act,
+ gpgrt_process_t *r_process);
-/* Fork and exec PGMNAME as a detached process. */
-gpg_err_code_t gpgrt_spawn_process_detached (const char *pgmname,
- const char *argv[],
- const char *envp[]);
+gpg_err_code_t gpgrt_process_terminate (gpgrt_process_t process);
-/* Wait for a single process. */
-gpg_err_code_t gpgrt_wait_process (const char *pgmname,
- gpgrt_process_t process_id,
- int hang, int *r_exitcode);
+gpg_err_code_t gpgrt_process_get_fds (gpgrt_process_t process,
+ unsigned int flags,
+ int *r_fd_in, int *r_fd_out,
+ int *r_fd_err);
-/* Wait for a multiple processes. */
-gpg_err_code_t gpgrt_wait_processes (const char **pgmnames,
- gpgrt_process_t *process_ids,
- size_t count, int hang, int *r_exitcodes);
+gpg_err_code_t gpgrt_process_get_streams (gpgrt_process_t process,
+ unsigned int flags,
+ gpgrt_stream_t *r_fp_in,
+ gpgrt_stream_t *r_fp_out,
+ gpgrt_stream_t *r_fp_err);
-/* Kill the process identified by PROCESS_ID. */
-void gpgrt_kill_process (gpgrt_process_t process_id);
+gpg_err_code_t gpgrt_process_ctl (gpgrt_process_t process,
+ unsigned int request, ...);
-/* Release process resources identified by PROCESS_ID. */
-void gpgrt_release_process (gpgrt_process_t process_id);
+gpg_err_code_t gpgrt_process_wait (gpgrt_process_t process, int hang);
-/* Close all file resources (descriptors), except KEEP_FDS. */
-void gpgrt_close_all_fds (int from, int *keep_fds);
-#endif /*0*/
+void gpgrt_process_release (gpgrt_process_t process);
/*
* Option parsing.
diff --git a/src/gpg-error.vers b/src/gpg-error.vers
index 9287fbf..f5657eb 100644
--- a/src/gpg-error.vers
+++ b/src/gpg-error.vers
@@ -173,15 +173,16 @@ GPG_ERROR_1.0 {
## API not yet finished for:
# gpgrt_make_pipe;
-# gpgrt_spawn_process;
-# gpgrt_spawn_process_fd;
-# gpgrt_spawn_process_detached;
-# gpgrt_wait_process;
-# gpgrt_wait_processes;
-# gpgrt_kill_process;
-# gpgrt_release_process;
# gpgrt_close_all_fds;
+ gpgrt_process_spawn;
+ gpgrt_process_terminate;
+ gpgrt_process_get_fds;
+ gpgrt_process_get_streams;
+ gpgrt_process_ctl;
+ gpgrt_process_wait;
+ gpgrt_process_release;
+
gpgrt_argparse;
gpgrt_argparser;
gpgrt_usage;
@@ -214,6 +215,11 @@ GPG_ERROR_1.0 {
gpgrt_add_post_log_func;
gpgrt_logv_domain;
+ gpgrt_spawn_actions_set_environ;
+ gpgrt_spawn_actions_set_redirect;
+ gpgrt_spawn_actions_set_inherit_fds;
+ gpgrt_spawn_actions_set_atfork;
+
local:
*;
};
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index cb25b3f..30348a4 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -696,8 +696,8 @@ void _gpgrt_spawn_actions_set_environ (gpgrt_spawn_actions_t, char **);
void _gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t, int, int, int);
void _gpgrt_spawn_actions_set_inherit_fds (gpgrt_spawn_actions_t,
const int *);
-void _gpgrt_spawn_actions_set_atfork (gpgrt_spawn_actions_t,
- void (*atfork)(void *), void *arg);
+void _gpgrt_spawn_actions_set_atfork (gpgrt_spawn_actions_t, void (*)(void *),
+ void *);
#endif
gpg_err_code_t _gpgrt_process_spawn (const char *pgmname, const char *argv1[],
@@ -718,8 +718,8 @@ gpg_err_code_t _gpgrt_process_get_streams (gpgrt_process_t process,
gpgrt_stream_t *r_fp_out,
gpgrt_stream_t *r_fp_err);
-gpg_err_code_t _gpgrt_process_ctl (gpgrt_process_t process,
- unsigned int request, ...);
+gpg_err_code_t _gpgrt_process_vctl (gpgrt_process_t process,
+ unsigned int request, va_list arg_ptr);
gpg_err_code_t _gpgrt_process_wait (gpgrt_process_t process, int hang);
diff --git a/src/mkheader.c b/src/mkheader.c
index 5005bbc..d9b8331 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -577,13 +577,16 @@ write_special (const char *fname, int lnr, const char *tag)
{
if (have_w32_system || have_w64_system)
{
+ fputs ("void gpgrt_spawn_actions_set_envvars (gpgrt_spawn_actions_t, char *);\n", stdout);
fputs ("void gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t, void *, void *, void *);\n", stdout);
fputs ("void gpgrt_spawn_actions_set_inherit_handles (gpgrt_spawn_actions_t, void **);\n", stdout);
}
else
{
+ fputs ("void gpgrt_spawn_actions_set_environ (gpgrt_spawn_actions_t, char **);\n", stdout);
fputs ("void gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t, int, int, int);\n", stdout);
fputs ("void gpgrt_spawn_actions_set_inherit_fds (gpgrt_spawn_actions_t, const int *);\n", stdout);
+ fputs ("void gpgrt_spawn_actions_set_atfork (gpgrt_spawn_actions_t, void (*)(void *), void *);", stdout);
}
}
else if (!strcmp (tag, "include:err-sources"))
diff --git a/src/spawn-posix.c b/src/spawn-posix.c
index eb990ad..67a118f 100644
--- a/src/spawn-posix.c
+++ b/src/spawn-posix.c
@@ -769,8 +769,9 @@ _gpgrt_process_get_streams (gpgrt_process_t process, unsigned int flags,
return 0;
}
-static gpg_err_code_t
-process_vctl (gpgrt_process_t process, unsigned int request, va_list arg_ptr)
+gpg_err_code_t
+_gpgrt_process_vctl (gpgrt_process_t process, unsigned int request,
+ va_list arg_ptr)
{
switch (request)
{
@@ -870,18 +871,6 @@ process_vctl (gpgrt_process_t process, unsigned int request, va_list arg_ptr)
}
gpg_err_code_t
-_gpgrt_process_ctl (gpgrt_process_t process, unsigned int request, ...)
-{
- va_list arg_ptr;
- gpg_err_code_t ec;
-
- va_start (arg_ptr, request);
- ec = process_vctl (process, request, arg_ptr);
- va_end (arg_ptr);
- return ec;
-}
-
-gpg_err_code_t
_gpgrt_process_wait (gpgrt_process_t process, int hang)
{
gpg_err_code_t ec;
diff --git a/src/spawn-w32.c b/src/spawn-w32.c
index 1c0daa9..4e0f206 100644
--- a/src/spawn-w32.c
+++ b/src/spawn-w32.c
@@ -952,8 +952,9 @@ process_kill (gpgrt_process_t process, unsigned int exitcode)
return ec;
}
-static gpg_err_code_t
-process_vctl (gpgrt_process_t process, unsigned int request, va_list arg_ptr)
+gpg_err_code_t
+_gpgrt_process_vctl (gpgrt_process_t process, unsigned int request,
+ va_list arg_ptr)
{
switch (request)
{
@@ -1066,18 +1067,6 @@ process_vctl (gpgrt_process_t process, unsigned int request, va_list arg_ptr)
}
gpg_err_code_t
-_gpgrt_process_ctl (gpgrt_process_t process, unsigned int request, ...)
-{
- va_list arg_ptr;
- gpg_err_code_t ec;
-
- va_start (arg_ptr, request);
- ec = process_vctl (process, request, arg_ptr);
- va_end (arg_ptr);
- return ec;
-}
-
-gpg_err_code_t
_gpgrt_process_wait (gpgrt_process_t process, int hang)
{
gpg_err_code_t ec;
diff --git a/src/visibility.c b/src/visibility.c
index 65385be..72342bb 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -1126,66 +1126,118 @@ gpgrt_make_pipe (int filedes[2], estream_t *r_fp, int direction, int nonblock)
return _gpgrt_make_pipe (filedes, r_fp, direction, nonblock);
}
-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,
- gpgrt_process_t *r_process_id)
+void
+gpgrt_close_all_fds (int from, int *keep_fds)
+{
+ _gpgrt_close_all_fds (from, keep_fds);
+}
+#endif /*0*/
+
+#ifdef HAVE_W32_SYSTEM
+void
+gpgrt_spawn_actions_set_envvars (gpgrt_spawn_actions_t act,
+ char *envvars)
{
- return _gpgrt_spawn_process (pgmname, argv, except, flags,
- r_infp, r_outfp, r_errfp, r_process_id);
+ _gpgrt_spawn_actions_set_envvars (act, envvars);
}
+void
+gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t act, void *in,
+ void *out, void *err)
+{
+ _gpgrt_spawn_actions_set_redirect (act, in, out, err);
+}
+
+void
+gpgrt_spawn_actions_set_inherit_handles (gpgrt_spawn_actions_t act, void **hds)
+{
+ _gpgrt_spawn_actions_set_inherit_handles (act, hds);
+}
+#else
+void
+gpgrt_spawn_actions_set_environ (gpgrt_spawn_actions_t act, char **env)
+{
+ _gpgrt_spawn_actions_set_environ (act, env);
+}
+
+void
+gpgrt_spawn_actions_set_redirect (gpgrt_spawn_actions_t act, int in, int out, int err)
+{
+ _gpgrt_spawn_actions_set_redirect (act, in, out, err);
+}
+
+void
+gpgrt_spawn_actions_set_inherit_fds (gpgrt_spawn_actions_t act, const int *fds)
+{
+ _gpgrt_spawn_actions_set_inherit_fds (act, fds);
+}
+
+void
+gpgrt_spawn_actions_set_atfork (gpgrt_spawn_actions_t act, void (*atfork)(void *), void *arg)
+{
+ _gpgrt_spawn_actions_set_atfork (act, atfork, arg);
+}
+#endif
+
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, gpgrt_process_t *r_process_id)
+gpgrt_process_spawn (const char *pgmname, const char *argv1[],
+ unsigned int flags,
+ gpgrt_spawn_actions_t act,
+ gpgrt_process_t *r_process)
{
- return _gpgrt_spawn_process_fd (pgmname, argv, infd, outfd, errfd,
- spawn_cb, spawn_cb_arg, r_process_id);
+ return _gpgrt_process_spawn (pgmname, argv1, flags, act, r_process);
}
gpg_err_code_t
-gpgrt_spawn_process_detached (const char *pgmname, const char *argv[],
- const char *envp[])
+gpgrt_process_terminate (gpgrt_process_t process)
{
- return _gpgrt_spawn_process_detached (pgmname, argv, envp);
+ return _gpgrt_process_terminate (process);
}
gpg_err_code_t
-gpgrt_wait_process (const char *pgmname, gpgrt_process_t process_id, int hang,
- int *r_exitcode)
+gpgrt_process_get_fds (gpgrt_process_t process,
+ unsigned int flags,
+ int *r_fd_in, int *r_fd_out,
+ int *r_fd_err)
{
- return _gpgrt_wait_process (pgmname, process_id, hang, r_exitcode);
+ return _gpgrt_process_get_fds (process, flags, r_fd_in, r_fd_out, r_fd_err);
}
gpg_err_code_t
-gpgrt_wait_processes (const char **pgmnames, gpgrt_process_t *process_ids,
- size_t count, int hang, int *r_exitcodes)
+gpgrt_process_get_streams (gpgrt_process_t process,
+ unsigned int flags,
+ gpgrt_stream_t *r_fp_in,
+ gpgrt_stream_t *r_fp_out,
+ gpgrt_stream_t *r_fp_err)
{
- return _gpgrt_wait_processes (pgmnames, process_ids, count, hang,
- r_exitcodes);
+ return _gpgrt_process_get_streams (process, flags, r_fp_in, r_fp_out,
+ r_fp_err);
}
-void
-gpgrt_kill_process (gpgrt_process_t process_id)
+gpg_err_code_t
+gpgrt_process_ctl (gpgrt_process_t process,
+ unsigned int request, ...)
{
- _gpgrt_kill_process (process_id);
+ va_list arg_ptr;
+ gpg_err_code_t ec;
+
+ va_start (arg_ptr, request);
+ ec = _gpgrt_process_vctl (process, request, arg_ptr);
+ va_end (arg_ptr);
+ return ec;
}
-void
-gpgrt_release_process (gpgrt_process_t process_id)
+gpg_err_code_t
+gpgrt_process_wait (gpgrt_process_t process, int hang)
{
- _gpgrt_release_process (process_id);
+ return _gpgrt_process_wait (process, hang);
}
void
-gpgrt_close_all_fds (int from, int *keep_fds)
+gpgrt_process_release (gpgrt_process_t process)
{
- _gpgrt_close_all_fds (from, keep_fds);
+ _gpgrt_process_release (process);
}
-#endif /*0*/
int
diff --git a/src/visibility.h b/src/visibility.h
index e1bf045..5572c47 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -204,16 +204,17 @@ MARK_VISIBLE (_gpgrt_log_assert)
#if 0
MARK_VISIBLE (gpgrt_make_pipe)
-MARK_VISIBLE (gpgrt_spawn_process)
-MARK_VISIBLE (gpgrt_spawn_process_fd)
-MARK_VISIBLE (gpgrt_spawn_process_detached)
-MARK_VISIBLE (gpgrt_wait_process)
-MARK_VISIBLE (gpgrt_wait_processes)
-MARK_VISIBLE (gpgrt_kill_process)
-MARK_VISIBLE (gpgrt_release_process)
MARK_VISIBLE (gpgrt_close_all_fds)
#endif
+MARK_VISIBLE (gpgrt_process_spawn)
+MARK_VISIBLE (gpgrt_process_terminate)
+MARK_VISIBLE (gpgrt_process_get_fds)
+MARK_VISIBLE (gpgrt_process_get_streams)
+MARK_VISIBLE (gpgrt_process_ctl)
+MARK_VISIBLE (gpgrt_process_wait)
+MARK_VISIBLE (gpgrt_process_release)
+
MARK_VISIBLE (gpgrt_argparse)
MARK_VISIBLE (gpgrt_argparser)
MARK_VISIBLE (gpgrt_usage)
@@ -228,6 +229,16 @@ MARK_VISIBLE (gpgrt_cmp_version)
MARK_VISIBLE (gpgrt_fnameconcat)
MARK_VISIBLE (gpgrt_absfnameconcat)
+#ifdef HAVE_W32_SYSTEM
+MARK_VISIBLE (gpgrt_spawn_actions_set_envvars)
+MARK_VISIBLE (gpgrt_spawn_actions_set_redirect)
+MARK_VISIBLE (gpgrt_spawn_actions_set_inherit_handles)
+#else
+MARK_VISIBLE (gpgrt_spawn_actions_set_environ)
+MARK_VISIBLE (gpgrt_spawn_actions_set_redirect)
+MARK_VISIBLE (gpgrt_spawn_actions_set_inherit_fds)
+MARK_VISIBLE (gpgrt_spawn_actions_set_atfork)
+#endif
#undef MARK_VISIBLE
@@ -395,15 +406,29 @@ MARK_VISIBLE (gpgrt_absfnameconcat)
#define gpgrt_log_flush _gpgrt_USE_UNDERSCORED_FUNCTION
#define _gpgrt_log_assert _gpgrt_USE_UNDERSCORED_FUNCTION
+#if 0
#define gpgrt_make_pipe _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_spawn_process _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_spawn_process_fd _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_spawn_process_detached _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_wait_process _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_wait_processes _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_kill_process _gpgrt_USE_UNDERSCORED_FUNCTION
-#define gpgrt_release_process _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_close_all_fds _gpgrt_USE_UNDERSCORED_FUNCTION
+#endif
+
+#define gpgrt_process_spawn _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_terminate _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_get_fds _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_get_streams _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_ctl _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_wait _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_process_release _gpgrt_USE_UNDERSCORED_FUNCTION
+
+#ifdef HAVE_W32_SYSTEM
+#define gpgrt_spawn_actions_set_envvars _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_spawn_actions_set_redirect _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_spawn_actions_set_inherit_handles _gpgrt_USE_UNDERSCORED_FUNCTION
+#else
+#define gpgrt_spawn_actions_set_environ _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_spawn_actions_set_redirect _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_spawn_actions_set_inherit_fds _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_spawn_actions_set_atfork _gpgrt_USE_UNDERSCORED_FUNCTION
+#endif
#define gpgrt_argparse _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_argparser _gpgrt_USE_UNDERSCORED_FUNCTION