aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2023-07-24 05:55:09 +0000
committerNIIBE Yutaka <[email protected]>2023-07-24 05:55:09 +0000
commitbf25d0e39bdcff28dc690722b8defc21bebeeed3 (patch)
tree1bbf55097376da0b6efb77cf83da16683188994a /src
parentsocket: Don't call pre/post_syscall for bind. (diff)
downloadlibassuan-bf25d0e39bdcff28dc690722b8defc21bebeeed3.tar.gz
libassuan-bf25d0e39bdcff28dc690722b8defc21bebeeed3.zip
Add new pipe functions to control its server process.
* src/assuan-pipe-connect.c (assuan_pipe_wait_server_termination) (assuan_pipe_kill_server): New. * src/assuan.h.in: Add new functions. * src/libassuan.def: Add symbols for those functions. * src/libassuan.vers: Likewise. * src/system-posix.c (__assuan_waitpid): Extend the semantics for OPTIONS. * src/system-w32.c (__assuan_waitpid): Likewise. -- GnuPG-bug-id: T6487 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/assuan-pipe-connect.c37
-rw-r--r--src/assuan.h.in4
-rw-r--r--src/libassuan.def2
-rw-r--r--src/libassuan.vers2
-rw-r--r--src/system-posix.c7
-rw-r--r--src/system-w32.c26
6 files changed, 73 insertions, 5 deletions
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c
index c116d1d..9669cb3 100644
--- a/src/assuan-pipe-connect.c
+++ b/src/assuan-pipe-connect.c
@@ -451,3 +451,40 @@ assuan_pipe_connect (assuan_context_t ctx,
flags);
}
+gpg_error_t
+assuan_pipe_wait_server_termination (assuan_context_t ctx, int *status,
+ int no_hang)
+{
+ assuan_pid_t pid;
+
+ if (ctx->server_proc == -1)
+ return _assuan_error (ctx, GPG_ERR_NO_SERVICE);
+
+ pid = _assuan_waitpid (ctx, ctx->server_proc, 0, status, no_hang);
+ if (pid == -1)
+ return _assuan_error (ctx, gpg_err_code_from_syserror ());
+ else if (pid == 0)
+ return _assuan_error (ctx, GPG_ERR_TIMEOUT);
+
+ /* We did wait on the process already, so, not any more. */
+ ctx->flags.no_waitpid = 1;
+ return 0;
+}
+
+gpg_error_t
+assuan_pipe_kill_server (assuan_context_t ctx)
+{
+ if (ctx->server_proc == -1)
+ ; /* No pid available can't send a kill. */
+ else
+ {
+ _assuan_pre_syscall ();
+#ifdef HAVE_W32_SYSTEM
+ TerminateProcess ((HANDLE)ctx->server_proc, 1);
+#else
+ kill (ctx->server_proc, SIGINT);
+#endif
+ _assuan_post_syscall ();
+ }
+ return 0;
+}
diff --git a/src/assuan.h.in b/src/assuan.h.in
index 30a243c..99444b8 100644
--- a/src/assuan.h.in
+++ b/src/assuan.h.in
@@ -514,6 +514,10 @@ int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce);
void assuan_sock_set_system_hooks (assuan_system_hooks_t system_hooks);
+gpg_error_t assuan_pipe_wait_server_termination (assuan_context_t ctx,
+ int *status, int no_hang);
+
+gpg_error_t assuan_pipe_kill_server (assuan_context_t ctx);
/* Set the default system callbacks. This is irreversible. */
void assuan_set_system_hooks (assuan_system_hooks_t system_hooks);
diff --git a/src/libassuan.def b/src/libassuan.def
index ebd2945..088400b 100644
--- a/src/libassuan.def
+++ b/src/libassuan.def
@@ -117,6 +117,8 @@ EXPORTS
assuan_sock_connect_byname @96
assuan_sock_set_system_hooks @97
assuan_sock_accept @98
+ assuan_pipe_wait_server_termination @99
+ assuan_pipe_kill_server @100
; END
diff --git a/src/libassuan.vers b/src/libassuan.vers
index e78d238..07612d4 100644
--- a/src/libassuan.vers
+++ b/src/libassuan.vers
@@ -106,6 +106,8 @@ LIBASSUAN_1.0 {
assuan_sock_connect_byname;
assuan_sock_set_system_hooks;
assuan_sock_accept;
+ assuan_pipe_wait_server_termination;
+ assuan_pipe_kill_server;
__assuan_close;
__assuan_pipe;
diff --git a/src/system-posix.c b/src/system-posix.c
index 5f3a7f2..7952907 100644
--- a/src/system-posix.c
+++ b/src/system-posix.c
@@ -398,12 +398,13 @@ assuan_pid_t
__assuan_waitpid (assuan_context_t ctx, assuan_pid_t pid, int nowait,
int *status, int options)
{
+ if (nowait)
+ return 0;
+
/* We can't just release the PID, a waitpid is mandatory. But
NOWAIT in POSIX systems just means the caller already did the
waitpid for this child. */
- if (! nowait)
- return waitpid (pid, NULL, 0);
- return 0;
+ return waitpid (pid, status, options ? WNOHANG : 0);
}
diff --git a/src/system-w32.c b/src/system-w32.c
index 523300a..25c2df2 100644
--- a/src/system-w32.c
+++ b/src/system-w32.c
@@ -603,8 +603,30 @@ assuan_pid_t
__assuan_waitpid (assuan_context_t ctx, assuan_pid_t pid, int nowait,
int *status, int options)
{
- CloseHandle ((HANDLE) pid);
- return 0;
+ int code;
+ DWORD exit_code;
+
+ (void)ctx;
+
+ if (nowait)
+ return 0;
+
+ code = WaitForSingleObject ((HANDLE)pid, options? 0: INFINITE);
+
+ if (code == WAIT_OBJECT_0)
+ {
+ if (status)
+ {
+ GetExitCodeProcess ((HANDLE)pid, &exit_code);
+ *status = (int)exit_code;
+ }
+ CloseHandle ((HANDLE)pid);
+ return pid;
+ }
+ else if (code == WAIT_TIMEOUT)
+ return 0;
+ else
+ return -1;
}