diff options
author | NIIBE Yutaka <[email protected]> | 2022-11-07 02:46:35 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2022-11-07 02:46:35 +0000 |
commit | a1f480468a3b41f3843833654c0b56c33552519c (patch) | |
tree | 4baf51ae7ac5669c2c268868db909f684f3eb805 /src | |
parent | Show the pid of listening process in the hello line. (diff) | |
download | libassuan-a1f480468a3b41f3843833654c0b56c33552519c.tar.gz libassuan-a1f480468a3b41f3843833654c0b56c33552519c.zip |
w32: Support fd passing through pipe.
* src/assuan-pipe-connect.c (initial_handshake): Get peer's PID
from the initial interaction.
* src/assuan-pipe-server.c (assuan_init_pipe_server): Handle the case
of FILEDES == NULL on Windows.
* tests/Makefile.am [HAVE_W32_SYSTEM] (TESTS): Add fdpassing.
* tests/fdpassing.c: Remove including sys/socket.h and sys/wait.h.
(cmd_echo): Output to stder, as stdout is /dev/null.
(main): Support Windows.
--
GnuPG-bug-id: 6236
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/assuan-pipe-connect.c | 26 | ||||
-rw-r--r-- | src/assuan-pipe-server.c | 12 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c index 13ea3de..fc56334 100644 --- a/src/assuan-pipe-connect.c +++ b/src/assuan-pipe-connect.c @@ -104,7 +104,31 @@ initial_handshake (assuan_context_t ctx) if (err) TRACE1 (ctx, ASSUAN_LOG_SYSIO, "initial_handshake", ctx, "can't connect server: %s", gpg_strerror (err)); - else if (response != ASSUAN_RESPONSE_OK) + else if (response == ASSUAN_RESPONSE_OK) + { +#ifdef HAVE_W32_SYSTEM + const char *line = ctx->inbound.line + off; + int pid = ASSUAN_INVALID_PID; + + /* 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); + } + } + if (pid != ASSUAN_INVALID_PID) + ctx->pid = pid; +#else + ; +#endif + } + else { TRACE1 (ctx, ASSUAN_LOG_SYSIO, "initial_handshake", ctx, "can't connect server: `%s'", ctx->inbound.line); diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c index 8da54ad..5c960a6 100644 --- a/src/assuan-pipe-server.c +++ b/src/assuan-pipe-server.c @@ -82,8 +82,16 @@ assuan_init_pipe_server (assuan_context_t ctx, assuan_fd_t filedes[2]) return TRACE_ERR (rc); #ifdef HAVE_W32_SYSTEM - infd = filedes[0]; - outfd = filedes[1]; + if (filedes) + { + infd = filedes[0]; + outfd = filedes[1]; + } + else + { + infd = assuan_fd_from_posix_fd (0); + outfd = assuan_fd_from_posix_fd (1); + } #else s = getenv ("_assuan_connection_fd"); if (s && *s && is_valid_socket (s)) |