diff options
author | Werner Koch <wk@gnupg.org> | 2017-11-29 19:29:18 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2017-11-29 19:29:18 +0100 |
commit | 1865c0ba1769b407a3c504f1ab0a4278704a9fc1 (patch) | |
tree | eb98697911bda0270e4aee8de308017642db8979 /src/gpg-error.h.in | |
parent | 8f41cc23b12485404203be5881aaaadb78696b4d (diff) | |
download | libgpg-error-1865c0ba1769b407a3c504f1ab0a4278704a9fc1.tar.gz |
core: Implement the spawn functions.
* src/gpg-error.h.in (GPGRT_SPAWN_NONBLOCK): New const.
(GPGRT_SPAWN_RUN_ASFW): New const.
(GPGRT_SPAWN_DETACHED): New const.
(gpgrt_make_pipe): New function.
(gpgrt_create_pipe): New macro.
(gpgrt_create_inbound_pipe): New macro.
(gpgrt_create_outbound_pipe): New macro.
(gpgrt_spawn_process): New function.
(gpgrt_spawn_process_fd): New function.
(gpgrt_spawn_process_detached): New function.
(gpgrt_wait_process): New function.
(gpgrt_wait_processes): New function.
(gpgrt_kill_process): New function.
(gpgrt_release_process): New function.
* src/gpg-error.def.in, src/gpg-error.vers: Add new functions.
* src/visibility.c, src/visibility.h: Add wrappers for new functions.
* src/spawn-posix.c: Rework to better fit the use in gpgrt. Rename
all public function with a _gpgrt prefix.
* src/spawn-w32.c: Ditto.
* src/gpgrt-int.h: Likewise.
* src/Makefile.am (arch_sources): Add spawn-posix.c and spawn-w32.c.
* src/w32-add.h: Add pid_t typedef as a temporary hack.
* configure.ac: Check for signal.h and getrlimit.
(AC_FUNC_FORK): New.
--
This does build but porting the tests and further changes are
required. Don't assume that the API for the new fucntions is stable.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/gpg-error.h.in')
-rw-r--r-- | src/gpg-error.h.in | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in index 20d196a..991636d 100644 --- a/src/gpg-error.h.in +++ b/src/gpg-error.h.in @@ -1025,6 +1025,57 @@ void _gpgrt_log_assert (const char *expr, const char *file, int line, #endif /*GPGRT_ENABLE_LOG_MACROS*/ + +/* + * Spawn functions + */ + +#define GPGRT_SPAWN_NONBLOCK 16 /* Set the streams to non-blocking. */ +#define GPGRT_SPAWN_RUN_ASFW 64 /* Use AllowSetForegroundWindow on W32. */ +#define GPGRT_SPAWN_DETACHED 128 /* Start the process in the background. */ + +/* Function and convenience macros to create pipes. */ +gpg_err_code_t gpgrt_make_pipe (int filedes[2], estream_t *r_fp, + int direction, int nonblock); +#define gpgrt_create_pipe(a) gpgrt_make_pipe ((a),NULL, 0, 0); +#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)); + + +/* Fork and exec PGMNAME. */ +gpg_err_code_t gpgrt_spawn_process (const char *pgmname, const char *argv[], + int *execpt, void (*preexec)(void), + unsigned int flags, + estream_t *r_infp, + estream_t *r_outfp, + estream_t *r_errfp, + pid_t *pid); + +/* 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, + pid_t *pid); + +/* 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[] ); + +/* Wait for a single process. */ +gpg_err_code_t gpgrt_wait_process (const char *pgmname, pid_t pid, int hang, + int *r_exitcode); + +/* Wait for a multiple processes. */ +gpg_err_code_t gpgrt_wait_processes (const char **pgmnames, pid_t *pids, + size_t count, int hang, int *r_exitcodes); + +/* Kill the process identified by PID. */ +void gpgrt_kill_process (pid_t pid); + +/* Release process resources identified by PID. */ +void gpgrt_release_process (pid_t pid); + + #ifdef __cplusplus } |