From 0d3ffd103d24f878887802742d10beba4b53b479 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 3 May 2002 18:19:44 +0000 Subject: [PATCH] * assuan-pipe-connect.c (assuan_pipe_connect2): New to extend assuan_pipe_connect with some flags. Implemented a bitbucket for stderr. --- assuan/ChangeLog | 6 ++++++ assuan/assuan-pipe-connect.c | 33 +++++++++++++++++++++++++++++++-- assuan/assuan.h | 4 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/assuan/ChangeLog b/assuan/ChangeLog index 0ddf65cc..0cf53b89 100644 --- a/assuan/ChangeLog +++ b/assuan/ChangeLog @@ -1,3 +1,9 @@ +2002-05-03 Werner Koch + + * assuan-pipe-connect.c (assuan_pipe_connect2): New to extend + assuan_pipe_connect with some flags. Implemented a bitbucket for + stderr. + 2002-04-26 Werner Koch * Makefile.am: Create libtool libraries diff --git a/assuan/assuan-pipe-connect.c b/assuan/assuan-pipe-connect.c index ccfc1f01..6614dab9 100644 --- a/assuan/assuan-pipe-connect.c +++ b/assuan/assuan-pipe-connect.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "assuan-defs.h" @@ -102,8 +104,9 @@ do_deinit (ASSUAN_CONTEXT ctx) 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[], - int *fd_child_list) +assuan_pipe_connect2 (ASSUAN_CONTEXT *ctx, const char *name, + char *const argv[], int *fd_child_list, + unsigned int connect_flags) { static int fixed_signals = 0; AssuanError err; @@ -217,6 +220,23 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], close (wp[0]); } + if ((connect_flags & 1)) + { /* dup stderr to /dev/null so that the application output + won't get clobbered with output from the backend */ + int fdzero = open ("/dev/null", O_WRONLY); + if (fdzero == -1) + { + LOGERROR1 ("can't open `/dev/null': %s\n", strerror (errno)); + _exit (4); + } + if (dup2 (fdzero, 2) == -1) + { + LOGERROR1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno)); + _exit (4); + } + close (fdzero); + } + 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", @@ -254,6 +274,15 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], return err; } +AssuanError +assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], + int *fd_child_list) +{ + return assuan_pipe_connect2 (ctx, name, argv, fd_child_list, 0); +} + + + diff --git a/assuan/assuan.h b/assuan/assuan.h index a9340019..e18c46e6 100644 --- a/assuan/assuan.h +++ b/assuan/assuan.h @@ -175,6 +175,10 @@ int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd); /*-- assuan-pipe-connect.c --*/ AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[], int *fd_child_list); +AssuanError assuan_pipe_connect2 (ASSUAN_CONTEXT *ctx, const char *name, + char *const argv[], int *fd_child_list, + unsigned int connect_flags); + /*-- assuan-socket-connect.c --*/ AssuanError assuan_socket_connect (ASSUAN_CONTEXT *ctx, const char *name, pid_t server_pid);