From patchwork Sat Dec 1 21:04:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 30515 Received: (qmail 28527 invoked by alias); 1 Dec 2018 21:04:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 28497 invoked by uid 89); 1 Dec 2018 21:04:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=letting X-HELO: mx1.redhat.com From: Florian Weimer To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] support: Close original descriptors in support_capture_subprocess References: <87muppo5hp.fsf@oldenburg.str.redhat.com> <87ftvh47xw.fsf@igel.home> <87va4dmh6i.fsf@oldenburg.str.redhat.com> <8736rh3tln.fsf@igel.home> <87r2f1m2nm.fsf@oldenburg.str.redhat.com> <87pnul2e47.fsf@igel.home> Date: Sat, 01 Dec 2018 22:04:42 +0100 In-Reply-To: <87pnul2e47.fsf@igel.home> (Andreas Schwab's message of "Sat, 01 Dec 2018 21:20:24 +0100") Message-ID: <87muppklg5.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 * Andreas Schwab: > On Dez 01 2018, Florian Weimer wrote: > >> This means that stdout_pipe[1] is at least 1 and stderr_pipe[1] is at >> least 3. We can never close descriptor 0, but the first xclose could >> close descriptor 1 or 2. Should I remove the second if condition? > > IMHO it would be cleaner that if a test needs a closed standard fd there > should be a separate functionality to set that up instead of letting the > test close it directly. What about this? Thanks, Florian 2018-12-01 Florian Weimer * support/support_capture_subprocess.c (support_capture_subprocess): Check that pipe descriptors have expected values. Close original pipe descriptors in subprocess. diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c index 6d2029e13b..93f6ea3102 100644 --- a/support/support_capture_subprocess.c +++ b/support/support_capture_subprocess.c @@ -59,8 +59,12 @@ support_capture_subprocess (void (*callback) (void *), void *closure) int stdout_pipe[2]; xpipe (stdout_pipe); + TEST_VERIFY (stdout_pipe[0] > STDERR_FILENO); + TEST_VERIFY (stdout_pipe[1] > STDERR_FILENO); int stderr_pipe[2]; xpipe (stderr_pipe); + TEST_VERIFY (stderr_pipe[0] > STDERR_FILENO); + TEST_VERIFY (stderr_pipe[1] > STDERR_FILENO); TEST_VERIFY (fflush (stdout) == 0); TEST_VERIFY (fflush (stderr) == 0); @@ -72,6 +76,8 @@ support_capture_subprocess (void (*callback) (void *), void *closure) xclose (stderr_pipe[0]); xdup2 (stdout_pipe[1], STDOUT_FILENO); xdup2 (stderr_pipe[1], STDERR_FILENO); + xclose (stdout_pipe[1]); + xclose (stderr_pipe[1]); callback (closure); _exit (0); }