aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-pipe-connect.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2004-04-21 14:42:17 +0000
committerWerner Koch <[email protected]>2004-04-21 14:42:17 +0000
commit93595de1ede96dedfcaa93c7442536a2cde0b6ef (patch)
treea0bd56b9a61f7f5301ea2337df1b215bbb318b38 /src/assuan-pipe-connect.c
parent* assuan-socket-server.c, assuan-socket-connect.c: Includes (diff)
downloadlibassuan-93595de1ede96dedfcaa93c7442536a2cde0b6ef.tar.gz
libassuan-93595de1ede96dedfcaa93c7442536a2cde0b6ef.zip
* 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.
Diffstat (limited to 'src/assuan-pipe-connect.c')
-rw-r--r--src/assuan-pipe-connect.c12
1 files changed, 11 insertions, 1 deletions
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",