From patchwork Tue Aug 24 19:28:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44784 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20D48385840A for ; Tue, 24 Aug 2021 19:30:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20D48385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629833459; bh=oxZCCoDVNzFTN+y9PyrLSEf5opnrRZ9MeAgkUmYexlI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SijbvDmjPUtcTniXpEJnOteWb1PlUb5sDIqicY0bzHctFi8XQ0AUwcxv1oVQsEuP5 IjodQHUCcj8sax8Il2jSxXeIDkAU1bDPLL1KOsofgO1nN1biGQrzK8ZpTpqTHhXz3T tzRpqjqA9VAGUTSI/hEKsqpGqguv/122L+C0iG8w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id 7EA013858405 for ; Tue, 24 Aug 2021 19:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EA013858405 Received: by mail-qv1-xf36.google.com with SMTP id jz1so12347933qvb.13 for ; Tue, 24 Aug 2021 12:29:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oxZCCoDVNzFTN+y9PyrLSEf5opnrRZ9MeAgkUmYexlI=; b=GRbEqdzXHjlH+g9IGtr1HqyWHrZnwmVaMRGAsr0ERK3isujZn5XrT7c3oMPiR6p2uP QzmdxsCQbLz4fGogViVEP55Inx0Gjh1hNRqhKJ4ubFdbY1P+yBctiWbErKCyktyUSYiP IJwRqRT0VfXAvZt1Fe91gZjTNt93052w/nmwWP0GsvGGXFvxKCBqW+lML4r5pfW/5gZD scxjuD+djzE7/ucxf1i/KvQW6pQtFC5690SbqLswXIVUbwLpOCJ5XlnQ5UzND0ws7OhN aLvqH+K0sFv+LWO92KauZ9E7GGYYQLBzZEvyeWNHXRzc6vtI9iwdM4VHF4KH0/TL44vC xIAA== X-Gm-Message-State: AOAM5326yC6TLJSpGHn7FNGPy5BULzwg7pbjLZtmlqZP9dqEkcWlixS2 UN8vpiEcg+gjaZEHl5IY05qkZBgwiVxfuw== X-Google-Smtp-Source: ABdhPJyF7nQy/9jK1CeVTUqzKnetF+M6s507yK3sDU06Y8euP67z57XqM+tF2Bf2yI+hKhr3sAzdIA== X-Received: by 2002:a0c:fde7:: with SMTP id m7mr4436764qvu.39.1629833342869; Tue, 24 Aug 2021 12:29:02 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:cd83:3337:ab4f:e3a1:7ba5]) by smtp.gmail.com with ESMTPSA id s20sm7482674qtw.14.2021.08.24.12.29.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 12:29:02 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/2] support: Add support_open_dev_null_range Date: Tue, 24 Aug 2021 16:28:57 -0300 Message-Id: <20210824192858.681680-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824192858.681680-1-adhemerval.zanella@linaro.org> References: <20210824192858.681680-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It returns a range of file descriptor referring to the '/dev/null' pathname. The function takes care of restarting the open range if a file descriptor is found within the specified range and also increases RLIMIT_NOFILE if required. Checked on x86_64-linux-gnu. --- support/Makefile | 2 + support/support-open-dev-null-range.c | 134 +++++++++++++++++++++ support/support.h | 8 ++ support/tst-support-open-dev-null-range.c | 137 ++++++++++++++++++++++ 4 files changed, 281 insertions(+) create mode 100644 support/support-open-dev-null-range.c create mode 100644 support/tst-support-open-dev-null-range.c diff --git a/support/Makefile b/support/Makefile index a462781718..6332e7b607 100644 --- a/support/Makefile +++ b/support/Makefile @@ -66,6 +66,7 @@ libsupport-routines = \ support_path_support_time64 \ support_process_state \ support_ptrace \ + support-open-dev-null-range \ support_openpty \ support_paths \ support_quote_blob \ @@ -264,6 +265,7 @@ tests = \ tst-support_capture_subprocess \ tst-support_descriptors \ tst-support_format_dns_packet \ + tst-support-open-dev-null-range \ tst-support-process_state \ tst-support_quote_blob \ tst-support_quote_string \ diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c new file mode 100644 index 0000000000..fe82d3b9f2 --- /dev/null +++ b/support/support-open-dev-null-range.c @@ -0,0 +1,134 @@ +/* Return a range of open file descriptors. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +static void +increase_nofile (void) +{ + struct rlimit rl; + if (getrlimit (RLIMIT_NOFILE, &rl) == -1) + FAIL_EXIT1 ("getrlimit (RLIMIT_NOFILE): %m"); + + rl.rlim_cur += 128; + + if (setrlimit (RLIMIT_NOFILE, &rl) == 1) + FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m"); +} + +static int +open_dev_null (int flags, mode_t mode) +{ + int fd = open64 ("/dev/null", flags, mode); + if (fd > 0) + return fd; + + if (fd < 0 && errno != EMFILE) + FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode); + + increase_nofile (); + + return xopen ("/dev/null", flags, mode); +} + +struct range +{ + int lowfd; + size_t len; +}; + +struct range_list +{ + size_t total; + size_t used; + struct range *ranges; +}; + +static void +range_init (struct range_list *r) +{ + r->total = 8; + r->used = 0; + r->ranges = xmalloc (8 * sizeof (struct range)); +} + +static void +range_add (struct range_list *r, int lowfd, size_t len) +{ + if (r->used == r->total) + { + r->total *= 2; + r->ranges = xrealloc (r->ranges, r->total); + } + r->ranges[r->used].lowfd = lowfd; + r->ranges[r->used].len = len; + r->used++; +} + +static void +range_close (struct range_list *r) +{ + for (size_t i = 0; i < r->used; i++) + { + int minfd = r->ranges[i].lowfd; + int maxfd = r->ranges[i].lowfd + r->ranges[i].len; + for (int fd = minfd; fd < maxfd; fd++) + xclose (fd); + } + free (r->ranges); +} + +int +support_open_dev_null_range (int num, int flags, mode_t mode) +{ + /* We keep track of the ranges that hit an already opened descriptor, so + we close them after we get a working range. */ + struct range_list rl; + range_init (&rl); + + int lowfd = open_dev_null (flags, mode); + int prevfd = lowfd; + while (true) + { + int i = 1; + for (; i < num; i++) + { + int fd = open_dev_null (flags, mode); + if (fd != lowfd + i) + { + range_add (&rl, lowfd, prevfd - lowfd + 1); + + prevfd = lowfd = fd; + break; + } + prevfd = fd; + } + if (i == num) + break; + } + + range_close (&rl); + + return lowfd; +} diff --git a/support/support.h b/support/support.h index 834dba9097..bffbb10f0d 100644 --- a/support/support.h +++ b/support/support.h @@ -193,6 +193,14 @@ struct support_stack support_stack_alloc (size_t size); /* Deallocate the STACK. */ void support_stack_free (struct support_stack *stack); + +/* Create a range of NUM opened '/dev/null' file descriptors using FLAGS and + MODE. The function takes care of restarting the open range if a file + descriptor is found within the specified range and also increases + RLIMIT_NOFILE if required. + The returned value is the lowest file descriptor number. */ +int support_open_dev_null_range (int num, int flags, mode_t mode); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/tst-support-open-dev-null-range.c b/support/tst-support-open-dev-null-range.c new file mode 100644 index 0000000000..8be430ea2a --- /dev/null +++ b/support/tst-support-open-dev-null-range.c @@ -0,0 +1,137 @@ +/* Tests for support_open_dev_null_range. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif + +#include + +static void +check_path (int fd) +{ + char *proc_fd_path = xasprintf ("/proc/self/fd/%d", fd); + char file_path[PATH_MAX]; + ssize_t file_path_length + = readlink (proc_fd_path, file_path, sizeof (file_path)); + if (file_path_length < 0) + FAIL_EXIT1 ("readlink (%s, %p, %zu)", proc_fd_path, file_path, + sizeof (file_path)); + file_path[file_path_length] = '\0'; + TEST_COMPARE_STRING (file_path, "/dev/null"); +} + +static int +number_of_opened_files (void) +{ + DIR *fds = opendir ("/proc/self/fd"); + if (fds == NULL) + FAIL_EXIT1 ("opendir (\"/proc/self/fd\"): %m"); + + int r = 0; + while (true) + { + errno = 0; + struct dirent64 *e = readdir64 (fds); + if (e == NULL) + { + if (errno != 0) + FAIL_EXIT1 ("readdir: %m"); + break; + } + + if (e->d_name[0] == '.') + continue; + + char *endptr; + long int fd = strtol (e->d_name, &endptr, 10); + if (*endptr != '\0' || fd < 0 || fd > INT_MAX) + FAIL_EXIT1 ("readdir: invalid file descriptor name: /proc/self/fd/%s", + e->d_name); + + /* Skip the descriptor which is used to enumerate the + descriptors. */ + if (fd == dirfd (fds)) + continue; + + r = r + 1; + } + + closedir (fds); + + return r; +} + +static int +do_test (void) +{ + const int nfds1 = 8; + int lowfd = support_open_dev_null_range (nfds1, O_RDONLY, 0600); + for (int i = 0; i < nfds1; i++) + { + TEST_VERIFY (fcntl (lowfd + i, F_GETFL) > -1); + check_path (lowfd + i); + } + + /* create some gaps. */ + xclose (lowfd + 1); + xclose (lowfd + 5); + xclose (lowfd + 6); + + const int nfds2 = 16; + int lowfd2 = support_open_dev_null_range (nfds2, O_RDONLY, 0600); + for (int i = 0; i < nfds2; i++) + { + TEST_VERIFY (fcntl (lowfd2 + i, F_GETFL) > -1); + check_path (lowfd2 + i); + } + + /* Decrease the maximum number of files. */ + { + struct rlimit rl; + if (getrlimit (RLIMIT_NOFILE, &rl) == -1) + FAIL_EXIT1 ("getrlimit (RLIMIT_NOFILE): %m"); + + rl.rlim_cur = number_of_opened_files (); + + if (setrlimit (RLIMIT_NOFILE, &rl) == 1) + FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m"); + } + + const int nfds3 = 16; + int lowfd3 = support_open_dev_null_range (nfds3, O_RDONLY, 0600); + for (int i = 0; i < nfds3; i++) + { + TEST_VERIFY (fcntl (lowfd3 + i, F_GETFL) > -1); + check_path (lowfd3 + i); + } + + return 0; +} + +#include From patchwork Tue Aug 24 19:28:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44782 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2B5B385843D for ; Tue, 24 Aug 2021 19:29:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2B5B385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629833373; bh=/s53TkXzT/OBDvrfn1huXt1Nx+BYOf2nYBRZVJpa/d8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UlcNimAXDqQ5iubo3HKKr7KWka3WfwpfZMAPYkf9phx5Q/TvJuLskXqmiq+CIIBBz 7BnokWB+7GYCl+iMsSOaTcTTW+wseIoDHr2W0gubn14LS6DwBS+gBs4HZ8s36wkJ5/ X+QwXORrtdhdxVfBRJMyz0pJKRtDt5z386EeqzLc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id 6F9CB3858409 for ; Tue, 24 Aug 2021 19:29:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F9CB3858409 Received: by mail-qt1-x82f.google.com with SMTP id g11so17793061qtk.5 for ; Tue, 24 Aug 2021 12:29:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/s53TkXzT/OBDvrfn1huXt1Nx+BYOf2nYBRZVJpa/d8=; b=U9Oom24nRnefrWPMBOCeFWWtUDff4uwNu6mO1z7tvqhAhPC8VdOQpAkqolFQWPPNuT XxWq/OZTmmaokcrukwS0HUM8tRTuHUZxEaDpX3ub0cPGWkAIXQlFu3Zc6AAQvkGfp4R+ NzWZpQw9vF3A7A/0QTy5nJn7zDFYVEGsui3NPo9mIkRmJ1HZjJ6GiVuTv92JU0J9ddT7 AKMa5stQcjcIK2ATsiECl9a/3L+J55Tbct/bWsrrLRg0D9kqR/WiyOBc2gAcWtJBRUfv sdA6FJyfpguCkftOBQgcNz0JrErXypykwn3mh+2QNUNqnxLFIJPLB23PEXRHCQEDKJPP b1ug== X-Gm-Message-State: AOAM530FRH9Uv+3xrJmQWgnEYCCO65ca/pueIKb53OvGvc9VQFozTzgs Svih9MBihEMO3bgS5df5c8xVRdIQ5twrHQ== X-Google-Smtp-Source: ABdhPJx7VFfSC9HfAUWjMeNY6IfeH7LYqI5uCQxpRcEKHWDptCN2NJp3Us+aHo6MR9nXJFD6ZaZlYQ== X-Received: by 2002:ac8:5acb:: with SMTP id d11mr35932952qtd.287.1629833343886; Tue, 24 Aug 2021 12:29:03 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:cd83:3337:ab4f:e3a1:7ba5]) by smtp.gmail.com with ESMTPSA id s20sm7482674qtw.14.2021.08.24.12.29.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 12:29:03 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/2] Use support_open_dev_null_range io/tst-closefrom, misc/tst-close_range, and posix/tst-spawn5 (BZ #28260) Date: Tue, 24 Aug 2021 16:28:58 -0300 Message-Id: <20210824192858.681680-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824192858.681680-1-adhemerval.zanella@linaro.org> References: <20210824192858.681680-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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; 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 @@ -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;