aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assuan/ChangeLog19
-rw-r--r--assuan/assuan-connect.c35
-rw-r--r--assuan/assuan-handler.c7
-rw-r--r--assuan/assuan-listen.c26
-rw-r--r--assuan/assuan.h6
5 files changed, 80 insertions, 13 deletions
diff --git a/assuan/ChangeLog b/assuan/ChangeLog
index 7b357b66..dbf5f43e 100644
--- a/assuan/ChangeLog
+++ b/assuan/ChangeLog
@@ -1,5 +1,19 @@
2001-12-14 Marcus Brinkmann <[email protected]>
+ * assuan-connect.c (assuan_pipe_connect): New argument
+ FD_CHILD_LIST. Don't close those fds.
+ * assuan.h: Likewise for prototype.
+
+2001-12-14 Werner Koch <[email protected]>
+
+ * assuan-listen.c (assuan_close_input_fd): New.
+ (assuan_close_output_fd): New.
+ * assuan-handler.c (std_handler_reset): Always close them after a
+ reset command.
+ (std_handler_bye): Likewise.
+
+2001-12-14 Marcus Brinkmann <[email protected]>
+
* assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use
it to save the length of the attic line.
Rediddle the code a bit to make it more clear what happens.
@@ -11,11 +25,6 @@
2001-12-13 Marcus Brinkmann <[email protected]>
- * assuan-connect.c (assuan_pipe_connect): Remove code that closes
- all the little file descriptors we set up.
-
-2001-12-13 Marcus Brinkmann <[email protected]>
-
* assuan-buffer.c (assuan_read_line): Fix order of execution to
get correct return values.
diff --git a/assuan/assuan-connect.c b/assuan/assuan-connect.c
index b8ce1a9c..613b54a1 100644
--- a/assuan/assuan-connect.c
+++ b/assuan/assuan-connect.c
@@ -71,9 +71,11 @@ writen ( int fd, const char *buffer, size_t length )
/* Connect to a server over a pipe, creating the assuan context and
returning it in CTX. The server filename is NAME, the argument
- vector in ARGV. */
+ vector in ARGV. FD_CHILD_LIST is a -1 terminated list of file
+ descriptors not to close in the child. */
AssuanError
-assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[])
+assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
+ int *fd_child_list)
{
static int fixed_signals = 0;
AssuanError err;
@@ -137,10 +139,35 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[])
if ((*ctx)->pid == 0)
{
+ int i, n;
char errbuf[512];
+#ifdef HAVE_JNLIB_LOGGING
+ int log_fd = log_get_fd ();
+#endif
+ /* close all files which will not be duped but keep stderr
+ and log_stream for now */
+ n = sysconf (_SC_OPEN_MAX);
+ if (n < 0)
+ n = MAX_OPEN_FDS;
+ for (i=0; i < n; i++)
+ {
+ int *fdp = fd_child_list;
- close (rp[0]);
- close (wp[1]);
+ if (fdp)
+ {
+ while (*fdp != -1 && *fdp != i)
+ fdp++;
+ }
+
+ if (!(fdp && *fdp != -1)
+ && i != fileno (stderr)
+#ifdef HAVE_JNLIB_LOGGING
+ && i != log_fd
+#endif
+ && i != rp[1] && i != wp[0])
+ close(i);
+ }
+ errno = 0;
/* Dup handles and to stdin/stdout and exec */
if (rp[1] != STDOUT_FILENO)
diff --git a/assuan/assuan-handler.c b/assuan/assuan-handler.c
index 614f83d8..a82bd537 100644
--- a/assuan/assuan-handler.c
+++ b/assuan/assuan-handler.c
@@ -54,6 +54,8 @@ std_handler_bye (ASSUAN_CONTEXT ctx, char *line)
{
if (ctx->bye_notify_fnc)
ctx->bye_notify_fnc (ctx);
+ assuan_close_input_fd (ctx);
+ assuan_close_output_fd (ctx);
return -1; /* pretty simple :-) */
}
@@ -68,6 +70,8 @@ std_handler_reset (ASSUAN_CONTEXT ctx, char *line)
{
if (ctx->reset_notify_fnc)
ctx->reset_notify_fnc (ctx);
+ assuan_close_input_fd (ctx);
+ assuan_close_output_fd (ctx);
return 0;
}
@@ -458,7 +462,8 @@ assuan_process_next (ASSUAN_CONTEXT ctx)
*
* Return all active filedescriptors for the given context. This
* function can be used to select on the fds and call
- * assuan_process_next() if there is an active one.
+ * assuan_process_next() if there is an active one. The first fd in
+ * the array is the one used for the command connection.
*
* Note, that write FDs are not yet supported.
*
diff --git a/assuan/assuan-listen.c b/assuan/assuan-listen.c
index 822ef32c..57fe4b66 100644
--- a/assuan/assuan-listen.c
+++ b/assuan/assuan-listen.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "assuan-defs.h"
@@ -106,3 +107,28 @@ assuan_get_output_fd (ASSUAN_CONTEXT ctx)
}
+/* Close the fd descriptor set by the command INPUT FD=n. We handle
+ this fd inside assuan so that we can do some initial checks */
+AssuanError
+assuan_close_input_fd (ASSUAN_CONTEXT ctx)
+{
+ if (!ctx || ctx->input_fd == -1)
+ return ASSUAN_Invalid_Value;
+ close (ctx->input_fd);
+ ctx->input_fd = -1;
+ return 0;
+}
+
+/* Close the fd descriptor set by the command OUTPUT FD=n. We handle
+ this fd inside assuan so that we can do some initial checks */
+AssuanError
+assuan_close_output_fd (ASSUAN_CONTEXT ctx)
+{
+ if (!ctx || ctx->output_fd == -1)
+ return ASSUAN_Invalid_Value;
+
+ close (ctx->output_fd);
+ ctx->output_fd = -1;
+ return 0;
+}
+
diff --git a/assuan/assuan.h b/assuan/assuan.h
index 485ad222..cddc98cb 100644
--- a/assuan/assuan.h
+++ b/assuan/assuan.h
@@ -136,6 +136,8 @@ AssuanError assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line);
AssuanError assuan_accept (ASSUAN_CONTEXT ctx);
int assuan_get_input_fd (ASSUAN_CONTEXT ctx);
int assuan_get_output_fd (ASSUAN_CONTEXT ctx);
+AssuanError assuan_close_input_fd (ASSUAN_CONTEXT ctx);
+AssuanError assuan_close_output_fd (ASSUAN_CONTEXT ctx);
/*-- assuan-pipe-server.c --*/
@@ -145,7 +147,7 @@ void assuan_deinit_pipe_server (ASSUAN_CONTEXT ctx);
/*-- assuan-connect.c --*/
AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name,
- char *const argv[]);
+ char *const argv[], int *fd_child_list);
void assuan_pipe_disconnect (ASSUAN_CONTEXT ctx);
pid_t assuan_get_pid (ASSUAN_CONTEXT ctx);
@@ -189,5 +191,3 @@ const char *assuan_strerror (AssuanError err);
}
#endif
#endif /*ASSUAN_H*/
-
-