From patchwork Tue Jul 4 19:53:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 107014 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1361287qge; Tue, 4 Jul 2017 12:54:55 -0700 (PDT) X-Received: by 10.84.232.205 with SMTP id x13mr18408980plm.245.1499198095662; Tue, 04 Jul 2017 12:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499198095; cv=none; d=google.com; s=arc-20160816; b=bEF23OlV6pXQt9HkHvgZkCoiPUXnN15w+B6KT/4LSERMFjHW40YInnXllr3KxIFJ7Q 4A+BRqgHn1S6ZjLG5StcQ9SVvWIFgFDpcEBtEz15Z3X0q1rLP6IgzpeUOsJySjyGhg+a 96WNDqQmEmXxfcchVn/b4S36hUb4741/R0mokkPhE6Jx/8LjRaCECyCb+AE7bKtj+CXE wc1DiVwio2qlXJOHxn3dyRugrXeE1VjNxXIObbNZW30h6StW7kmNhDouhKBPvsWZkkuF VjTryLbF+n6Yy1Wl0eraBZihJTdRKT5yNF3jYQ7tqfbb+fbDVSv2LqmPDJ+9MvuiVfiI YlPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to: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=lHUWfAfMmq2a0vVk0LdjMgD9flrrI7JAg2iLEeciFig=; b=JpYSs0oMyUPS+EMj/mDFE68tXFzh8UL0ULghNzbE4qoF4CtdZuww3kaDMBL5MMUmzF JH11Vib+54rKD8g3Rv7DNt7Vlv4MNDpqTVRuUzZU2u+fVEjI4ANCK6pr5laygBPkpCYn BbY7rAgu4rt43tG/uoDh58TUliMSGwK6LOOvTKrh6JfCraxSuZX7ZZ0XxopWPfXSp2RG SfCMj5/YxV2Xys5NdHs3z/KrDsabKBbgH76WaKmCscs8EVqQzV9ST1Mr54/TxbKEewu+ HZjDOlbEIJYCBI+UJPGjesARzzmO0TpYPvaOwL5a4aMHWJXKw0arlZWh2SDvZJoUKIb9 HpMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.b=sVRpFmMr; spf=pass (google.com: domain of libc-alpha-return-81665-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-81665-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 r9si15529761pgu.401.2017.07.04.12.54.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jul 2017 12:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-81665-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.b=sVRpFmMr; spf=pass (google.com: domain of libc-alpha-return-81665-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-81665-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:in-reply-to :references; q=dns; s=default; b=dbG2+LW12wrwafvJE683kU7EWirs2En haSIaLgGonrE+MnWw3tlqsnHpe+I2dW+nIHYAM2iHE1+XGH1jQT4rrkHwbyAmAa1 IM9qqiAGUdtTBFNsdWEdvbBEDiQ0ul6Yek0GlsN3fAs6+2LI6Z9NXUZv3MIgmEB3 WOvF1j1td7Gs= 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:in-reply-to :references; s=default; bh=qiOI135cUFJGyrQzx0NUekN7RNQ=; b=sVRpF mMr9Bz3l+pcJnIdTPq1RKPi7YSRGjMej+mHR3x82CyNNtMo25YvLdcDELrvVU0Mk 0r4b2FyHyh09eqHmUhMyY/lm2u3fgDWDLxqfsklJXkaWs3QHEPIMW6Eqf2nPPVDJ M7+qD3V+2bJWlNnRZvVfw+xaRPf0t4dK7oXd9k= Received: (qmail 74396 invoked by alias); 4 Jul 2017 19:54:22 -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 73563 invoked by uid 89); 4 Jul 2017 19:54:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Non X-HELO: mail-qk0-f169.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:in-reply-to :references; bh=lHUWfAfMmq2a0vVk0LdjMgD9flrrI7JAg2iLEeciFig=; b=fjOqnzCyUF+C2BLXdAVGt2Ssv+/s3NLfsrQXjPWmVx6wvZjO+CH8ex60eCd+XpuPZW 8nFlIhOtD14Af1QIxjEvjJgJuysJWakLJkJVKykNbAyPtjcIgsUo0mqPTPwG3QDgSFmG /eaX3FLsoihBS8Tkvi0QMXj4U20PVhsVfRGf2GUb2NJtF2FkGUNaRwpd61VK+uWiAyAC o6SOVoQ4D3EI46dtOGyKFgSkLh1VqVXL8GRZLvFPTqjvXjiK21QzvCwz/qPDc9tGkB4z mkm03yB/XZgXJGcP+zEHqcUfJaJz0ZoPuIuyi/QJSSMqRcWl1A2Yvml63oiaT7twsshw YL1w== X-Gm-Message-State: AKS2vOyWxpCgRO8TxyKOjZx/raTYPrxSjwfIO3hBI/LUv8omjLtNDRfh F0XO6W8gkGSnmAbiFBvQxg== X-Received: by 10.55.160.196 with SMTP id j187mr46776979qke.145.1499198043625; Tue, 04 Jul 2017 12:54:03 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 01/14] Consolidate non cancellable open call Date: Tue, 4 Jul 2017 16:53:41 -0300 Message-Id: <1499198034-5837-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1499198034-5837-1-git-send-email-adhemerval.zanella@linaro.org> References: <1499198034-5837-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates all the non cancellable open calls to use the __open_nocancel identifier. For non cancellable targets it will be just a macro to call the default respective symbol while on Linux will be a internal one. To be consistent with the following non cancellable openat call, a new __open64_nocancel is also added (although not currently used). Checked on x86_64-linux-gnu, x86_64-linux-gnu-x32, and i686-linux-gnu. * sysdeps/generic/not-cancel.h (open_not_cancel): Remove macro. (open_not_cancel_2): Likewise. (open_nocancel): New macro. (open64_nocancel): Likewise. * sysdeps/unix/sysv/linux/not-cancel.h (open_not_cancel): Remove macro. (open_not_cancel_2): Likewise. (__open_nocancel): New prototype. (__open64_nocancel): Likewise. * sysdeps/unix/sysv/linux/Versions (libc) [GLIBC_PRIVATE]: Add __open_nocancel. * sysdeps/unix/sysv/linux/open.c (__open_nocancel): New function. * sysdeps/unix/sysv/linux/open64.c (__open64_nocancel): Likewise. * catgets/open_catalog.c (__open_catalog): Replace open_not_cancel{_2} with __open_nocancel. * csu/check_fds.c (check_one_fd): Likewise. * gmon/gmon.c (write_gmon): Likewise. * iconv/gconv_cache.c (__gconv_load_cached): Likewise. * intl/loadmsgcat.c (open): Likewise. * libio/fileops.c (_IO_file_open): Likewise. * locale/loadarchive.c (_nl_load_locale_from_archive): Likewise. * locale/loadlocale.c (_nl_load_locale): Likewise. * login/utmp_file.c (setutent_file): Likewise. * misc/daemon.c (daemon): Likewise. * nss/nss_db/db-open.c (internal_setent): Likewise. * sysdeps/mach/hurd/opendir.c (__opendirat): Likewise. * sysdeps/posix/libc_fatal.c (__libc_message): Likewise. * sysdeps/posix/opendir.c (tryopen_o_directory): Likewise. (__opendir): Likewise. * sysdeps/posix/spawni.c (__spawni_child): Likewise. * sysdeps/unix/sysv/linux/fips-private.h (fips_enable_p): Likewise. * sysdeps/unix/sysv/linux/gethostid.c (sethostid): Likewise. (gethostid): Likewise. * sysdeps/unix/sysv/linux/getloadavg.c (getloadavg): Likewise. * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Likewise. * sysdeps/unix/sysv/linux/getsysstats.c (__get_nprocs): Likewise. * sysdeps/unix/sysv/linux/grantpt.c (__close_all_fds): Likewise. * sysdeps/unix/sysv/linux/i386/smp.h (is_smp_system): Likewise. * sysdeps/unix/sysv/linux/ia64/has_cpuclock.c (has_cpuclock): Likewise. * sysdeps/unix/sysv/linux/libc_fatal.c (backtrace_and_maps): Likewise. * sysdeps/unix/sysv/linux/malloc-sysdep.h (check_may_shrink_heap): Likewise. * sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c (__get_clockfreq): Likewise. * sysdeps/unix/sysv/linux/pthread_getname.c (pthread_getname_np): Likewise. * sysdeps/unix/sysv/linux/pthread_setname.c (pthread_setname_np): Likewise. * sysdeps/unix/sysv/linux/spawni.c (__spawni_child): Likewise. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Likewise. --- ChangeLog | 55 +++++++++++++++++++++++++ catgets/open_catalog.c | 4 +- csu/check_fds.c | 2 +- gmon/gmon.c | 4 +- iconv/gconv_cache.c | 2 +- intl/loadmsgcat.c | 2 +- libio/fileops.c | 2 +- locale/loadarchive.c | 4 +- locale/loadlocale.c | 4 +- login/utmp_file.c | 6 +-- misc/daemon.c | 2 +- nss/nss_db/db-open.c | 2 +- sysdeps/generic/not-cancel.h | 8 ++-- sysdeps/mach/hurd/opendir.c | 2 +- sysdeps/posix/libc_fatal.c | 2 +- sysdeps/posix/opendir.c | 4 +- sysdeps/posix/spawni.c | 2 +- sysdeps/unix/sysv/linux/Versions | 1 + sysdeps/unix/sysv/linux/fips-private.h | 2 +- sysdeps/unix/sysv/linux/gethostid.c | 4 +- sysdeps/unix/sysv/linux/getloadavg.c | 2 +- sysdeps/unix/sysv/linux/getlogin_r.c | 2 +- sysdeps/unix/sysv/linux/getsysstats.c | 6 +-- sysdeps/unix/sysv/linux/grantpt.c | 4 +- sysdeps/unix/sysv/linux/i386/smp.h | 2 +- sysdeps/unix/sysv/linux/ia64/has_cpuclock.c | 2 +- sysdeps/unix/sysv/linux/libc_fatal.c | 2 +- sysdeps/unix/sysv/linux/malloc-sysdep.h | 4 +- sysdeps/unix/sysv/linux/not-cancel.h | 20 ++++----- sysdeps/unix/sysv/linux/open.c | 18 ++++++++ sysdeps/unix/sysv/linux/open64.c | 35 +++++++++++++--- sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c | 2 +- sysdeps/unix/sysv/linux/pthread_getname.c | 2 +- sysdeps/unix/sysv/linux/pthread_setname.c | 2 +- sysdeps/unix/sysv/linux/spawni.c | 2 +- sysdeps/unix/sysv/linux/sysconf.c | 2 +- 36 files changed, 157 insertions(+), 64 deletions(-) -- 2.7.4 diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index cbb305a..4621b26 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -50,7 +50,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, char *buf = NULL; if (strchr (cat_name, '/') != NULL || nlspath == NULL) - fd = open_not_cancel_2 (cat_name, O_RDONLY); + fd = __open_nocancel (cat_name, O_RDONLY); else { const char *run_nlspath = nlspath; @@ -178,7 +178,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, if (bufact != 0) { - fd = open_not_cancel_2 (buf, O_RDONLY); + fd = __open_nocancel (buf, O_RDONLY); if (fd >= 0) break; } diff --git a/csu/check_fds.c b/csu/check_fds.c index 062c879..5bd6392 100644 --- a/csu/check_fds.c +++ b/csu/check_fds.c @@ -61,7 +61,7 @@ check_one_fd (int fd, int mode) /* Something is wrong with this descriptor, it's probably not opened. Open /dev/null so that the SUID program we are about to start does not accidentally use this descriptor. */ - int nullfd = open_not_cancel (name, mode, 0); + int nullfd = __open_nocancel (name, mode, 0); /* We are very paranoid here. With all means we try to ensure that we are actually opening the /dev/null device and nothing diff --git a/gmon/gmon.c b/gmon/gmon.c index f394a78..87c3c4e 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -342,12 +342,12 @@ write_gmon (void) size_t len = strlen (env); char buf[len + 20]; __snprintf (buf, sizeof (buf), "%s.%u", env, __getpid ()); - fd = open_not_cancel (buf, O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666); + fd = __open_nocancel (buf, O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666); } if (fd == -1) { - fd = open_not_cancel ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, + fd = __open_nocancel ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666); if (fd < 0) { diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index 0cadea3..f1dce29 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -59,7 +59,7 @@ __gconv_load_cache (void) return -1; /* See whether the cache file exists. */ - fd = open_not_cancel (GCONV_MODULES_CACHE, O_RDONLY, 0); + fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY, 0); if (__builtin_expect (fd, 0) == -1) /* Not available. */ return -1; diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c index c2ff64e..adca419 100644 --- a/intl/loadmsgcat.c +++ b/intl/loadmsgcat.c @@ -445,7 +445,7 @@ /* Rename the non ISO C functions. This is required by the standard because some ISO C functions will require linking with this object file and the name space must not be polluted. */ -# define open(name, flags) open_not_cancel_2 (name, flags) +# define open(name, flags) __open_nocancel (name, flags) # define close(fd) close_not_cancel_no_status (fd) # define read(fd, buf, n) read_not_cancel (fd, buf, n) # define mmap(addr, len, prot, flags, fd, offset) \ diff --git a/libio/fileops.c b/libio/fileops.c index c55e196..67f3d72 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -223,7 +223,7 @@ _IO_file_open (_IO_FILE *fp, const char *filename, int posix_mode, int prot, int fdesc; #ifdef _LIBC if (__glibc_unlikely (fp->_flags2 & _IO_FLAGS2_NOTCANCEL)) - fdesc = open_not_cancel (filename, + fdesc = __open_nocancel (filename, posix_mode | (is32not64 ? 0 : O_LARGEFILE), prot); else fdesc = open (filename, posix_mode | (is32not64 ? 0 : O_LARGEFILE), prot); diff --git a/locale/loadarchive.c b/locale/loadarchive.c index e6e1a05..aebb590 100644 --- a/locale/loadarchive.c +++ b/locale/loadarchive.c @@ -203,7 +203,7 @@ _nl_load_locale_from_archive (int category, const char **namep) archmapped = &headmap; /* The archive has never been opened. */ - fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); + fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); if (fd < 0) /* Cannot open the archive, for whatever reason. */ return NULL; @@ -398,7 +398,7 @@ _nl_load_locale_from_archive (int category, const char **namep) if (fd == -1) { struct stat64 st; - fd = open_not_cancel_2 (archfname, + fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); if (fd == -1) /* Cannot open the archive, for whatever reason. */ diff --git a/locale/loadlocale.c b/locale/loadlocale.c index 9bca304..9c69ad4 100644 --- a/locale/loadlocale.c +++ b/locale/loadlocale.c @@ -173,7 +173,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) file->decided = 1; file->data = NULL; - fd = open_not_cancel_2 (file->filename, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (file->filename, O_RDONLY | O_CLOEXEC); if (__builtin_expect (fd, 0) < 0) /* Cannot open the file. */ return; @@ -201,7 +201,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) _nl_category_names.str + _nl_category_name_idxs[category], _nl_category_name_sizes[category] + 1); - fd = open_not_cancel_2 (newp, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (newp, O_RDONLY | O_CLOEXEC); if (__builtin_expect (fd, 0) < 0) return; diff --git a/login/utmp_file.c b/login/utmp_file.c index 240e0e3..1407116 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -143,7 +143,7 @@ setutent_file (void) file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); file_writable = false; - file_fd = open_not_cancel_2 + file_fd = __open_nocancel (file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC); if (file_fd == -1) return 0; @@ -374,7 +374,7 @@ pututline_file (const struct utmp *data) /* We must make the file descriptor writable before going on. */ const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); - int new_fd = open_not_cancel_2 + int new_fd = __open_nocancel (file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC); if (new_fd == -1) return NULL; @@ -484,7 +484,7 @@ updwtmp_file (const char *file, const struct utmp *utmp) int fd; /* Open WTMP file. */ - fd = open_not_cancel_2 (file, O_WRONLY | O_LARGEFILE); + fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE); if (fd < 0) return -1; diff --git a/misc/daemon.c b/misc/daemon.c index 9d186b2..dd38f2b 100644 --- a/misc/daemon.c +++ b/misc/daemon.c @@ -63,7 +63,7 @@ daemon (int nochdir, int noclose) if (!noclose) { struct stat64 st; - if ((fd = open_not_cancel(_PATH_DEVNULL, O_RDWR, 0)) != -1 + if ((fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0)) != -1 && (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0)) { if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0 diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c index 1c58bd1..40a2540 100644 --- a/nss/nss_db/db-open.c +++ b/nss/nss_db/db-open.c @@ -36,7 +36,7 @@ internal_setent (const char *file, struct nss_db_map *mapping) { enum nss_status status = NSS_STATUS_UNAVAIL; - int fd = open_not_cancel_2 (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC); + int fd = __open_nocancel (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC); if (fd != -1) { struct nss_db_header header; diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h index 5eabd2b..a4f7b7b 100644 --- a/sysdeps/generic/not-cancel.h +++ b/sysdeps/generic/not-cancel.h @@ -18,10 +18,10 @@ . */ /* By default we have none. Map the name to the normal functions. */ -#define open_not_cancel(name, flags, mode) \ - __libc_open (name, flags, mode) -#define open_not_cancel_2(name, flags) \ - __libc_open (name, flags) +#define __open_nocancel(...) \ + __open (__VA_ARGS__) +#define __open64_nocancel(...) \ + __open64 (__VA_ARGS__) #define openat_not_cancel(fd, name, flags, mode) \ __openat (fd, name, flags, mode) #define openat_not_cancel_3(fd, name, flags) \ diff --git a/sysdeps/mach/hurd/opendir.c b/sysdeps/mach/hurd/opendir.c index b3dab24..8db70b2 100644 --- a/sysdeps/mach/hurd/opendir.c +++ b/sysdeps/mach/hurd/opendir.c @@ -84,7 +84,7 @@ __opendirat (int dfd, const char *name) int fd; #if IS_IN (rtld) assert (dfd == AT_FDCWD); - fd = open_not_cancel_2 (name, flags); + fd = __open_nocancel (name, flags); #else fd = openat_not_cancel_3 (dfd, name, flags); #endif diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index b261963..37834c7 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -79,7 +79,7 @@ __libc_message (int do_abort, const char *fmt, ...) requests errors on standard error. */ const char *on_2 = __libc_secure_getenv ("LIBC_FATAL_STDERR_"); if (on_2 == NULL || *on_2 == '\0') - fd = open_not_cancel_2 (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY); + fd = __open_nocancel (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) fd = STDERR_FILENO; diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c index 909aa61..3ee27b2 100644 --- a/sysdeps/posix/opendir.c +++ b/sysdeps/posix/opendir.c @@ -61,7 +61,7 @@ static void tryopen_o_directory (void) { int serrno = errno; - int x = open_not_cancel_2 ("/dev/null", O_RDONLY|O_NDELAY|O_DIRECTORY); + int x = __open_nocancel ("/dev/null", O_RDONLY|O_NDELAY|O_DIRECTORY); if (x >= 0) { @@ -188,7 +188,7 @@ __opendir (const char *name) } } - return opendir_tail (open_not_cancel_2 (name, opendir_oflags)); + return opendir_tail (__open_nocancel (name, opendir_oflags)); } weak_alias (__opendir, opendir) diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c index 1979830..aaca6e2 100644 --- a/sysdeps/posix/spawni.c +++ b/sysdeps/posix/spawni.c @@ -185,7 +185,7 @@ __spawni_child (void *arguments) paths (like /dev/watchdog). */ close_not_cancel (action->action.open_action.fd); - int new_fd = open_not_cancel (action->action.open_action.path, + int new_fd = __open_nocancel (action->action.open_action.path, action->action.open_action.oflag | O_LARGEFILE, action->action.open_action.mode); diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 202ffcc..3c64077 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -169,6 +169,7 @@ libc { GLIBC_PRIVATE { # functions used in other libraries __syscall_rt_sigqueueinfo; + __open_nocancel; # functions used by nscd __netlink_assert_response; } diff --git a/sysdeps/unix/sysv/linux/fips-private.h b/sysdeps/unix/sysv/linux/fips-private.h index c9fe266..3a83a0f 100644 --- a/sysdeps/unix/sysv/linux/fips-private.h +++ b/sysdeps/unix/sysv/linux/fips-private.h @@ -42,7 +42,7 @@ fips_enabled_p (void) if (checked == FIPS_UNTESTED) { - int fd = open_not_cancel_2 ("/proc/sys/crypto/fips_enabled", O_RDONLY); + int fd = __open_nocancel ("/proc/sys/crypto/fips_enabled", O_RDONLY); if (fd != -1) { diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c index cc108aa..3ea8656 100644 --- a/sysdeps/unix/sysv/linux/gethostid.c +++ b/sysdeps/unix/sysv/linux/gethostid.c @@ -47,7 +47,7 @@ sethostid (long int id) } /* Open file for writing. Everybody is allowed to read this file. */ - fd = open_not_cancel (HOSTIDFILE, O_CREAT|O_WRONLY|O_TRUNC, 0644); + fd = __open_nocancel (HOSTIDFILE, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd < 0) return -1; @@ -77,7 +77,7 @@ gethostid (void) int fd; /* First try to get the ID from a former invocation of sethostid. */ - fd = open_not_cancel (HOSTIDFILE, O_RDONLY|O_LARGEFILE, 0); + fd = __open_nocancel (HOSTIDFILE, O_RDONLY|O_LARGEFILE, 0); if (fd >= 0) { ssize_t n = read_not_cancel (fd, &id, sizeof (id)); diff --git a/sysdeps/unix/sysv/linux/getloadavg.c b/sysdeps/unix/sysv/linux/getloadavg.c index 117f8c2..0bfe41d 100644 --- a/sysdeps/unix/sysv/linux/getloadavg.c +++ b/sysdeps/unix/sysv/linux/getloadavg.c @@ -33,7 +33,7 @@ getloadavg (double loadavg[], int nelem) { int fd; - fd = open_not_cancel_2 ("/proc/loadavg", O_RDONLY); + fd = __open_nocancel ("/proc/loadavg", O_RDONLY); if (fd < 0) return -1; else diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c index 05ac36b..2519792 100644 --- a/sysdeps/unix/sysv/linux/getlogin_r.c +++ b/sysdeps/unix/sysv/linux/getlogin_r.c @@ -34,7 +34,7 @@ int attribute_hidden __getlogin_r_loginuid (char *name, size_t namesize) { - int fd = open_not_cancel_2 ("/proc/self/loginuid", O_RDONLY); + int fd = __open_nocancel ("/proc/self/loginuid", O_RDONLY); if (fd == -1) return -1; diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index a0dd6eb..e21a34c 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -143,7 +143,7 @@ __get_nprocs (void) char *re = buffer_end; const int flags = O_RDONLY | O_CLOEXEC; - int fd = open_not_cancel_2 ("/sys/devices/system/cpu/online", flags); + int fd = __open_nocancel ("/sys/devices/system/cpu/online", flags); char *l; int result = 0; if (fd != -1) @@ -194,7 +194,7 @@ __get_nprocs (void) result = 2; /* The /proc/stat format is more uniform, use it by default. */ - fd = open_not_cancel_2 ("/proc/stat", flags); + fd = __open_nocancel ("/proc/stat", flags); if (fd != -1) { result = 0; @@ -211,7 +211,7 @@ __get_nprocs (void) } else { - fd = open_not_cancel_2 ("/proc/cpuinfo", flags); + fd = __open_nocancel ("/proc/cpuinfo", flags); if (fd != -1) { GET_NPROCS_PARSER (fd, buffer, cp, re, buffer_end, result); diff --git a/sysdeps/unix/sysv/linux/grantpt.c b/sysdeps/unix/sysv/linux/grantpt.c index 8cebde3..97c6ba7 100644 --- a/sysdeps/unix/sysv/linux/grantpt.c +++ b/sysdeps/unix/sysv/linux/grantpt.c @@ -31,9 +31,9 @@ close_all_fds (void) __closedir (dir); - int nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_RDONLY); + int nullfd = __open_nocancel (_PATH_DEVNULL, O_RDONLY); assert (nullfd == STDIN_FILENO); - nullfd = open_not_cancel_2 (_PATH_DEVNULL, O_WRONLY); + nullfd = __open_nocancel (_PATH_DEVNULL, O_WRONLY); assert (nullfd == STDOUT_FILENO); __dup2 (STDOUT_FILENO, STDERR_FILENO); } diff --git a/sysdeps/unix/sysv/linux/i386/smp.h b/sysdeps/unix/sysv/linux/i386/smp.h index 3109ea9..c24f2fd 100644 --- a/sysdeps/unix/sysv/linux/i386/smp.h +++ b/sysdeps/unix/sysv/linux/i386/smp.h @@ -41,7 +41,7 @@ is_smp_system (void) else { /* This was not successful. Now try reading the /proc filesystem. */ - int fd = open_not_cancel_2 ("/proc/sys/kernel/version", O_RDONLY); + int fd = __open_nocancel ("/proc/sys/kernel/version", O_RDONLY); if (__builtin_expect (fd, 0) == -1 || read_not_cancel (fd, u.buf, sizeof (u.buf)) <= 0) /* This also didn't work. We give up and say it's a UP machine. */ diff --git a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c index 2207c88..04e395b 100644 --- a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c +++ b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c @@ -30,7 +30,7 @@ has_cpuclock (void) if (__builtin_expect (itc_usable == 0, 0)) { int newval = 1; - int fd = open_not_cancel_2 ("/proc/sal/itc_drift", O_RDONLY); + int fd = __open_nocancel ("/proc/sal/itc_drift", O_RDONLY); if (__builtin_expect (fd != -1, 1)) { char buf[16]; diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c index d22bfdc..5b484cf 100644 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ b/sysdeps/unix/sysv/linux/libc_fatal.c @@ -53,7 +53,7 @@ backtrace_and_maps (int do_abort, bool written, int fd) __backtrace_symbols_fd (addrs + 1, n - 1, fd); writestr (strnsize ("======= Memory map: ========\n")); - int fd2 = open_not_cancel_2 ("/proc/self/maps", O_RDONLY); + int fd2 = __open_nocancel ("/proc/self/maps", O_RDONLY); char buf[1024]; ssize_t n2; while ((n2 = read_not_cancel (fd2, buf, sizeof (buf))) > 0) diff --git a/sysdeps/unix/sysv/linux/malloc-sysdep.h b/sysdeps/unix/sysv/linux/malloc-sysdep.h index 48cf7c1..cb87b58 100644 --- a/sysdeps/unix/sysv/linux/malloc-sysdep.h +++ b/sysdeps/unix/sysv/linux/malloc-sysdep.h @@ -42,8 +42,8 @@ check_may_shrink_heap (void) if (__builtin_expect (may_shrink_heap == 0, 1)) { - int fd = open_not_cancel_2 ("/proc/sys/vm/overcommit_memory", - O_RDONLY | O_CLOEXEC); + int fd = __open_nocancel ("/proc/sys/vm/overcommit_memory", + O_RDONLY | O_CLOEXEC); if (fd >= 0) { char val; diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index 43959ba..8d897f0 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -20,23 +20,19 @@ #ifndef NOT_CANCEL_H # define NOT_CANCEL_H +#include #include #include #include #include -/* Uncancelable open. */ -#ifdef __NR_open -# define open_not_cancel(name, flags, mode) \ - INLINE_SYSCALL (open, 3, name, flags, mode) -# define open_not_cancel_2(name, flags) \ - INLINE_SYSCALL (open, 2, name, flags) -#else -# define open_not_cancel(name, flags, mode) \ - INLINE_SYSCALL (openat, 4, AT_FDCWD, name, flags, mode) -# define open_not_cancel_2(name, flags) \ - INLINE_SYSCALL (openat, 3, AT_FDCWD, name, flags) -#endif +/* Non cancellable open syscall. */ +__typeof (open) __open_nocancel; +libc_hidden_proto (__open_nocancel) + +/* Non cancellable open syscall (LFS version). */ +__typeof (open64) __open64_nocancel; +libc_hidden_proto (__open64_nocancel) /* Uncancelable read. */ #define __read_nocancel(fd, buf, len) \ diff --git a/sysdeps/unix/sysv/linux/open.c b/sysdeps/unix/sysv/linux/open.c index b3912d5..5069333 100644 --- a/sysdeps/unix/sysv/linux/open.c +++ b/sysdeps/unix/sysv/linux/open.c @@ -22,6 +22,7 @@ #include #include +#include #ifndef __OFF_T_MATCHES_OFF64_T @@ -48,4 +49,21 @@ weak_alias (__libc_open, __open) libc_hidden_weak (__open) weak_alias (__libc_open, open) +int +__open_nocancel (const char *file, int oflag, ...) +{ + int mode = 0; + + if (__OPEN_NEEDS_MODE (oflag)) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, int); + va_end (arg); + } + + return INLINE_SYSCALL_CALL (openat, AT_FDCWD, file, oflag, mode); +} +libc_hidden_def (__open_nocancel) + #endif diff --git a/sysdeps/unix/sysv/linux/open64.c b/sysdeps/unix/sysv/linux/open64.c index fcac984..d5839e3 100644 --- a/sysdeps/unix/sysv/linux/open64.c +++ b/sysdeps/unix/sysv/linux/open64.c @@ -21,6 +21,13 @@ #include #include +#include + +#ifdef __OFF_T_MATCHES_OFF64_T +# define EXTRA_OPEN_FLAGS 0 +#else +# define EXTRA_OPEN_FLAGS O_LARGEFILE +#endif /* Open FILE with access OFLAG. If O_CREAT or O_TMPFILE is in OFLAG, a third argument is the file protection. */ @@ -37,12 +44,6 @@ __libc_open64 (const char *file, int oflag, ...) va_end (arg); } -#ifdef __OFF_T_MATCHES_OFF64_T -# define EXTRA_OPEN_FLAGS 0 -#else -# define EXTRA_OPEN_FLAGS O_LARGEFILE -#endif - return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag | EXTRA_OPEN_FLAGS, mode); } @@ -51,9 +52,31 @@ strong_alias (__libc_open64, __open64) libc_hidden_weak (__open64) weak_alias (__libc_open64, open64) + +int +__open64_nocancel (const char *file, int oflag, ...) +{ + int mode = 0; + + if (__OPEN_NEEDS_MODE (oflag)) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, int); + va_end (arg); + } + + return INLINE_SYSCALL_CALL (openat, AT_FDCWD, file, oflag | EXTRA_OPEN_FLAGS, + mode); +} +libc_hidden_def (__open64_nocancel) + #ifdef __OFF_T_MATCHES_OFF64_T strong_alias (__libc_open64, __libc_open) strong_alias (__libc_open64, __open) libc_hidden_weak (__open) weak_alias (__libc_open64, open) + +strong_alias (__open64_nocancel, __open_nocancel) +libc_hidden_weak (__open_nocancel) #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c index b8d01d8..c99e7de 100644 --- a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c +++ b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c @@ -40,7 +40,7 @@ __get_clockfreq (void) contains at least one line like: timebase : 33333333 We search for this line and convert the number into an integer. */ - int fd = open_not_cancel_2 ("/proc/cpuinfo", O_RDONLY); + int fd = __open_nocancel ("/proc/cpuinfo", O_RDONLY); if (__glibc_likely (fd != -1)) return result; diff --git a/sysdeps/unix/sysv/linux/pthread_getname.c b/sysdeps/unix/sysv/linux/pthread_getname.c index 9a5343a..caab2cc 100644 --- a/sysdeps/unix/sysv/linux/pthread_getname.c +++ b/sysdeps/unix/sysv/linux/pthread_getname.c @@ -45,7 +45,7 @@ pthread_getname_np (pthread_t th, char *buf, size_t len) char fname[sizeof (FMT) + 8]; sprintf (fname, FMT, (unsigned int) pd->tid); - int fd = open_not_cancel_2 (fname, O_RDONLY); + int fd = __open_nocancel (fname, O_RDONLY); if (fd == -1) return errno; diff --git a/sysdeps/unix/sysv/linux/pthread_setname.c b/sysdeps/unix/sysv/linux/pthread_setname.c index 5769c5b..93f0e9d 100644 --- a/sysdeps/unix/sysv/linux/pthread_setname.c +++ b/sysdeps/unix/sysv/linux/pthread_setname.c @@ -46,7 +46,7 @@ pthread_setname_np (pthread_t th, const char *name) char fname[sizeof (FMT) + 8]; sprintf (fname, FMT, (unsigned int) pd->tid); - int fd = open_not_cancel_2 (fname, O_RDWR); + int fd = __open_nocancel (fname, O_RDWR); if (fd == -1) return errno; diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index c56f894..4994a07 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -230,7 +230,7 @@ __spawni_child (void *arguments) paths (like /dev/watchdog). */ close_not_cancel (action->action.open_action.fd); - int ret = open_not_cancel (action->action.open_action.path, + int ret = __open_nocancel (action->action.open_action.path, action->action. open_action.oflag | O_LARGEFILE, action->action.open_action.mode); diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c index db20977..ab068ab 100644 --- a/sysdeps/unix/sysv/linux/sysconf.c +++ b/sysdeps/unix/sysv/linux/sysconf.c @@ -115,7 +115,7 @@ __sysconf (int name) if (procfname != NULL) { - int fd = open_not_cancel_2 (procfname, O_RDONLY); + int fd = __open_nocancel (procfname, O_RDONLY); if (fd != -1) { /* This is more than enough, the file contains a single integer. */