summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-10-13 16:21:09 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2022-10-13 16:21:09 +0900
commitd2db52be26c191e4faaf925d5483d8a7ef0d0da8 (patch)
tree10c599061bab5057a04a956e494d3c0999f144d2
parentb7d3f7c7740f28521fb9a9e70eeb0ec546e659f3 (diff)
downloadlibassuan-d2db52be26c191e4faaf925d5483d8a7ef0d0da8.tar.gz
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 <gniibe@fsij.org>
-rw-r--r--src/assuan-listen.c2
-rw-r--r--src/assuan-socket-connect.c27
-rw-r--r--src/client.c3
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;
}