From fe3ee5123602ac2b8af8d1209087c2c61274c8c5 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 27 Feb 2011 10:49:15 +0100 Subject: mailtrain: redirect stdout/stderr to /dev/null for execv This fixes a bug where sa-learn and similar tools fail because they cannot write to stdout or stderr at all, and propagate the error (EBADF or such). --- mailtrain.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mailtrain.c b/mailtrain.c index 41071bc..5529f03 100644 --- a/mailtrain.c +++ b/mailtrain.c @@ -71,7 +71,7 @@ static int run_sendmail(int mailfd, enum classification wanted) } else { char **argv; int sz = sizeof(char *) * (2 + extra_args_num + 1); - int i; + int i, fd; argv = i_malloc(sz); memset(argv, 0, sz); @@ -84,8 +84,10 @@ static int run_sendmail(int mailfd, enum classification wanted) argv[i + 1] = (char *) dest; dup2(mailfd, 0); - close(1); - close(2); + fd = open("/dev/null", O_WRONLY); + dup2(fd, 1); + dup2(fd, 2); + close(fd); execv(sendmail_binary, argv); _exit(1); /* not reached */ -- cgit v1.2.3