From patchwork Fri Mar 2 18:59:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130571 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1600983lja; Fri, 2 Mar 2018 10:59:57 -0800 (PST) X-Google-Smtp-Source: AG47ELvEmoRwV0OUnnJKCFvAXvn9K9FUfQ01AHmP6rOGgfNnaol6Au9nLZvaG4LeqGneeq08CMFM X-Received: by 10.99.123.92 with SMTP id k28mr5319702pgn.167.1520017197549; Fri, 02 Mar 2018 10:59:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017197; cv=none; d=google.com; s=arc-20160816; b=DMmzVeIx7gsfLUnrK/cK2znmyQOynPJPRtnsHKyGgRe1FjfOFXy2VEB8jMma37QLxp VTJ5ZFA+lTdKe8xAN/+7yWEPaD+USVKqVQkC8kSQJKMsx4uIeKAygMBHGsR7Wj/KeKEB a3I1LstpTnFYmfsag+NKJR8K+pcDYWT/XEYMiVI9QkJcaMDLlh0wV4qcsBLRvfdPKXK1 uYmY0QvuBzOffC+EYQby1SjfroZUB7gLI9RD2oMcqFYZvEoQsJ70FkTNyAi14hpWYN9i j9HdLHniTxQG7aIYuvDVlQCbOy+OHt7a2U2ydL0h310peYmbufWl4KFldvksDTuGu7He jyPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=shGmVZV4do+XoPU67dunwiDQHK9G26/QITbRWBA0evE=; b=xpW03wo/h/3M1zZxn5hlyh80r4UQgRzBr6omzrMxvBIy+mVlM0ravAf27tPdGga3Tv 9nGBOTSnOjM+H3s8FX/84evIEFln/aLtjaM8bO0FwH0kQvj0o1aQtT7Ypt0v01s31LGW W3mlxvGDjgLTrGqVpTlo/VbeW4EX7/+JxZwD0hyn9Y5eiymyzjojYcCbvJ6iVNsKM/9F shvpHWwPR23QcDacWN30NyxZE/IRyiuprDn9cWZ+m96AADXpfS35IArofAjE47cyWEKw WNdWn/+98lGaskqcbnAlrBe0LZlR5GWjW4rAXjyiTnxg/0Tu2C8yJpL+lUhRy2j3K8Xx vxtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=egFoCh8x; spf=pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90737-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o4si4305818pgp.285.2018.03.02.10.59.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 10:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=egFoCh8x; spf=pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90737-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=fQPSon0cfs9kKxo/5S+R7MO7FBLbSzKqnIOP9rtCW/sgmJJv+3S3U B+oO8fsgXgVyo1HI8t7ARJ1hVijsQJCnQTgRJwlsWwq2dfsmT9K9ksCPw5mf3h3v lx4BqD9ssZA3jUFjse2yu78meIVtb9qreIbv3TfRX1729mxZbS/kJ4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=Rk1zuBucSKV2I1BXXP58uicESg4=; b=egFoCh8xPqfUo0JFueh+OkjBOyGf STZr8+9CW+sK7Ik4i+GjYVpWfGdy9ODiUaga+Yi2YC9CTrveq0XJUsBPDFAPjRm/ 5EGUGdvqITNa+cW+uyhOgIil5zPCESczvcsQvRNefzUuXFXKeAUv6Zmc08k1wiSm kr7L4+ErxWBert8= Received: (qmail 96959 invoked by alias); 2 Mar 2018 18:59:40 -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 96858 invoked by uid 89); 2 Mar 2018 18:59:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f196.google.com 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; bh=shGmVZV4do+XoPU67dunwiDQHK9G26/QITbRWBA0evE=; b=eJGJbAeohwK2J1WUyrluHZsZqnxX3NxGc3v4jH8WZQx3LJBr6MwELlX6ZvH3OmvwGW mx3MGsk0/8/fv6hWeNvprB8qZGMNFmQ/QrXxi8BV6JbcP/nT3EOdehHaZhZUgUa4w3aM q+8de36pwp8L8d0Z4CWNOurbOmNbQtDPOoYgvv0SOUz/pYXXkuf1Li4Mm76crqY+b+C6 O+zyZL2IlH8MH1E8RGfc4vkwBb5XZH9wru7B8DRCTYTfPmqdm9IXIb/UTYxMHl+XQSQf YQCClipld9FZCMVj4bAaSP+IsTp7mWRfxOtLSHNk8Dpk+klQFvxfKDBBTPnpn+O12vOm Aj+Q== X-Gm-Message-State: AElRT7Fqe+wEGyOeKKKNMWMMpEyWL9/qmF64jNBx9Pisk9vQrTWTn1nS 71WWv916yUCMAx2jHdofHIUuhpdOudI= X-Received: by 10.200.83.12 with SMTP id t12mr10444992qtn.333.1520017172079; Fri, 02 Mar 2018 10:59:32 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 1/7] Assume O_DIRECTORY for opendir Date: Fri, 2 Mar 2018 15:59:19 -0300 Message-Id: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch assumes O_DIRECTORY works as defined by POSIX on opendir implementation (aligning with other glibc code, for instance pwd). This allows remove both the fallback code to handle system with missing or broken O_DIRECTORY along with the Linux specific opendir.c which just advertise the working flag. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/posix/opendir.c (o_directory_works, tryopen_o_directory): Remove definitions. (opendir_oflags): Use O_DIRECTORY regardless. (__opendir, __opendirat): Remove need_isdir_precheck usage. * sysdeps/unix/sysv/linux/opendir.c: Remove file. --- ChangeLog | 8 +++ sysdeps/posix/opendir.c | 108 ++------------------------------------ sysdeps/unix/sysv/linux/opendir.c | 20 ------- 3 files changed, 13 insertions(+), 123 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/opendir.c -- 2.7.4 diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c index d925804..dea23b2 100644 --- a/sysdeps/posix/opendir.c +++ b/sysdeps/posix/opendir.c @@ -15,24 +15,13 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include - -#include +#include +#include /* For BUFSIZ. */ +#include /* For MIN and MAX. */ + #include -#include /* The st_blksize value of the directory is used as a hint for the size of the buffer which receives struct dirent values from the @@ -40,49 +29,8 @@ file system provides a bogus value. */ #define MAX_DIR_BUFFER_SIZE 1048576U -/* opendir() must not accidentally open something other than a directory. - Some OS's have kernel support for that, some don't. In the worst - case we have to stat() before the open() AND fstat() after. - - We have to test at runtime for kernel support since libc may have - been compiled with different headers to the kernel it's running on. - This test can't be done reliably in the general case. We'll use - /dev/null, which if it's not a device lots of stuff will break, as - a guinea pig. It may be missing in chroot environments, so we - make sure to fail safe. */ -#ifdef O_DIRECTORY -# ifdef O_DIRECTORY_WORKS -# define o_directory_works 1 -# define tryopen_o_directory() while (1) /* This must not be called. */ -# else -static int o_directory_works; - -static void -tryopen_o_directory (void) -{ - int serrno = errno; - int x = __open_nocancel ("/dev/null", O_RDONLY|O_NDELAY|O_DIRECTORY); - - if (x >= 0) - { - __close_nocancel_nostatus (x); - o_directory_works = -1; - } - else if (errno != ENOTDIR) - o_directory_works = -1; - else - o_directory_works = 1; - - __set_errno (serrno); -} -# endif -# define EXTRA_FLAGS O_DIRECTORY -#else -# define EXTRA_FLAGS 0 -#endif - enum { - opendir_oflags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE|O_CLOEXEC + opendir_oflags = O_RDONLY|O_NDELAY|O_DIRECTORY|O_LARGEFILE|O_CLOEXEC }; static bool @@ -98,21 +46,6 @@ invalid_name (const char *name) return false; } - -static bool -need_isdir_precheck (void) -{ -#ifdef O_DIRECTORY - /* Test whether O_DIRECTORY works. */ - if (o_directory_works == 0) - tryopen_o_directory (); - - /* We can skip the expensive `stat' call if O_DIRECTORY works. */ - return o_directory_works < 0; -#endif - return true; -} - static DIR * opendir_tail (int fd) { @@ -144,22 +77,6 @@ __opendirat (int dfd, const char *name) if (__glibc_unlikely (invalid_name (name))) return NULL; - if (need_isdir_precheck ()) - { - /* We first have to check whether the name is for a directory. We - cannot do this after the open() call since the open/close operation - performed on, say, a tape device might have undesirable effects. */ - struct stat64 statbuf; - if (__glibc_unlikely (__fxstatat64 (_STAT_VER, dfd, name, - &statbuf, 0) < 0)) - return NULL; - if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) - { - __set_errno (ENOTDIR); - return NULL; - } - } - return opendir_tail (__openat_nocancel (dfd, name, opendir_oflags)); } #endif @@ -172,21 +89,6 @@ __opendir (const char *name) if (__glibc_unlikely (invalid_name (name))) return NULL; - if (need_isdir_precheck ()) - { - /* We first have to check whether the name is for a directory. We - cannot do this after the open() call since the open/close operation - performed on, say, a tape device might have undesirable effects. */ - struct stat64 statbuf; - if (__glibc_unlikely (__xstat64 (_STAT_VER, name, &statbuf) < 0)) - return NULL; - if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) - { - __set_errno (ENOTDIR); - return NULL; - } - } - return opendir_tail (__open_nocancel (name, opendir_oflags)); } weak_alias (__opendir, opendir) diff --git a/sysdeps/unix/sysv/linux/opendir.c b/sysdeps/unix/sysv/linux/opendir.c deleted file mode 100644 index 2677253..0000000 --- a/sysdeps/unix/sysv/linux/opendir.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2000-2018 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 - . */ - -#define O_DIRECTORY_WORKS 1 - -#include