+2001-12-14 Marcus Brinkmann <marcus@g10code.de>
+
+ * 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 <wk@gnupg.org>
+
+ * 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 <marcus@g10code.de>
* assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use
* assuan-defs.h (LINELENGTH): Define as ASSUAN_LINELENGTH.
assuan.h: Define ASSUAN_LINELENGTH.
-2001-12-13 Marcus Brinkmann <marcus@g10code.de>
-
- * assuan-connect.c (assuan_pipe_connect): Remove code that closes
- all the little file descriptors we set up.
-
2001-12-13 Marcus Brinkmann <marcus@g10code.de>
* assuan-buffer.c (assuan_read_line): Fix order of execution to
/* 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;
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)
{
if (ctx->bye_notify_fnc)
ctx->bye_notify_fnc (ctx);
+ assuan_close_input_fd (ctx);
+ assuan_close_output_fd (ctx);
return -1; /* pretty simple :-) */
}
{
if (ctx->reset_notify_fnc)
ctx->reset_notify_fnc (ctx);
+ assuan_close_input_fd (ctx);
+ assuan_close_output_fd (ctx);
return 0;
}
*
* 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.
*
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "assuan-defs.h"
}
+/* 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;
+}
+
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 --*/
/*-- 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);
}
#endif
#endif /*ASSUAN_H*/
-
-