From 3bccb33ccd9028ff505d9979fd6c8a37393b892d Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 25 May 2023 13:49:09 +0900 Subject: 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: 6487 Signed-off-by: NIIBE Yutaka --- src/assuan-pipe-connect.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/assuan-pipe-connect.c') 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; +} -- cgit v1.2.3