From d2db52be26c191e4faaf925d5483d8a7ef0d0da8 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 13 Oct 2022 16:21:09 +0900 Subject: Set ctx->pid even with TCP connection, useful for Windows. * src/assuan-listen.c (assuan_accept): Use PID to notify client. * src/assuan-socket-connect.c (_assuan_connect_finalize): Parse the initial message to extract remote PID. * src/client.c (_assuan_client_finish): Only call waitpid when it's not socket. -- Signed-off-by: NIIBE Yutaka --- src/assuan-listen.c | 2 +- src/assuan-socket-connect.c | 27 ++++++++++++++++++++++++++- src/client.c | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/assuan-listen.c b/src/assuan-listen.c index 6755d59..93560ff 100644 --- a/src/assuan-listen.c +++ b/src/assuan-listen.c @@ -117,7 +117,7 @@ assuan_accept (assuan_context_t ctx) else { static char const okstr[] = "OK Pleased to meet you"; - pid_t apid = assuan_get_pid (ctx); + pid_t apid = getpid (); if (apid != ASSUAN_INVALID_PID) { char tmpbuf[50]; diff --git a/src/assuan-socket-connect.c b/src/assuan-socket-connect.c index d7adc31..d13514a 100644 --- a/src/assuan-socket-connect.c +++ b/src/assuan-socket-connect.c @@ -131,7 +131,32 @@ _assuan_connect_finalize (assuan_context_t ctx, assuan_fd_t fd, if (err) TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_socket_connect", ctx, "can't connect to server: %s\n", gpg_strerror (err)); - else if (response != ASSUAN_RESPONSE_OK) + else if (response == ASSUAN_RESPONSE_OK) + { + const char *line = ctx->inbound.line + off; + int pid = ASSUAN_INVALID_PID; + + fprintf (stderr, "%s\n", line); + + /* Parse the message: OK ..., process %i */ + line = strchr (line, ','); + if (line) + { + line = strchr (line + 1, ' '); + if (line) + { + line = strchr (line + 1, ' '); + if (line) + { + pid = atoi (line + 1); + fprintf (stderr, "PID=%d (%s)\n", pid, line+1); + } + } + } + if (pid != ASSUAN_INVALID_PID) + ctx->pid = pid; + } + else { char *sname = _assuan_encode_c_string (ctx, ctx->inbound.line); if (sname) diff --git a/src/client.c b/src/client.c index e0759f6..1746788 100644 --- a/src/client.c +++ b/src/client.c @@ -50,7 +50,8 @@ _assuan_client_finish (assuan_context_t ctx) } if (ctx->pid != ASSUAN_INVALID_PID && ctx->pid) { - _assuan_waitpid (ctx, ctx->pid, ctx->flags.no_waitpid, NULL, 0); + if (!ctx->flags.is_socket) + _assuan_waitpid (ctx, ctx->pid, ctx->flags.no_waitpid, NULL, 0); ctx->pid = ASSUAN_INVALID_PID; } -- cgit v1.2.1