From e8a547c3e9b1343206cc691ec88fc41db03a9d6e Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 19 Dec 2001 00:23:25 +0000 Subject: [PATCH] Update from newpg. --- trunk/assuan/ChangeLog | 19 ++++++++++++++----- trunk/assuan/assuan-connect.c | 35 +++++++++++++++++++++++++++++++---- trunk/assuan/assuan-handler.c | 7 ++++++- trunk/assuan/assuan-listen.c | 26 ++++++++++++++++++++++++++ trunk/assuan/assuan.h | 6 +++--- 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/trunk/assuan/ChangeLog b/trunk/assuan/ChangeLog index 7b357b6..dbf5f43 100644 --- a/trunk/assuan/ChangeLog +++ b/trunk/assuan/ChangeLog @@ -1,3 +1,17 @@ +2001-12-14 Marcus Brinkmann + + * 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 + + * 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 * assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use @@ -9,11 +23,6 @@ * assuan-defs.h (LINELENGTH): Define as ASSUAN_LINELENGTH. assuan.h: Define ASSUAN_LINELENGTH. -2001-12-13 Marcus Brinkmann - - * assuan-connect.c (assuan_pipe_connect): Remove code that closes - all the little file descriptors we set up. - 2001-12-13 Marcus Brinkmann * assuan-buffer.c (assuan_read_line): Fix order of execution to diff --git a/trunk/assuan/assuan-connect.c b/trunk/assuan/assuan-connect.c index b8ce1a9..613b54a 100644 --- a/trunk/assuan/assuan-connect.c +++ b/trunk/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/trunk/assuan/assuan-handler.c b/trunk/assuan/assuan-handler.c index 614f83d..a82bd53 100644 --- a/trunk/assuan/assuan-handler.c +++ b/trunk/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/trunk/assuan/assuan-listen.c b/trunk/assuan/assuan-listen.c index 822ef32..57fe4b6 100644 --- a/trunk/assuan/assuan-listen.c +++ b/trunk/assuan/assuan-listen.c @@ -22,6 +22,7 @@ #include #include #include +#include #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/trunk/assuan/assuan.h b/trunk/assuan/assuan.h index 485ad22..cddc98c 100644 --- a/trunk/assuan/assuan.h +++ b/trunk/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*/ - - -- 2.26.2