From 93595de1ede96dedfcaa93c7442536a2cde0b6ef Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 21 Apr 2004 14:42:17 +0000 Subject: * assuan-socket-server.c (accept_connection_bottom): Save the pid of the peer if it is available. * assuan-socket-connect.c (assuan_socket_connect): Do not save the dummy SERVED_PID arg. * assuan-pipe-connect.c (do_finish): Don't wait if the pid is 0. (assuan_pipe_connect2): Store the parents pid in the environment of the child. * assuan-pipe-server.c (assuan_init_pipe_server): Initialize the peer's pid from the environment. * assuan-connect.c (assuan_get_pid): Do not return 0 as a PID. --- src/assuan-socket-server.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/assuan-socket-server.c') diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c index d92e6e4..e81ee50 100644 --- a/src/assuan-socket-server.c +++ b/src/assuan-socket-server.c @@ -34,14 +34,16 @@ accept_connection_bottom (ASSUAN_CONTEXT ctx) { int fd = ctx->connected_fd; - ctx->client_pid = (pid_t)-1; #ifdef HAVE_SO_PEERCRED { + /* This overrides any already set PID if the function returns a + valid one. */ struct ucred cr; int cl = sizeof cr; - if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) ) - ctx->client_pid = cr.pid; + if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) + && cr.pid != (pid_t)-1 && cr.pid ) + ctx->pid = cr.pid; } #endif @@ -68,7 +70,6 @@ accept_connection (ASSUAN_CONTEXT ctx) struct sockaddr_un clnt_addr; size_t len = sizeof clnt_addr; - ctx->client_pid = (pid_t)-1; fd = accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); if (fd == -1) { -- cgit v1.2.3