2004-12-16 Marcus Brinkmann <marcus@g10code.de>

* assuan-pipe-connect.c (do_finish): Do not wait for child to finish.
	(assuan_pipe_connect): Use double-fork approach.
	* assuan-connect.c (assuan_disconnect): Do not write BYE to the
	status line.
This commit is contained in:
Marcus Brinkmann 2004-12-21 08:44:27 +00:00
parent 7b6dad7dcd
commit fc3ab2e2c5
3 changed files with 96 additions and 64 deletions

View File

@ -1,3 +1,10 @@
2004-12-16 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (do_finish): Do not wait for child to finish.
(assuan_pipe_connect): Use double-fork approach.
* assuan-connect.c (assuan_disconnect): Do not write BYE to the
status line.
2004-12-07 Marcus Brinkmann <marcus@g10code.de> 2004-12-07 Marcus Brinkmann <marcus@g10code.de>
* README.1st: Add copyright notice. * README.1st: Add copyright notice.

View File

@ -39,7 +39,11 @@ assuan_disconnect (ASSUAN_CONTEXT ctx)
{ {
if (ctx) if (ctx)
{ {
#if 0
/* This may not work if the pipe is full and the other end is
blocked. */
assuan_write_line (ctx, "BYE"); assuan_write_line (ctx, "BYE");
#endif
ctx->finish_handler (ctx); ctx->finish_handler (ctx);
ctx->deinit_handler (ctx); ctx->deinit_handler (ctx);
ctx->deinit_handler = NULL; ctx->deinit_handler = NULL;

View File

@ -80,8 +80,11 @@ do_finish (ASSUAN_CONTEXT ctx)
} }
if (ctx->pid != -1) if (ctx->pid != -1)
{ {
#if 0
/* This is already done by the double fork. */
waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */ waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */
ctx->pid = -1; ctx->pid = -1;
#endif
} }
return 0; return 0;
} }
@ -155,6 +158,8 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
(*ctx)->deinit_handler = do_deinit; (*ctx)->deinit_handler = do_deinit;
(*ctx)->finish_handler = do_finish; (*ctx)->finish_handler = do_finish;
/* FIXME: Use _gpgme_io_spawn. The PID stored here is actually
soon useless. */
(*ctx)->pid = fork (); (*ctx)->pid = fork ();
if ((*ctx)->pid < 0) if ((*ctx)->pid < 0)
{ {
@ -168,6 +173,13 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
if ((*ctx)->pid == 0) if ((*ctx)->pid == 0)
{ {
/* Intermediate child to prevent zombie processes. */
pid_t pid;
if ((pid = fork ()) == 0)
{
/* Child. */
int i, n; int i, n;
char errbuf[512]; char errbuf[512];
int *fdp; int *fdp;
@ -233,6 +245,7 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
if (!(fdp && *fdp != -1)) if (!(fdp && *fdp != -1))
close(i); close(i);
} }
errno = 0; errno = 0;
execv (name, argv); execv (name, argv);
@ -242,8 +255,16 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
errbuf[sizeof(errbuf)-1] = 0; errbuf[sizeof(errbuf)-1] = 0;
writen (1, errbuf, strlen (errbuf)); writen (1, errbuf, strlen (errbuf));
_exit (4); _exit (4);
} /* End child. */
if (pid == -1)
_exit (1);
else
_exit (0);
} }
waitpid ((*ctx)->pid, NULL, 0);
(*ctx)->pid = -1;
close (rp[1]); close (rp[1]);
close (wp[0]); close (wp[0]);