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=-5.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 A972C1F8C6 for ; Wed, 25 Aug 2021 11:46:47 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 822303857C5B for ; Wed, 25 Aug 2021 11:46:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 822303857C5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629892006; bh=7LW7hK5nfnDh+icETXkVDytzqj07qkpwEFYAXOaWypc=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=LLw3EZ9MF0lWTNBDgD8I5csHRooi/gM7tDJfZJcP6eCGnWGNbdATzlyx1FQuFfZqq ATcyAgeLgIJ0eKEGRR+YdXFa7/wqHieQQDM01zUOoV9iHjCJgnq/0YUMVZQJd/mdWy ZsmKf4oTa5xtYy2AXgJaMm07VUi9kOPp9dGhbcvo= Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 32EDA3858400 for ; Wed, 25 Aug 2021 11:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32EDA3858400 Received: by mail-qt1-x834.google.com with SMTP id x5so19493250qtq.13 for ; Wed, 25 Aug 2021 04:46:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7LW7hK5nfnDh+icETXkVDytzqj07qkpwEFYAXOaWypc=; b=DBbVWA9ZrE2XazAg18WyCGQV6ghErfwCAJ3+NXYAAERt50vrIOuFqUavAGURn2Ahe6 IHnojASMQSTzYKsOhMqz5g+MNIMvxE3eljkt0+eCodH2TDwhOMYiA74TO4qb3cGdesBg 9RvHriqsGOQwrDetFx27V7NMhswpgBA2v2yE46YsC128tyqgGq72VerahIovEppjS6zc Khi5vLlmOiigqFh25IPYi1EsOlLV+N0Ji2pDfXjPQ2apldmryd+qxbuDzCPm/514j7v/ c/k1vc/ODUVb+QcHepQVCwIDS66Olx6HKybuHsScy5UHWTpMHmKqMgumUc5PPKY1EWzl nlPg== X-Gm-Message-State: AOAM531yWoK7z/EYKiCpF5gGiiW13KnOhkWllRhG+xKUWOaFFuNlhKAK K0VoWrFVD8V+jC2CvU4T+5jIP3PPx1KtrA== X-Google-Smtp-Source: ABdhPJx4KMYvBHWi443qYaXw2DQfmJY1l+HitTyLu41ErOxah/umKMzb/lZyP/0/5ywtEKuSMLSIjw== X-Received: by 2002:ac8:57cc:: with SMTP id w12mr23231953qta.81.1629891976569; Wed, 25 Aug 2021 04:46:16 -0700 (PDT) Received: from ?IPv6:2804:431:c7ca:1a68:e3de:10e0:28dd:40db? ([2804:431:c7ca:1a68:e3de:10e0:28dd:40db]) by smtp.gmail.com with ESMTPSA id t66sm12763795qkc.3.2021.08.25.04.46.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Aug 2021 04:46:16 -0700 (PDT) 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: Michael Hudson-Doyle References: <20210824192858.681680-1-adhemerval.zanella@linaro.org> <20210824192858.681680-3-adhemerval.zanella@linaro.org> Message-ID: <61bf036c-033c-553e-1c45-3cf3fc3a305f@linaro.org> Date: Wed, 25 Aug 2021 08:46:14 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On 25/08/2021 05:40, Michael Hudson-Doyle wrote: > I found some more problems, updated patch attached. > > On Wed, 25 Aug 2021 at 15:41, Michael Hudson-Doyle > wrote: > > > > On Wed, 25 Aug 2021 at 15:15, Michael Hudson-Doyle > wrote: > > Hi, thanks for looking at this. > > On Wed, 25 Aug 2021 at 07:29, Adhemerval Zanella via Libc-alpha > 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  > > > I'm attaching a patch which when applied on top of this one makes these tests pass my hackish way of reproducing the issue: > > mwhudson@anduril:~/src/pkg/build-glibc$ bash -c 'exec 40 mwhudson@anduril:~/src/pkg/build-glibc$ bash -c 'exec 40   > Cheers, > mwh > Thanks for catching it, I add merged on the patch and I will commit this shortly.