aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-pipe-connect.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2023-05-25 04:49:09 +0000
committerNIIBE Yutaka <[email protected]>2023-05-25 05:01:09 +0000
commit3bccb33ccd9028ff505d9979fd6c8a37393b892d (patch)
treeff36c2065b3e2fe11738d9068fdcbf012b814069 /src/assuan-pipe-connect.c
parentAllow use of global system hooks with API version 2. (diff)
downloadlibassuan-gniibe/t6487.tar.gz
libassuan-gniibe/t6487.zip
Add new pipe functions to control its server process.gniibe/t6487
* 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: 6487 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to '')
-rw-r--r--src/assuan-pipe-connect.c37
1 files changed, 37 insertions, 0 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;
+}