summaryrefslogtreecommitdiff
path: root/src/gpgrt-int.h
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2017-11-29 19:29:18 +0100
committerWerner Koch <wk@gnupg.org>2017-11-29 19:29:18 +0100
commit1865c0ba1769b407a3c504f1ab0a4278704a9fc1 (patch)
treeeb98697911bda0270e4aee8de308017642db8979 /src/gpgrt-int.h
parent8f41cc23b12485404203be5881aaaadb78696b4d (diff)
downloadlibgpg-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/gpgrt-int.h')
-rw-r--r--src/gpgrt-int.h110
1 files changed, 51 insertions, 59 deletions
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index e144ff1..2413257 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -122,6 +122,7 @@ char *_gpgrt_strconcat_core (const char *s1, va_list arg_ptr);
#define xtrymalloc(a) _gpgrt_malloc ((a))
#define xtrycalloc(a,b) _gpgrt_calloc ((a),(b))
#define xtryrealloc(a,b) _gpgrt_realloc ((a),(b))
+#define xtrystrdup(a) _gpgrt_strdup ((a))
@@ -553,6 +554,9 @@ int _gpgrt_logv_internal (int level, int ignore_arg_ptr,
/*
* Local prototypes for the spawn functions.
+ *
+ * We put the docs here because we have separate implementations in
+ * the files spawn-posix.c and spawn-w32.c
*/
/* Return the maximum number of currently allowed file descriptors.
@@ -574,27 +578,18 @@ int _gpgrt_logv_internal (int level, int ignore_arg_ptr,
* been initialized. Returns NULL on error and sets ERRNO accordingly. */
/* int *get_all_open_fds (void); */
+/* Create a pipe. The DIRECTION parameter gives the type of the created pipe:
+ * DIRECTION < 0 := Inbound pipe: On Windows the write end is inheritable.
+ * DIRECTION > 0 := Outbound pipe: On Windows the read end is inheritable.
+ * If R_FP is NULL a standard pipe and no stream is created, DIRECTION
+ * should then be 0. */
+gpg_err_code_t _gpgrt_make_pipe (int filedes[2], estream_t *r_fp,
+ int direction, int nonblock);
-/* Portable function to create a pipe. Under Windows the write end is
- * inheritable. If R_FP is not NULL, an estream is created for the
- * write end and stored at R_FP. */
-gpg_error_t gnupg_create_inbound_pipe (int filedes[2],
- estream_t *r_fp, int nonblock);
-
-/* Portable function to create a pipe. Under Windows the read end is
- * inheritable. If R_FP is not NULL, an estream is created for the
- * write end and stored at R_FP. */
-gpg_error_t gnupg_create_outbound_pipe (int filedes[2],
- estream_t *r_fp, int nonblock);
-
-/* Portable function to create a pipe. Under Windows both ends are
- * inheritable. */
-gpg_error_t gnupg_create_pipe (int filedes[2]);
-
-
-#define GNUPG_SPAWN_NONBLOCK 16
-#define GNUPG_SPAWN_RUN_ASFW 64
-#define GNUPG_SPAWN_DETACHED 128
+/* Convenience macros to create a pipe. */
+#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 the program PGMNAME.
@@ -618,51 +613,60 @@ gpg_error_t gnupg_create_pipe (int filedes[2]);
* descriptors, terminated by an entry with the value (-1). These
* file descriptors won't be closed before spawning a new program.
*
- * Returns 0 on success or an error code. Calling gnupg_wait_process
- * and gnupg_release_process is required if the function succeeded.
+ * Returns 0 on success or an error code. Calling gpgrt_wait_process
+ * and gpgrt_release_process is required if the function succeeded.
*
* FLAGS is a bit vector:
*
- * GNUPG_SPAWN_NONBLOCK
+ * GPGRT_SPAWN_NONBLOCK
* If set the two output streams are created in non-blocking
* mode and the input stream is switched to non-blocking mode.
* This is merely a convenience feature because the caller
* could do the same with gpgrt_set_nonblock. Does not yet
* work for Windows.
*
- * GNUPG_SPAWN_DETACHED
+ * GPGRT_SPAWN_DETACHED
* If set the process will be started as a background process.
* This flag is only useful under W32 (but not W32CE) systems,
* so that no new console is created and pops up a console
* window when starting the server. Does not work on W32CE.
*
- * GNUPG_SPAWN_RUN_ASFW
+ * GPGRT_SPAWN_RUN_ASFW
* On W32 (but not on W32CE) run AllowSetForegroundWindow for
* the child. Note that due to unknown problems this actually
* allows SetForegroundWindow for all children of this process.
*/
-gpg_error_t
-gnupg_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);
+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);
-/* Simplified version of gnupg_spawn_process. This function forks and
+/* Simplified version of gpgrt_spawn_process. This function forks and
* then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout
* and ERRFD to stderr (any of them may be -1 to connect them to
* /dev/null). The arguments for the process are expected in the NULL
* terminated array ARGV. The program name itself should not be
- * included there. Calling gnupg_wait_process and
- * gnupg_release_process is required. Returns 0 on success or an
+ * included there. Calling gpgrt_wait_process and
+ * gpgrt_release_process is required. Returns 0 on success or an
* error code. */
-gpg_error_t gnupg_spawn_process_fd (const char *pgmname,
- const char *argv[],
- int infd, int outfd, int errfd,
- pid_t *pid);
+gpg_err_code_t _gpgrt_spawn_process_fd (const char *pgmname,
+ const char *argv[],
+ int infd, int outfd, int errfd,
+ pid_t *pid);
+/* 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
+ * programname is automatically passed as first argument).
+ * Environment strings in ENVP are set. An error is returned if
+ * pgmname is not executable; to make this work it is necessary to
+ * provide an absolute file name. */
+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.
@@ -688,34 +692,22 @@ gpg_error_t gnupg_spawn_process_fd (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_error_t gnupg_wait_process (const char *pgmname, pid_t pid, int hang,
- int *r_exitcode);
-
-/* Like gnupg_wait_process, but for COUNT processes. */
-gpg_error_t gnupg_wait_processes (const char **pgmnames, pid_t *pids,
- size_t count, int hang, int *r_exitcodes);
+gpg_err_code_t _gpgrt_wait_process (const char *pgmname, pid_t pid, 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);
/* Kill a process; that is send an appropriate signal to the process.
- * gnupg_wait_process must be called to actually remove the process
+ * gpgrt_wait_process must be called to actually remove the process
* from the system. An invalid PID is ignored. */
-void gnupg_kill_process (pid_t pid);
+void _gpgrt_kill_process (pid_t pid);
/* 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 gnupg_release_process (pid_t pid);
-
-
-/* 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
- * programname is automatically passed as first argument).
- * Environment strings in ENVP are set. An error is returned if
- * pgmname is not executable; to make this work it is necessary to
- * provide an absolute file name. */
-gpg_error_t gnupg_spawn_process_detached (const char *pgmname,
- const char *argv[],
- const char *envp[] );
+void _gpgrt_release_process (pid_t pid);