gpgme-1-0-branch gpgme/assuan (ChangeLog assuan-connect.c
assuan-pipe-connect.c)
cvs user marcus
cvs at cvs.gnupg.org
Tue Dec 21 09:39:29 CET 2004
Date: Tuesday, December 21, 2004 @ 09:44:27
Author: marcus
Path: /cvs/gpgme/gpgme/assuan
Tag: gpgme-1-0-branch
Modified: ChangeLog assuan-connect.c assuan-pipe-connect.c
2004-12-16 Marcus Brinkmann <marcus at 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.
-----------------------+
ChangeLog | 7 ++
assuan-connect.c | 4 +
assuan-pipe-connect.c | 137 +++++++++++++++++++++++++++---------------------
3 files changed, 90 insertions(+), 58 deletions(-)
Index: gpgme/assuan/ChangeLog
diff -u gpgme/assuan/ChangeLog:1.22.2.1 gpgme/assuan/ChangeLog:1.22.2.2
--- gpgme/assuan/ChangeLog:1.22.2.1 Tue Dec 7 22:11:52 2004
+++ gpgme/assuan/ChangeLog Tue Dec 21 09:44:27 2004
@@ -1,3 +1,10 @@
+2004-12-16 Marcus Brinkmann <marcus at 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 at g10code.de>
* README.1st: Add copyright notice.
Index: gpgme/assuan/assuan-connect.c
diff -u gpgme/assuan/assuan-connect.c:1.7 gpgme/assuan/assuan-connect.c:1.7.2.1
--- gpgme/assuan/assuan-connect.c:1.7 Sat Feb 1 19:52:56 2003
+++ gpgme/assuan/assuan-connect.c Tue Dec 21 09:44:27 2004
@@ -39,7 +39,11 @@
{
if (ctx)
{
+#if 0
+ /* This may not work if the pipe is full and the other end is
+ blocked. */
assuan_write_line (ctx, "BYE");
+#endif
ctx->finish_handler (ctx);
ctx->deinit_handler (ctx);
ctx->deinit_handler = NULL;
Index: gpgme/assuan/assuan-pipe-connect.c
diff -u gpgme/assuan/assuan-pipe-connect.c:1.5 gpgme/assuan/assuan-pipe-connect.c:1.5.2.1
--- gpgme/assuan/assuan-pipe-connect.c:1.5 Mon Oct 6 18:17:12 2003
+++ gpgme/assuan/assuan-pipe-connect.c Tue Dec 21 09:44:27 2004
@@ -80,8 +80,11 @@
}
if (ctx->pid != -1)
{
+#if 0
+ /* This is already done by the double fork. */
waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */
ctx->pid = -1;
+#endif
}
return 0;
}
@@ -155,6 +158,8 @@
(*ctx)->deinit_handler = do_deinit;
(*ctx)->finish_handler = do_finish;
+ /* FIXME: Use _gpgme_io_spawn. The PID stored here is actually
+ soon useless. */
(*ctx)->pid = fork ();
if ((*ctx)->pid < 0)
{
@@ -168,82 +173,98 @@
if ((*ctx)->pid == 0)
{
- int i, n;
- char errbuf[512];
- int *fdp;
+ /* Intermediate child to prevent zombie processes. */
+ pid_t pid;
- /* Dup handles to stdin/stdout. */
- if (rp[1] != STDOUT_FILENO)
+ if ((pid = fork ()) == 0)
{
- if (dup2 (rp[1], STDOUT_FILENO) == -1)
+ /* Child. */
+
+ int i, n;
+ char errbuf[512];
+ int *fdp;
+
+ /* Dup handles to stdin/stdout. */
+ if (rp[1] != STDOUT_FILENO)
{
- LOG ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
+ if (dup2 (rp[1], STDOUT_FILENO) == -1)
+ {
+ LOG ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
}
- }
- if (wp[0] != STDIN_FILENO)
- {
- if (dup2 (wp[0], STDIN_FILENO) == -1)
+ if (wp[0] != STDIN_FILENO)
{
- LOG ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
+ if (dup2 (wp[0], STDIN_FILENO) == -1)
+ {
+ LOG ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
}
- }
-
- /* Dup stderr to /dev/null unless it is in the list of FDs to be
- passed to the child. */
- fdp = fd_child_list;
- if (fdp)
- {
- for (; *fdp != -1 && *fdp != STDERR_FILENO; fdp++)
- ;
- }
- if (!fdp || *fdp == -1)
- {
- int fd = open ("/dev/null", O_WRONLY);
- if (fd == -1)
+
+ /* Dup stderr to /dev/null unless it is in the list of FDs to be
+ passed to the child. */
+ fdp = fd_child_list;
+ if (fdp)
{
- LOG ("can't open `/dev/null': %s\n", strerror (errno));
- _exit (4);
+ for (; *fdp != -1 && *fdp != STDERR_FILENO; fdp++)
+ ;
}
- if (dup2 (fd, STDERR_FILENO) == -1)
+ if (!fdp || *fdp == -1)
{
- LOG ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
- _exit (4);
+ int fd = open ("/dev/null", O_WRONLY);
+ if (fd == -1)
+ {
+ LOG ("can't open `/dev/null': %s\n", strerror (errno));
+ _exit (4);
+ }
+ if (dup2 (fd, STDERR_FILENO) == -1)
+ {
+ LOG ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
+ _exit (4);
+ }
}
- }
- /* Close all files which will not be duped and are not in the
- fd_child_list. */
- n = sysconf (_SC_OPEN_MAX);
- if (n < 0)
- n = MAX_OPEN_FDS;
- for (i=0; i < n; i++)
- {
- if ( i == STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO)
- continue;
- fdp = fd_child_list;
- if (fdp)
+ /* Close all files which will not be duped and are not in the
+ fd_child_list. */
+ n = sysconf (_SC_OPEN_MAX);
+ if (n < 0)
+ n = MAX_OPEN_FDS;
+ for (i=0; i < n; i++)
{
- while (*fdp != -1 && *fdp != i)
- fdp++;
+ if ( i == STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO)
+ continue;
+ fdp = fd_child_list;
+ if (fdp)
+ {
+ while (*fdp != -1 && *fdp != i)
+ fdp++;
+ }
+
+ if (!(fdp && *fdp != -1))
+ close(i);
}
- if (!(fdp && *fdp != -1))
- close(i);
- }
- errno = 0;
+ errno = 0;
- 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",
- ASSUAN_Problem_Starting_Server, name, strerror (errno));
- errbuf[sizeof(errbuf)-1] = 0;
- writen (1, errbuf, strlen (errbuf));
- _exit (4);
+ 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",
+ ASSUAN_Problem_Starting_Server, name, strerror (errno));
+ errbuf[sizeof(errbuf)-1] = 0;
+ writen (1, errbuf, strlen (errbuf));
+ _exit (4);
+ } /* End child. */
+ if (pid == -1)
+ _exit (1);
+ else
+ _exit (0);
}
+ waitpid ((*ctx)->pid, NULL, 0);
+ (*ctx)->pid = -1;
+
close (rp[1]);
close (wp[0]);
More information about the Gnupg-commits
mailing list