From cbc993efd7c38bb71bb179feed22d440474f4f36 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 13 Jul 2013 16:34:40 +0100 Subject: [PATCH] rand/noise.c (noise_filter): Use . The code was slightly incorrect previously: if the standard descriptors are closed to begin with, then the pipe ends up being closed on entry. As far as I know, this has never actually happened, but I have the machinery to fix this bug so I might as well use it. --- rand/noise.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/rand/noise.c b/rand/noise.c index aa45e03b..fb4c4531 100644 --- a/rand/noise.c +++ b/rand/noise.c @@ -47,6 +47,7 @@ #endif #include +#include #include #include "noise.h" @@ -262,20 +263,16 @@ int noise_filter(rand_pool *r, int good, const char *c) /* --- Handle the child end of the deal --- */ if (kid == 0) { - int f; + mdup_fd mfd[3]; + int f, i = 0; /* --- Set the pipe as standard output, close standard input --- */ - close(0); close(1); close(2); - - if (fd[1] != 1) { - if (dup2(fd[1], 1) < 0) _exit(127); - close(fd[1]); - } - - if ((f = open("/dev/null", O_RDONLY)) != 0 || - (f = open("/dev/null", O_WRONLY)) != 2) - _exit(127); + if ((f = open("/dev/null", O_RDONLY)) < 0) _exit(127); + mfd[i].cur = f; mfd[i].want = 0; i++; + mfd[i].cur = fd[1]; mfd[i].want = 1; i++; + mfd[i].cur = f; mfd[i].want = 2; i++; + if (mdup(mfd, i)) _exit(127); /* --- Play games with uids --- */ -- 2.11.0