From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 45A7D1F8C6 for ; Wed, 25 Aug 2021 03:16:47 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AC4D3858C2C for ; Wed, 25 Aug 2021 03:16:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AC4D3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629861406; bh=AXC6mg6jVOO0N4ZAyHUiJG0BvQeQXx5ErbCp0RDIJzY=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=d2U+txoFpjeYozhW2T7APaaabxTWZ+aG5Cm9deKvUIBvAqZ3Kj6JcOzcUXiMTEbzV 5rAj+K5zUD2tkYGtKfIensoDrthxJ5sKgUvm3SpcO3QY5nuiaQtF3Yo76vdpG8LWit ha+P+L15is0+Q3W+rIfNa8fJfCk7t7laDdbXf3Fs= Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by sourceware.org (Postfix) with ESMTPS id 79A5B3858C2C for ; Wed, 25 Aug 2021 03:16:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 79A5B3858C2C Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 22EE140767 for ; Wed, 25 Aug 2021 03:16:13 +0000 (UTC) Received: by mail-pg1-f199.google.com with SMTP id q22-20020a63e956000000b002524787adb1so13286566pgj.3 for ; Tue, 24 Aug 2021 20:16:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3sIRf5EmG6RUzA0AdZPsQQVyCNSGNwyjK2FO0RPxnWo=; b=bf3J8pyEQ5VO82hTsLJvW9uivhZoM8XZ83r5J3kAEHg+k+FyipJf/YHUo6KYWsF+6W 9l7NgcmaGJsrllMAV35nBUxdk8IfPKIAGSleiXOCikgoEwJIoiK3iU64H6GX7Z1iuR8w IzcmxDkFX65GTmfdfbrxEn9F0fGpRJMzNEwzcSy/0dTA/Fj84Lw/pWbWrGnkYeb1w/jA vugqDZsOavMYm275dMNsSarpbdvigm2a7GirHBNk+5AOn8Wb6n9v1dSBSYcGKnOs/oYx SrnXyauxc7KiQ89bxPKT5I9gEBP04DnmbX0z9KOhR6/JLZ7WmczXBTdyTLwWEb0ADTJO JeBg== X-Gm-Message-State: AOAM532FAt/gQhQgCQ6Vf1Tste922Tk0kXiRjnQe0RTqcEdXnC+sLvoe i2aak0yCtYlloEiJpqGFkvGBESbupt4YRIVSZ8LSxIvqc/jIa6/m0NSkorEh6WpCrSas4Ml8aOS 6x19x5HWNah/ykDTVBCoHr6Y1ndWCnddwVTOqHNOCDrsY6qyYXPmXvw== X-Received: by 2002:a17:90b:360c:: with SMTP id ml12mr6837441pjb.158.1629861370779; Tue, 24 Aug 2021 20:16:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGr7gVMAlLTiV6HcfKwvi2udEhkkdhWMa82wAwrf9NN2O3sLYqKRpUS7c1ol+Au2pkEYZ4ncpcaZ+a/BwqgRQ= X-Received: by 2002:a17:90b:360c:: with SMTP id ml12mr6837410pjb.158.1629861370331; Tue, 24 Aug 2021 20:16:10 -0700 (PDT) MIME-Version: 1.0 References: <20210824192858.681680-1-adhemerval.zanella@linaro.org> <20210824192858.681680-3-adhemerval.zanella@linaro.org> In-Reply-To: <20210824192858.681680-3-adhemerval.zanella@linaro.org> Date: Wed, 25 Aug 2021 15:15:59 +1200 Message-ID: Subject: Re: [PATCH 2/2] Use support_open_dev_null_range io/tst-closefrom, misc/tst-close_range, and posix/tst-spawn5 (BZ #28260) To: Adhemerval Zanella Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Michael Hudson-Doyle via Libc-alpha Reply-To: Michael Hudson-Doyle Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Hi, thanks for looking at this. On Wed, 25 Aug 2021 at 07:29, Adhemerval Zanella via Libc-alpha < libc-alpha@sourceware.org> wrote: > It ensures a continuous range of file descriptor and avoid hitting > the RLIMIT_NOFILE. > > Checked on x86_64-linux-gnu. > --- > io/tst-closefrom.c | 15 +++----------- > posix/tst-spawn5.c | 13 +----------- > sysdeps/unix/sysv/linux/tst-close_range.c | 25 +++++++---------------- > 3 files changed, 11 insertions(+), 42 deletions(-) > > diff --git a/io/tst-closefrom.c b/io/tst-closefrom.c > index d4c187073c..0800e19f3f 100644 > --- a/io/tst-closefrom.c > +++ b/io/tst-closefrom.c > @@ -24,29 +24,20 @@ > #include > #include > #include > +#include > > #include > > #define NFDS 100 > > -static int > -open_multiple_temp_files (void) > -{ > - /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); > - for (int i = 1; i <= NFDS; i++) > - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), lowfd + i); > - return lowfd; > -} > - > static int > closefrom_test (void) > { > struct support_descriptors *descrs = support_descriptors_list (); > > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > - const int maximum_fd = lowfd + NFDS; > + const int maximum_fd = lowfd + NFDS - 1; > const int half_fd = lowfd + NFDS / 2; > const int gap = maximum_fd / 4; > There are two for loops in this function that iterate from 0: for (int i = 0; i < half_fd; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); for (int i = 0; i < gap; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); These should both iterate from i = lowfd I think? (And maybe should have done before this change?) Certainly they fail in the cases this patch is trying to fix. diff --git a/posix/tst-spawn5.c b/posix/tst-spawn5.c > index ac66738004..a95199af6b 100644 > --- a/posix/tst-spawn5.c > +++ b/posix/tst-spawn5.c > @@ -47,17 +47,6 @@ static int initial_argv_count; > > #define NFDS 100 > > -static int > -open_multiple_temp_files (void) > -{ > - /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); > - for (int i = 1; i <= NFDS; i++) > - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), > - lowfd + i); > - return lowfd; > -} > - > static int > parse_fd (const char *str) > { > @@ -185,7 +174,7 @@ spawn_closefrom_test (posix_spawn_file_actions_t *fa, > int lowfd, int highfd, > static void > do_test_closefrom (void) > { > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > const int half_fd = lowfd + NFDS / 2; > > /* Close half of the descriptors and check result. */ > diff --git a/sysdeps/unix/sysv/linux/tst-close_range.c > b/sysdeps/unix/sysv/linux/tst-close_range.c > index dccb6189c5..3548b10363 100644 > --- a/sysdeps/unix/sysv/linux/tst-close_range.c > +++ b/sysdeps/unix/sysv/linux/tst-close_range.c > This for look in close_range_unshare_test in this file needs to change too: for (int i = 0; i < NFDS; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); (presumably to iterate from low_fd to lowfd + NFDS). > @@ -36,23 +36,12 @@ > > #define NFDS 100 > > -static int > -open_multiple_temp_files (void) > -{ > - /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); > - for (int i = 1; i <= NFDS; i++) > - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), > - lowfd + i); > - return lowfd; > -} > - > static void > close_range_test_max_upper_limit (void) > { > struct support_descriptors *descrs = support_descriptors_list (); > > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > { > int r = close_range (lowfd, ~0U, 0); > @@ -68,7 +57,7 @@ close_range_test_max_upper_limit (void) > static void > close_range_test_common (int lowfd, unsigned int flags) > { > - const int maximum_fd = lowfd + NFDS; > + const int maximum_fd = lowfd + NFDS - 1; > const int half_fd = lowfd + NFDS / 2; > const int gap_1 = maximum_fd - 8; > > @@ -121,7 +110,7 @@ close_range_test (void) > struct support_descriptors *descrs = support_descriptors_list (); > > /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > close_range_test_common (lowfd, 0); > > @@ -146,7 +135,7 @@ close_range_test_subprocess (void) > struct support_descriptors *descrs = support_descriptors_list (); > > /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > struct support_stack stack = support_stack_alloc (4096); > > @@ -184,7 +173,7 @@ close_range_unshare_test (void) > struct support_descriptors *descrs1 = support_descriptors_list (); > > /* Check if the temporary file descriptor has no no gaps. */ > - int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > struct support_descriptors *descrs2 = support_descriptors_list (); > > @@ -226,9 +215,9 @@ static void > close_range_cloexec_test (void) > { > /* Check if the temporary file descriptor has no no gaps. */ > - const int lowfd = open_multiple_temp_files (); > + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); > > - const int maximum_fd = lowfd + NFDS; > + const int maximum_fd = lowfd + NFDS - 1; > const int half_fd = lowfd + NFDS / 2; > const int gap_1 = maximum_fd - 8; > > -- > 2.30.2 > Cheers, mwh