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-pipe-connect.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/assuan-pipe-connect.c') diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c index 9c41aa9..ffb0202 100644 --- a/src/assuan-pipe-connect.c +++ b/src/assuan-pipe-connect.c @@ -78,7 +78,7 @@ do_finish (ASSUAN_CONTEXT ctx) close (ctx->outbound.fd); ctx->outbound.fd = -1; } - if (ctx->pid != -1) + if (ctx->pid != -1 && ctx->pid) { waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */ ctx->pid = -1; @@ -111,6 +111,7 @@ assuan_pipe_connect2 (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], AssuanError err; int rp[2]; int wp[2]; + char mypidstr[50]; if (!ctx || !name || !argv || !argv[0]) return ASSUAN_Invalid_Value; @@ -131,6 +132,8 @@ assuan_pipe_connect2 (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], /* FIXME: This is not MT safe */ } + sprintf (mypidstr, "%lu", (unsigned long)getpid ()); + if (pipe (rp) < 0) return ASSUAN_General_Error; @@ -239,6 +242,13 @@ assuan_pipe_connect2 (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], } errno = 0; + /* We store our parents pid in the environment so that the + execed assuan server is able to read the actual pid of the + client. The server can't use getppid becuase it might have + been double forked before the assuan server has been + initialized. */ + setenv ("_assuan_pipe_connect_pid", mypidstr, 1); + execv (name, argv); /* oops - use the pipe to tell the parent about it */ snprintf (errbuf, sizeof(errbuf)-1, "ERR %d can't exec `%s': %.50s\n", -- cgit v1.2.3