From 6350f796fdd1c7519c35a9cd71b33b6dafc5ed3a Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 17 May 2023 10:55:17 +0900 Subject: w32: Cleaner semantics for PID and Process handle. * src/assuan-defs.h (struct assuan_context_s): Introduce SERVER_PROC member. Clarify the use of PROCESS_ID and PID. Introduce assuan_pid_t for internal use of process id or handle. * src/assuan.h.in: Follow the change. * src/assuan.c (assuan_new_ext): Likewise. * src/client.c (_assuan_client_finish): Likewise. * src/assuan-pipe-connect.c (pipe_connect): Likewise. * src/server.c (_assuan_server_finish): Likewise. * src/system-posix.c: Likewise. * src/system-w32.c: Likewise. * src/system.c: Likewise. * src/assuan-pipe-server.c (assuan_init_pipe_server) [HAVE_W32_SYSTEM]: Exclude the use of _assuan_pipe_connect_pid. * src/assuan-socket-server.c (accept_connection_bottom) [HAVE_W32_SYSTEM]: Exclude the use of the member peercred.pid. * src/assuan-socket.c (_assuan_sock_check_nonce): Support Cygwin Unix domain emulation for having valid client process ID. * src/context.c (assuan_get_pid): Clarify the use cases. * src/posix-types.inc.h, src/w32-types.inc.h: Introduce assuan_pid_t. -- GnuPG-bug-id: 6487 Signed-off-by: NIIBE Yutaka --- src/context.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/context.c') diff --git a/src/context.c b/src/context.c index 947df76..e41b60b 100644 --- a/src/context.c +++ b/src/context.c @@ -207,10 +207,30 @@ assuan_set_error (assuan_context_t ctx, gpg_error_t err, const char *text) pid_t assuan_get_pid (assuan_context_t ctx) { +#if defined(HAVE_W32_SYSTEM) + TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pid", ctx, + "pid=%i", ctx ? ctx->process_id : -1); +#else TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pid", ctx, "pid=%i", ctx ? ctx->pid : -1); +#endif - return (ctx && ctx->pid) ? ctx->pid : ASSUAN_INVALID_PID; + if (!ctx) + return ASSUAN_INVALID_PID; + + if (ctx->flags.is_server) +#if defined(HAVE_W32_SYSTEM) + return ctx->process_id; +#else + return ctx->pid; +#endif + else + /* + * This use case of getting internal process reference by the + * application should be fixed. It's here, only for backward + * compatibility. + */ + return ctx->server_proc; } -- cgit v1.2.3