From patchwork Sat May 20 11:55:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 69719 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 E90BD3857715 for ; Sat, 20 May 2023 11:56:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E90BD3857715 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684583803; bh=PR+asB25pBK656HSV/szdQa3IVC1zdICNY60QUyMTOg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=G/N7mFiF4oaxLLHtFBavNhV1iAq2zE9FfTRq0HSw/SENjHlghj7QgIe+eqx8ZCiKF MZI3Owwyyu2aizyHTnyEPsFIgQgUtLrSgJaE3ZLNd4vf6de3wQM875fGpfvfVH03ou hpUraYKFvmEIhZT6jh+an4p+ZaZnCcx94e1c6rXo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 318943858C52 for ; Sat, 20 May 2023 11:55:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 318943858C52 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f3a611b3ddso2219330e87.0 for ; Sat, 20 May 2023 04:55:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684583734; x=1687175734; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PR+asB25pBK656HSV/szdQa3IVC1zdICNY60QUyMTOg=; b=VlZdcj4iIDW9U5y/Ps4J52o+Bh7N8+VPyetolI8ehMjxtQ9+sNk6vCa6wVX2/8vPnq b66VcqxIPaI9juCo1L28gJKkrlW1HtB+s1umWhkrM3cG9sPU7w7PGI1oZxRnIkarvAxg z+GgoQfSfs75RgnYKIWBkoI1NIDjsG3qzf0nU7nkmqqTxK5J2U0yASNzjCYPnKxD9GCa Q0zrfIzS9T4NQ3A9LgppVNEIfAnm2mZ0+X9ESGRfcL7sozhiPfDQUDUA5KEZRa4PP+HS DsEeDsEIxrFnmIsakBb96qbhXZIwkhAxWDU2YarFT4xemdQQkUgQnhqQE+WYfGc51JFc VxkQ== X-Gm-Message-State: AC+VfDxkOfcw0K6AHJW2aJ3BXmJb2rUy9NUlQ38x4tU39jZJB4nOScvU 8rzgh7iOMlYxXb296ClWWbGiSB368yg= X-Google-Smtp-Source: ACHHUZ4KujXaNYzyJcdX9D+UdXErmfQveiEcC1NJRymj6RbL2MnuQy7CJJhMf+DXE0om1/L2+kjjpg== X-Received: by 2002:a05:6512:3e27:b0:4f2:47ea:2f32 with SMTP id i39-20020a0565123e2700b004f247ea2f32mr2043594lfv.23.1684583733229; Sat, 20 May 2023 04:55:33 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:c81f:63f8:270e:be79]) by smtp.gmail.com with ESMTPSA id k7-20020ac24567000000b004efe9a169d2sm250767lfm.64.2023.05.20.04.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 May 2023 04:55:32 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH 1/3] hurd: Use __hurd_fail () instead of assigning errno Date: Sat, 20 May 2023 14:55:29 +0300 Message-Id: <20230520115531.3911877-1-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The __hurd_fail () inline function is the dedicated, idiomatic way of reporting errors in the Hurd part of glibc. Not only is it more concise than '{ errno = err; return -1; }', it is since commit 6639cc10029e24e06b34e169712b21c31b8cf213 "hurd: Mark error functions as __COLD" marked with the cold attribute, telling the compiler that this codepath is unlikely to be executed. In one case, use __hurd_dfail () over the plain __hurd_fail (). Signed-off-by: Sergey Bugaev --- hurd/alloc-fd.c | 13 +++++-------- hurd/fopenport.c | 5 +---- hurd/getdport.c | 12 +++--------- hurd/hurdselect.c | 13 +++---------- hurd/hurdsock.c | 7 ++----- sysdeps/mach/hurd/brk.c | 7 ++----- sysdeps/mach/hurd/closedir.c | 5 +---- sysdeps/mach/hurd/cthreads.c | 12 +++++------- sysdeps/mach/hurd/dirfd.c | 6 ++---- sysdeps/mach/hurd/dl-sysdep.c | 14 ++++---------- sysdeps/mach/hurd/dup3.c | 2 +- sysdeps/mach/hurd/f_setlk.c | 10 ++++------ sysdeps/mach/hurd/fcntl.c | 23 +++++++---------------- sysdeps/mach/hurd/fdopendir.c | 10 ++-------- sysdeps/mach/hurd/getcwd.c | 10 ++-------- sysdeps/mach/hurd/getegid.c | 12 +++--------- sysdeps/mach/hurd/getentropy.c | 15 +++++---------- sysdeps/mach/hurd/geteuid.c | 12 +++--------- sysdeps/mach/hurd/getgid.c | 12 +++--------- sysdeps/mach/hurd/getlogin.c | 5 +---- sysdeps/mach/hurd/getlogin_r.c | 7 ++----- sysdeps/mach/hurd/getrlimit.c | 5 +---- sysdeps/mach/hurd/getuid.c | 12 +++--------- sysdeps/mach/hurd/i386/sigreturn.c | 5 +---- sysdeps/mach/hurd/if_index.c | 11 ++++------- sysdeps/mach/hurd/ifreq.c | 2 +- sysdeps/mach/hurd/libc_sigaction.c | 5 +---- sysdeps/mach/hurd/lseek.c | 6 ++---- sysdeps/mach/hurd/mknodat.c | 5 +---- sysdeps/mach/hurd/mmap64.c | 8 +++----- sysdeps/mach/hurd/opendir.c | 23 +++++++---------------- sysdeps/mach/hurd/ptrace.c | 3 +-- sysdeps/mach/hurd/ptsname.c | 12 +++--------- sysdeps/mach/hurd/readdir.c | 6 ++---- sysdeps/mach/hurd/readdir64.c | 5 +---- sysdeps/mach/hurd/readdir64_r.c | 5 +---- sysdeps/mach/hurd/sendmsg.c | 5 +---- sysdeps/mach/hurd/setrlimit.c | 5 +---- sysdeps/mach/hurd/sigaltstack.c | 3 +-- sysdeps/mach/hurd/sigpending.c | 5 +---- sysdeps/mach/hurd/sigprocmask.c | 3 +-- sysdeps/mach/hurd/sigsuspend.c | 3 +-- sysdeps/mach/hurd/spawni.c | 3 +-- sysdeps/mach/hurd/statconv.c | 6 ++---- sysdeps/mach/hurd/statfsconv.c | 6 ++---- sysdeps/mach/hurd/ttyname_r.c | 5 +---- sysdeps/mach/hurd/unlinkat.c | 5 +---- sysdeps/mach/hurd/waitid.c | 8 ++------ sysdeps/mach/hurd/x86_64/sigreturn.c | 5 +---- 49 files changed, 109 insertions(+), 278 deletions(-) diff --git a/hurd/alloc-fd.c b/hurd/alloc-fd.c index 60c8b008..4edc7421 100644 --- a/hurd/alloc-fd.c +++ b/hurd/alloc-fd.c @@ -34,10 +34,7 @@ _hurd_alloc_fd (int *fd, int first_fd) long int rlimit; if (first_fd < 0) - { - errno = EINVAL; - return NULL; - } + return __hurd_fail (EINVAL), NULL; crit = _hurd_critical_section_lock (); @@ -99,7 +96,7 @@ _hurd_alloc_fd (int *fd, int first_fd) if (size * sizeof (*_hurd_dtable) < size) { /* Integer overflow! */ - errno = ENOMEM; + __hurd_fail (ENOMEM); goto out; } @@ -124,13 +121,13 @@ _hurd_alloc_fd (int *fd, int first_fd) goto search; } else - errno = ENOMEM; + __hurd_fail (ENOMEM); } else - errno = EMFILE; + __hurd_fail (EMFILE); } else - errno = EINVAL; /* Bogus FIRST_FD value. */ + __hurd_fail (EINVAL); /* Bogus FIRST_FD value. */ out: __mutex_unlock (&_hurd_dtable_lock); diff --git a/hurd/fopenport.c b/hurd/fopenport.c index be6aa30c..a1efc542 100644 --- a/hurd/fopenport.c +++ b/hurd/fopenport.c @@ -126,10 +126,7 @@ __fopenport (mach_port_t port, const char *mode) /* Check the access mode. */ if ((pflags & needflags) != needflags) - { - errno = EBADF; - return NULL; - } + return __hurd_fail (EBADF), NULL; return fopencookie ((void *) (uintptr_t) port, mode, funcsio); diff --git a/hurd/getdport.c b/hurd/getdport.c index 2bccc597..27fc41f4 100644 --- a/hurd/getdport.c +++ b/hurd/getdport.c @@ -35,18 +35,12 @@ __getdport (int fd) so we don't bother allocating a real table. */ if (_hurd_init_dtable == NULL) - { - /* Never had a descriptor table. */ - errno = EBADF; - return MACH_PORT_NULL; - } + /* Never had a descriptor table. */ + return __hurd_fail (EBADF), MACH_PORT_NULL; if (fd < 0 || (unsigned int) fd > _hurd_init_dtablesize || _hurd_init_dtable[fd] == MACH_PORT_NULL) - { - errno = EBADF; - return MACH_PORT_NULL; - } + return __hurd_fail (EBADF), MACH_PORT_NULL; else { __mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd], diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c index 9630cae4..94027639 100644 --- a/hurd/hurdselect.c +++ b/hurd/hurdselect.c @@ -71,10 +71,7 @@ _hurd_select (int nfds, struct hurd_sigstate *ss = NULL; if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE)) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); #define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */ #define IO_SELECT_TIMEOUT_REPLY_MSGID (21031 + 100) /* XXX */ @@ -86,10 +83,7 @@ _hurd_select (int nfds, struct timespec now; if (timeout->tv_sec < 0 || ! valid_nanoseconds (timeout->tv_nsec)) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); err = __clock_gettime (CLOCK_REALTIME, &now); if (err) @@ -281,8 +275,7 @@ _hurd_select (int nfds, { if (sigmask) __sigprocmask (SIG_SETMASK, &oset, NULL); - errno = EBADF; - return -1; + return __hurd_fail (EBADF); } if (nfds > _hurd_dtablesize) diff --git a/hurd/hurdsock.c b/hurd/hurdsock.c index 58c27feb..1d04047a 100644 --- a/hurd/hurdsock.c +++ b/hurd/hurdsock.c @@ -48,10 +48,7 @@ _hurd_socket_server (int domain, int dead) socket_t server; if (domain < 0) - { - errno = EAFNOSUPPORT; - return MACH_PORT_NULL; - } + return __hurd_fail (EAFNOSUPPORT), MACH_PORT_NULL; retry: HURD_CRITICAL_BEGIN; @@ -99,7 +96,7 @@ retry: if (server == MACH_PORT_NULL && errno == ENOENT) /* If the server node is absent, we don't support that protocol. */ - errno = EAFNOSUPPORT; + __hurd_fail (EAFNOSUPPORT); __mutex_unlock (&lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/brk.c b/sysdeps/mach/hurd/brk.c index 12aaba52..f1349495 100644 --- a/sysdeps/mach/hurd/brk.c +++ b/sysdeps/mach/hurd/brk.c @@ -93,11 +93,8 @@ _hurd_set_brk (vm_address_t addr) __mutex_unlock (&_hurd_rlimit_lock); if (addr - brk_start > rlimit) - { - /* Need to increase the resource limit. */ - errno = ENOMEM; - return -1; - } + /* Need to increase the resource limit. */ + return __hurd_fail (ENOMEM); if (pagend > _hurd_data_end) { diff --git a/sysdeps/mach/hurd/closedir.c b/sysdeps/mach/hurd/closedir.c index 3a16418f..46815f05 100644 --- a/sysdeps/mach/hurd/closedir.c +++ b/sysdeps/mach/hurd/closedir.c @@ -32,10 +32,7 @@ __closedir (DIR *dirp) error_t err; if (dirp == NULL) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); __libc_lock_lock (dirp->__lock); err = __vm_deallocate (__mach_task_self (), diff --git a/sysdeps/mach/hurd/cthreads.c b/sysdeps/mach/hurd/cthreads.c index 87b6c06b..4f5920bc 100644 --- a/sysdeps/mach/hurd/cthreads.c +++ b/sysdeps/mach/hurd/cthreads.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -25,9 +26,8 @@ int weak_function __cthread_keycreate (__cthread_key_t *key) { - __set_errno (ENOSYS); - *key = -1; - return -1; + *key = -1; + return __hurd_fail (ENOSYS); } /* Placeholder for key retrieval routine from Hurd cthreads library. */ @@ -36,8 +36,7 @@ weak_function __cthread_getspecific (__cthread_key_t key, void **pval) { *pval = NULL; - __set_errno (ENOSYS); - return -1; + return __hurd_fail (ENOSYS); } /* Placeholder for key setting routine from Hurd cthreads library. */ @@ -45,6 +44,5 @@ int weak_function __cthread_setspecific (__cthread_key_t key, void *val) { - __set_errno (ENOSYS); - return -1; + return __hurd_fail (ENOSYS); } diff --git a/sysdeps/mach/hurd/dirfd.c b/sysdeps/mach/hurd/dirfd.c index 9520f3ef..2cf02c78 100644 --- a/sysdeps/mach/hurd/dirfd.c +++ b/sysdeps/mach/hurd/dirfd.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -32,10 +33,7 @@ __dirfd (DIR *dirp) if (_hurd_dtable[fd] == dirp->__fd) break; if (fd == _hurd_dtablesize) - { - errno = EINVAL; - fd = -1; - } + fd = __hurd_fail (EINVAL); __mutex_unlock (&_hurd_dtable_lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index af1ae142..42add605 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -285,8 +285,7 @@ open_file (const char *file_name, int flags, MACH_PORT_RIGHT_SEND, +1); return _dl_hurd_data->dtable[fd]; } - errno = EBADF; - return MACH_PORT_NULL; + return __hurd_fail (EBADF), MACH_PORT_NULL; } assert (!(flags & ~(O_READ | O_EXEC | O_CLOEXEC | O_IGNORE_CTTY))); @@ -403,10 +402,7 @@ __ssize_t weak_function __TEXT_STARTUP __writev (int fd, const struct iovec *iov, int niov) { if (fd >= _hurd_init_dtablesize) - { - errno = EBADF; - return -1; - } + return __hurd_fail (EBADF); int i; size_t total = 0; @@ -554,8 +550,7 @@ check_no_hidden(__access); int weak_function __TEXT_STARTUP __access (const char *file, int type) { - errno = ENOSYS; - return -1; + return __hurd_fail (ENOSYS); } check_no_hidden(__access_noerrno); int weak_function __TEXT_STARTUP @@ -697,8 +692,7 @@ check_no_hidden(__getcwd); char *weak_function __TEXT_STARTUP __getcwd (char *buf, size_t size) { - errno = ENOSYS; - return NULL; + return __hurd_fail (ENOSYS), NULL; } /* This is used by dl-tunables.c to strdup strings. We can just make this a diff --git a/sysdeps/mach/hurd/dup3.c b/sysdeps/mach/hurd/dup3.c index 0bcbbfd6..c5f64bce 100644 --- a/sysdeps/mach/hurd/dup3.c +++ b/sysdeps/mach/hurd/dup3.c @@ -103,7 +103,7 @@ __dup3 (int fd, int fd2, int flags) { fd2 = -1; if (errno == EINVAL) - errno = EBADF; /* POSIX.1-1990 6.2.1.2 ll 54-55. */ + __hurd_fail (EBADF); /* POSIX.1-1990 6.2.1.2 ll 54-55. */ } else { diff --git a/sysdeps/mach/hurd/f_setlk.c b/sysdeps/mach/hurd/f_setlk.c index 5c60a634..9f1b0baa 100644 --- a/sysdeps/mach/hurd/f_setlk.c +++ b/sysdeps/mach/hurd/f_setlk.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -39,8 +40,7 @@ __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wai case F_WRLCK: cmd = LOCK_EX; break; case F_UNLCK: cmd = LOCK_UN; break; default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } if (cmd != LOCK_UN && wait == 0) @@ -71,11 +71,9 @@ __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wai /* FALLTHROUGH */ case SEEK_CUR: case SEEK_END: - errno = ENOTSUP; - return -1; + return __hurd_fail (ENOTSUP); default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } return __flock (fd, cmd); diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c index a89d6d39..0b9a64bc 100644 --- a/sysdeps/mach/hurd/fcntl.c +++ b/sysdeps/mach/hurd/fcntl.c @@ -48,8 +48,7 @@ __libc_fcntl (int fd, int cmd, ...) error_t err; default: /* Bad command. */ - errno = EINVAL; - result = -1; + result = __hurd_fail (EINVAL); break; /* First the descriptor-based commands, which do no RPCs. */ @@ -149,8 +148,7 @@ __libc_fcntl (int fd, int cmd, ...) cmd = F_SETLKW64; break; default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } struct flock64 fl64 = { @@ -183,8 +181,7 @@ __libc_fcntl (int fd, int cmd, ...) switch (cmd) { case F_GETLK64: - errno = ENOSYS; - return -1; + return __hurd_fail (ENOSYS); case F_SETLKW64: wait = 1; /* FALLTHROUGH */ @@ -192,8 +189,7 @@ __libc_fcntl (int fd, int cmd, ...) return __f_setlk (fd, fl->l_type, fl->l_whence, fl->l_start, fl->l_len, wait); default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } } else if (cmd == F_GETLK64) @@ -208,10 +204,7 @@ __libc_fcntl (int fd, int cmd, ...) && fl->l_start != fl64.l_start) || (sizeof fl->l_len != sizeof fl64.l_len && fl->l_len != fl64.l_len)) - { - errno = EOVERFLOW; - return -1; - } + return __hurd_fail (EOVERFLOW); } result = err ? __hurd_dfail (fd, err) : 0; @@ -246,8 +239,7 @@ __libc_fcntl (int fd, int cmd, ...) switch (cmd) { case F_GETLK64: - errno = ENOSYS; - return -1; + return __hurd_fail (ENOSYS); case F_SETLKW64: wait = 1; /* FALLTHROUGH */ @@ -255,8 +247,7 @@ __libc_fcntl (int fd, int cmd, ...) return __f_setlk (fd, fl->l_type, fl->l_whence, fl->l_start, fl->l_len, wait); default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } } diff --git a/sysdeps/mach/hurd/fdopendir.c b/sysdeps/mach/hurd/fdopendir.c index 2a152b07..33ea2f0c 100644 --- a/sysdeps/mach/hurd/fdopendir.c +++ b/sysdeps/mach/hurd/fdopendir.c @@ -31,10 +31,7 @@ __fdopendir (int fd) struct hurd_fd *d = _hurd_fd_get (fd); if (d == NULL) - { - errno = EBADF; - return NULL; - } + return __hurd_fail (EBADF), NULL; /* Ensure that it's a directory. */ error_t err = HURD_FD_PORT_USE @@ -47,10 +44,7 @@ __fdopendir (int fd) })); if (err) - { - errno = err; - return NULL; - } + return __hurd_dfail (fd, err), NULL; return _hurd_fd_opendir (d); } diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c index cd3aedd9..b9a6f855 100644 --- a/sysdeps/mach/hurd/getcwd.c +++ b/sysdeps/mach/hurd/getcwd.c @@ -69,10 +69,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir, if (size <= 0) { if (buf != NULL) - { - errno = EINVAL; - return NULL; - } + return __hurd_fail (EINVAL), NULL; size = FILENAME_MAX * 4 + 1; /* Good starting guess. */ } @@ -227,10 +224,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir, if (offset < d->d_namlen + 1) { if (orig_size > 0) - { - errno = ERANGE; - return NULL; - } + return __hurd_fail (ERANGE), NULL; else { size *= 2; diff --git a/sysdeps/mach/hurd/getegid.c b/sysdeps/mach/hurd/getegid.c index 7f07d13b..9ca56e57 100644 --- a/sysdeps/mach/hurd/getegid.c +++ b/sysdeps/mach/hurd/getegid.c @@ -32,21 +32,15 @@ retry: __mutex_lock (&_hurd_id.lock); if (err = _hurd_check_ids ()) - { - errno = err; - egid = -1; - } + egid = __hurd_fail (err); else if (_hurd_id.gen.ngids >= 1) egid = _hurd_id.gen.gids[0]; else if (_hurd_id.aux.ngids >= 1) /* We have no effective gids. Return the real gid. */ egid = _hurd_id.aux.gids[0]; else - { - /* We do not even have a real gid. */ - errno = EGRATUITOUS; - egid = -1; - } + /* We do not even have a real gid. */ + egid = __hurd_fail (EGRATUITOUS); __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/getentropy.c b/sysdeps/mach/hurd/getentropy.c index adbbb78c..118f8984 100644 --- a/sysdeps/mach/hurd/getentropy.c +++ b/sysdeps/mach/hurd/getentropy.c @@ -20,6 +20,7 @@ #include #include #include +#include /* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on success and -1 on failure. */ @@ -29,10 +30,7 @@ getentropy (void *buffer, size_t length) /* The interface is documented to return EIO for buffer lengths longer than 256 bytes. */ if (length > 256) - { - __set_errno (EIO); - return -1; - } + return __hurd_fail (EIO); /* Try to fill the buffer completely. Even with the 256 byte limit above, we might still receive an EINTR error (when blocking @@ -51,12 +49,9 @@ getentropy (void *buffer, size_t length) return -1; } if (bytes == 0) - { - /* No more bytes available. This should not happen under - normal circumstances. */ - __set_errno (EIO); - return -1; - } + /* No more bytes available. This should not happen under + normal circumstances. */ + return __hurd_fail (EIO); /* Try again in case of a short read. */ buffer += bytes; } diff --git a/sysdeps/mach/hurd/geteuid.c b/sysdeps/mach/hurd/geteuid.c index a50c514f..3548bdde 100644 --- a/sysdeps/mach/hurd/geteuid.c +++ b/sysdeps/mach/hurd/geteuid.c @@ -32,21 +32,15 @@ retry: __mutex_lock (&_hurd_id.lock); if (err = _hurd_check_ids ()) - { - errno = err; - euid = -1; - } + euid = __hurd_fail (err); else if (_hurd_id.gen.nuids >= 1) euid = _hurd_id.gen.uids[0]; else if (_hurd_id.aux.nuids >= 1) /* We have no effective uids. Return the real uid. */ euid = _hurd_id.aux.uids[0]; else - { - /* We do not even have a real uid. */ - errno = EGRATUITOUS; - euid = -1; - } + /* We do not even have a real uid. */ + euid = __hurd_fail (EGRATUITOUS); __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/getgid.c b/sysdeps/mach/hurd/getgid.c index f49e592f..62183074 100644 --- a/sysdeps/mach/hurd/getgid.c +++ b/sysdeps/mach/hurd/getgid.c @@ -32,18 +32,12 @@ retry: __mutex_lock (&_hurd_id.lock); if (err = _hurd_check_ids ()) - { - errno = err; - gid = -1; - } + gid = __hurd_fail (err); else if (_hurd_id.aux.ngids >= 1) gid = _hurd_id.aux.gids[0]; else - { - /* We do not even have a real gid. */ - errno = EGRATUITOUS; - gid = -1; - } + /* We do not even have a real gid. */ + gid = __hurd_fail (EGRATUITOUS); __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/getlogin.c b/sysdeps/mach/hurd/getlogin.c index 336afaea..3f1b9a6f 100644 --- a/sysdeps/mach/hurd/getlogin.c +++ b/sysdeps/mach/hurd/getlogin.c @@ -29,10 +29,7 @@ getlogin (void) error_t err; if (err = __USEPORT (PROC, __proc_getlogin (port, login))) - { - errno = err; - return NULL; - } + return __hurd_fail (err), NULL; return login; } diff --git a/sysdeps/mach/hurd/getlogin_r.c b/sysdeps/mach/hurd/getlogin_r.c index 2e432251..c1a2f14e 100644 --- a/sysdeps/mach/hurd/getlogin_r.c +++ b/sysdeps/mach/hurd/getlogin_r.c @@ -31,14 +31,11 @@ __getlogin_r (char *name, size_t name_len) error_t err; if (err = __USEPORT (PROC, __proc_getlogin (port, login))) - return errno = err; + return __hurd_fail (err), err; size_t len = __strnlen (login, sizeof login - 1) + 1; if (len > name_len) - { - errno = ERANGE; - return errno; - } + return __hurd_fail (ERANGE), ERANGE; memcpy (name, login, len); return 0; diff --git a/sysdeps/mach/hurd/getrlimit.c b/sysdeps/mach/hurd/getrlimit.c index 547d4e61..5744f67d 100644 --- a/sysdeps/mach/hurd/getrlimit.c +++ b/sysdeps/mach/hurd/getrlimit.c @@ -28,10 +28,7 @@ __getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits) struct rlimit lim; if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_rlimit_lock); diff --git a/sysdeps/mach/hurd/getuid.c b/sysdeps/mach/hurd/getuid.c index 267cbda9..fa778ebc 100644 --- a/sysdeps/mach/hurd/getuid.c +++ b/sysdeps/mach/hurd/getuid.c @@ -32,18 +32,12 @@ retry: __mutex_lock (&_hurd_id.lock); if (err = _hurd_check_ids ()) - { - errno = err; - uid = -1; - } + uid = __hurd_fail (err); else if (_hurd_id.aux.nuids >= 1) uid = _hurd_id.aux.uids[0]; else - { - /* We do not even have a real uid. */ - errno = EGRATUITOUS; - uid = -1; - } + /* We do not even have a real uid. */ + uid = __hurd_fail (EGRATUITOUS); __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c index 1686734d..64faa5d8 100644 --- a/sysdeps/mach/hurd/i386/sigreturn.c +++ b/sysdeps/mach/hurd/i386/sigreturn.c @@ -84,10 +84,7 @@ __sigreturn (struct sigcontext *scp) struct hurd_userlink *link = (void *) &scp[1]; if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); ss = _hurd_self_sigstate (); _hurd_sigstate_lock (ss); diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c index c8ad7e72..5c10da5d 100644 --- a/sysdeps/mach/hurd/if_index.c +++ b/sysdeps/mach/hurd/if_index.c @@ -38,10 +38,7 @@ __if_nametoindex (const char *ifname) return 0; if (strlen (ifname) >= IFNAMSIZ) - { - __set_errno (ENODEV); - return 0; - } + return __hurd_fail (ENODEV), 0; strncpy (ifr.ifr_name, ifname, IFNAMSIZ); if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0) @@ -49,7 +46,7 @@ __if_nametoindex (const char *ifname) int saved_errno = errno; __close (fd); if (saved_errno == EINVAL || saved_errno == ENOTTY) - __set_errno (ENOSYS); + __hurd_fail (ENOSYS); return 0; } __close (fd); @@ -180,9 +177,9 @@ __if_indextoname (unsigned int ifindex, char ifname[IF_NAMESIZE]) int saved_errno = errno; __close (fd); if (saved_errno == EINVAL || saved_errno == ENOTTY) - __set_errno (ENOSYS); + __hurd_fail (ENOSYS); else if (saved_errno == ENODEV) - __set_errno (ENXIO); + __hurd_fail (ENXIO); return NULL; } __close (fd); diff --git a/sysdeps/mach/hurd/ifreq.c b/sysdeps/mach/hurd/ifreq.c index 394d020c..eec7dd80 100644 --- a/sysdeps/mach/hurd/ifreq.c +++ b/sysdeps/mach/hurd/ifreq.c @@ -54,7 +54,7 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd) if (len % sizeof (struct ifreq) != 0) { __munmap (data, len); - errno = EGRATUITOUS; + __hurd_fail (EGRATUITOUS); goto out; } *num_ifs = len / sizeof (struct ifreq); diff --git a/sysdeps/mach/hurd/libc_sigaction.c b/sysdeps/mach/hurd/libc_sigaction.c index 3053c7e7..748647e9 100644 --- a/sysdeps/mach/hurd/libc_sigaction.c +++ b/sysdeps/mach/hurd/libc_sigaction.c @@ -33,10 +33,7 @@ __libc_sigaction (int sig, const struct sigaction *act, if (act != NULL && act->sa_handler != SIG_DFL && ((__sigmask (sig) & _SIG_CANT_MASK) || act->sa_handler == SIG_ERR)) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); /* Copy so we fault before taking locks. */ if (act != NULL) diff --git a/sysdeps/mach/hurd/lseek.c b/sysdeps/mach/hurd/lseek.c index 7b4e1289..0fe20e2a 100644 --- a/sysdeps/mach/hurd/lseek.c +++ b/sysdeps/mach/hurd/lseek.c @@ -18,6 +18,7 @@ #include #include #include +#include /* Seek to OFFSET on FD, starting from WHENCE. */ off_t @@ -27,10 +28,7 @@ __libc_lseek (int fd, off_t offset, int whence) off_t res = (off_t) res64; if (sizeof res != sizeof res64 && res != res64) - { - __set_errno (EOVERFLOW); - return (off_t) -1; - } + return (off_t) __hurd_fail (EOVERFLOW); return res; } diff --git a/sysdeps/mach/hurd/mknodat.c b/sysdeps/mach/hurd/mknodat.c index f3ccb869..67158e1b 100644 --- a/sysdeps/mach/hurd/mknodat.c +++ b/sysdeps/mach/hurd/mknodat.c @@ -63,10 +63,7 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev) len = 0; } else - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); if (translator != NULL && ! S_ISFIFO (mode)) { diff --git a/sysdeps/mach/hurd/mmap64.c b/sysdeps/mach/hurd/mmap64.c index a838afd4..cafd0347 100644 --- a/sysdeps/mach/hurd/mmap64.c +++ b/sysdeps/mach/hurd/mmap64.c @@ -19,6 +19,7 @@ #include #include #include +#include /* Map addresses starting near ADDR and extending for LEN bytes. From OFFSET into the file FD describes according to PROT and FLAGS. If ADDR @@ -36,11 +37,8 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, vm_offset_t small_offset = (vm_offset_t) offset; if (small_offset != offset) - { - /* We cannot do this since the offset is too large. */ - __set_errno (EOVERFLOW); - return MAP_FAILED; - } + /* We cannot do this since the offset is too large. */ + return __hurd_fail (EOVERFLOW), MAP_FAILED; return __mmap (addr, len, prot, flags, fd, small_offset); } diff --git a/sysdeps/mach/hurd/opendir.c b/sysdeps/mach/hurd/opendir.c index a9e8f94d..07260d22 100644 --- a/sysdeps/mach/hurd/opendir.c +++ b/sysdeps/mach/hurd/opendir.c @@ -40,10 +40,7 @@ _hurd_fd_opendir (struct hurd_fd *d) DIR *dirp; if (d == NULL) - { - errno = EBADF; - return NULL; - } + return __hurd_fail (EBADF), NULL; dirp = (DIR *) malloc (sizeof (DIR)); if (dirp == NULL) @@ -72,12 +69,9 @@ DIR * __opendirat (int dfd, const char *name) { if (name[0] == '\0') - { - /* POSIX.1-1990 says an empty name gets ENOENT; - but `open' might like it fine. */ - __set_errno (ENOENT); - return NULL; - } + /* POSIX.1-1990 says an empty name gets ENOENT; + but `open' might like it fine. */ + return __hurd_fail (ENOENT), NULL; int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_IGNORE_CTTY; int fd; @@ -107,12 +101,9 @@ __opendir (const char *name) return __opendirat (AT_FDCWD, name); #else if (name[0] == '\0') - { - /* POSIX.1-1990 says an empty name gets ENOENT; - but `open' might like it fine. */ - __set_errno (ENOENT); - return NULL; - } + /* POSIX.1-1990 says an empty name gets ENOENT; + but `open' might like it fine. */ + return __hurd_fail (ENOENT), NULL; int fd = __open (name, O_RDONLY | O_NONBLOCK | O_DIRECTORY); if (fd < 0) diff --git a/sysdeps/mach/hurd/ptrace.c b/sysdeps/mach/hurd/ptrace.c index b2efac07..97948d3f 100644 --- a/sysdeps/mach/hurd/ptrace.c +++ b/sysdeps/mach/hurd/ptrace.c @@ -380,8 +380,7 @@ ptrace (enum __ptrace_request request, ... ) } default: - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } return 0; diff --git a/sysdeps/mach/hurd/ptsname.c b/sysdeps/mach/hurd/ptsname.c index f6ad9939..06234f53 100644 --- a/sysdeps/mach/hurd/ptsname.c +++ b/sysdeps/mach/hurd/ptsname.c @@ -49,11 +49,8 @@ __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp) int ttype; if (HURD_DPORT_USE (fd, __term_get_bottom_type (port, &ttype)) == 0) - { - /* get_bottom_type suceeded, this is the slave side. */ - errno = ENOTTY; - return ENOTTY; - } + /* get_bottom_type suceeded, this is the slave side. */ + return __hurd_fail (ENOTTY), ENOTTY; if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername))) { @@ -64,10 +61,7 @@ __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp) len = __strnlen (peername, sizeof peername - 1) + 1; if (len > buflen) - { - errno = ERANGE; - return ERANGE; - } + return __hurd_fail (ERANGE), ERANGE; if (stp) { diff --git a/sysdeps/mach/hurd/readdir.c b/sysdeps/mach/hurd/readdir.c index d52cfe7d..bf67823e 100644 --- a/sysdeps/mach/hurd/readdir.c +++ b/sysdeps/mach/hurd/readdir.c @@ -21,6 +21,7 @@ #include #include #include +#include /* Read a directory entry from DIRP. */ struct dirent * @@ -52,10 +53,7 @@ __readdir (DIR *dirp) - sizeof entry->d_ino); const ino_t d_ino = entry64->d_ino; if (d_ino != entry64->d_ino) - { - __set_errno (EOVERFLOW); - return NULL; - } + return __hurd_fail (EOVERFLOW), NULL; # if BYTE_ORDER != BIG_ENDIAN /* We just skipped over the zero high word. */ entry->d_ino = d_ino; /* ... or the nonzero low word, swap it. */ # endif diff --git a/sysdeps/mach/hurd/readdir64.c b/sysdeps/mach/hurd/readdir64.c index ceb7083e..2c01ca22 100644 --- a/sysdeps/mach/hurd/readdir64.c +++ b/sysdeps/mach/hurd/readdir64.c @@ -29,10 +29,7 @@ __readdir64 (DIR *dirp) struct dirent64 *dp; if (dirp == NULL) - { - errno = EINVAL; - return NULL; - } + return __hurd_fail (EINVAL), NULL; __libc_lock_lock (dirp->__lock); diff --git a/sysdeps/mach/hurd/readdir64_r.c b/sysdeps/mach/hurd/readdir64_r.c index 4f4252c2..fdfe498d 100644 --- a/sysdeps/mach/hurd/readdir64_r.c +++ b/sysdeps/mach/hurd/readdir64_r.c @@ -31,10 +31,7 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result) error_t err = 0; if (dirp == NULL) - { - errno = EINVAL; - return errno; - } + return __hurd_fail (EINVAL), EINVAL; __libc_lock_lock (dirp->__lock); diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c index 3c9cdc4e..7f86f60b 100644 --- a/sysdeps/mach/hurd/sendmsg.c +++ b/sysdeps/mach/hurd/sendmsg.c @@ -82,10 +82,7 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags) { err = __vm_allocate (__mach_task_self (), &data.addr, len, 1); if (err) - { - __set_errno (err); - return -1; - } + return __hurd_fail (err); dealloc = 1; } else diff --git a/sysdeps/mach/hurd/setrlimit.c b/sysdeps/mach/hurd/setrlimit.c index 7dc62e1e..f57439f3 100644 --- a/sysdeps/mach/hurd/setrlimit.c +++ b/sysdeps/mach/hurd/setrlimit.c @@ -30,10 +30,7 @@ __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlimits) struct rlimit lim; if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); lim = *rlimits; diff --git a/sysdeps/mach/hurd/sigaltstack.c b/sysdeps/mach/hurd/sigaltstack.c index 8d5a2a8e..7431a11c 100644 --- a/sysdeps/mach/hurd/sigaltstack.c +++ b/sysdeps/mach/hurd/sigaltstack.c @@ -42,8 +42,7 @@ __sigaltstack (const stack_t *argss, stack_t *oss) { /* Can't disable a stack that is in use. */ __spin_unlock (&s->lock); - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } old = s->sigaltstack; diff --git a/sysdeps/mach/hurd/sigpending.c b/sysdeps/mach/hurd/sigpending.c index 59078a3f..6a8d3b8b 100644 --- a/sysdeps/mach/hurd/sigpending.c +++ b/sysdeps/mach/hurd/sigpending.c @@ -30,10 +30,7 @@ sigpending (sigset_t *set) sigset_t pending; if (set == NULL) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); ss = _hurd_self_sigstate (); _hurd_sigstate_lock (ss); diff --git a/sysdeps/mach/hurd/sigprocmask.c b/sysdeps/mach/hurd/sigprocmask.c index c7c5dfc3..d5309511 100644 --- a/sysdeps/mach/hurd/sigprocmask.c +++ b/sysdeps/mach/hurd/sigprocmask.c @@ -58,8 +58,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset) default: _hurd_sigstate_unlock (ss); - errno = EINVAL; - return -1; + return __hurd_fail (EINVAL); } ss->blocked &= ~_SIG_CANT_MASK; diff --git a/sysdeps/mach/hurd/sigsuspend.c b/sysdeps/mach/hurd/sigsuspend.c index 85f3e78f..2dec3f91 100644 --- a/sysdeps/mach/hurd/sigsuspend.c +++ b/sysdeps/mach/hurd/sigsuspend.c @@ -81,8 +81,7 @@ __sigsuspend (const sigset_t *set) /* We've been interrupted! And a good thing, too. Otherwise we'd never return. That's right; this function always returns an error. */ - errno = EINTR; - return -1; + return __hurd_fail (EINTR); } libc_hidden_def (__sigsuspend) weak_alias (__sigsuspend, sigsuspend) diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index f45311a0..5e053080 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -216,8 +216,7 @@ __spawni (pid_t *pid, const char *file, MACH_PORT_RIGHT_SEND, +1); return dtable[fd]; } - errno = EBADF; - return MACH_PORT_NULL; + return __hurd_fail (EBADF), MACH_PORT_NULL; } inline error_t child_lookup (const char *file, int oflag, mode_t mode, file_t *result) diff --git a/sysdeps/mach/hurd/statconv.c b/sysdeps/mach/hurd/statconv.c index 306dde38..ae3950f1 100644 --- a/sysdeps/mach/hurd/statconv.c +++ b/sysdeps/mach/hurd/statconv.c @@ -18,6 +18,7 @@ #include #include +#include static inline int stat64_conv (struct stat *buf, const struct stat64 *buf64) @@ -55,10 +56,7 @@ stat64_conv (struct stat *buf, const struct stat64 *buf64) && buf->st_size != buf64->st_size) || (sizeof buf->st_blocks != sizeof buf64->st_blocks && buf->st_blocks != buf64->st_blocks)) - { - __set_errno (EOVERFLOW); - return -1; - } + return __hurd_fail (EOVERFLOW); return 0; } diff --git a/sysdeps/mach/hurd/statfsconv.c b/sysdeps/mach/hurd/statfsconv.c index f67d6b98..8a2051c2 100644 --- a/sysdeps/mach/hurd/statfsconv.c +++ b/sysdeps/mach/hurd/statfsconv.c @@ -18,6 +18,7 @@ #include #include +#include static inline int statfs64_conv (struct statfs *buf, const struct statfs64 *buf64) @@ -25,10 +26,7 @@ statfs64_conv (struct statfs *buf, const struct statfs64 *buf64) # define DO(memb) \ buf->memb = buf64->memb; \ if (sizeof buf->memb != sizeof buf64->memb && buf->memb != buf64->memb) \ - { \ - __set_errno (EOVERFLOW); \ - return -1; \ - } + return __hurd_fail (EOVERFLOW); DO (f_type); DO (f_bsize); diff --git a/sysdeps/mach/hurd/ttyname_r.c b/sysdeps/mach/hurd/ttyname_r.c index 35a657bf..8fd05a8d 100644 --- a/sysdeps/mach/hurd/ttyname_r.c +++ b/sysdeps/mach/hurd/ttyname_r.c @@ -41,10 +41,7 @@ __ttyname_r (int fd, char *buf, size_t buflen) len = strlen (nodename) + 1; if (len > buflen) - { - errno = ERANGE; - return errno; - } + return __hurd_fail (ERANGE), ERANGE; memcpy (buf, nodename, len); return 0; diff --git a/sysdeps/mach/hurd/unlinkat.c b/sysdeps/mach/hurd/unlinkat.c index 5197a30c..cdc27742 100644 --- a/sysdeps/mach/hurd/unlinkat.c +++ b/sysdeps/mach/hurd/unlinkat.c @@ -33,10 +33,7 @@ __unlinkat (int fd, const char *name, int flag) const char *file; if ((flag &~ AT_REMOVEDIR) != 0) - { - __set_errno (EINVAL); - return -1; - } + return __hurd_fail (EINVAL); dir = __directory_name_split_at (fd, name, (char **) &file); if (dir == MACH_PORT_NULL) diff --git a/sysdeps/mach/hurd/waitid.c b/sysdeps/mach/hurd/waitid.c index 7bbbbdbe..3a416971 100644 --- a/sysdeps/mach/hurd/waitid.c +++ b/sysdeps/mach/hurd/waitid.c @@ -52,8 +52,7 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) break; default: invalid: - __set_errno (EINVAL); - return -1; + return __hurd_fail (EINVAL); } /* Technically we're supposed to return EFAULT if infop is bogus, @@ -62,10 +61,7 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) We just check for a null pointer. */ if (infop == NULL) - { - __set_errno (EFAULT); - return -1; - } + return __hurd_fail (EFAULT); cancel_oldtype = LIBC_CANCEL_ASYNC(); #if HURD_INTERFACE_VERSION >= 20201227 diff --git a/sysdeps/mach/hurd/x86_64/sigreturn.c b/sysdeps/mach/hurd/x86_64/sigreturn.c index 5d3a4d31..f37ae119 100644 --- a/sysdeps/mach/hurd/x86_64/sigreturn.c +++ b/sysdeps/mach/hurd/x86_64/sigreturn.c @@ -79,10 +79,7 @@ __sigreturn (struct sigcontext *scp) struct hurd_userlink *link = (void *) &scp[1]; if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); ss = _hurd_self_sigstate (); _hurd_sigstate_lock (ss); From patchwork Sat May 20 11:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 69718 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 68B0C3857700 for ; Sat, 20 May 2023 11:56:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68B0C3857700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684583761; bh=wkdLbGg2Ogg5ZRQgtOFfnYbrAp4mNkYdTZcEDO9ofj8=; 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=DZVoU/t7RwxQrv7z0QwTm6xXB2hCNhpmwVrdQlMYPcQ1Q7L47RTU9kZOR5mEefXQa EnFCvNIOifPPK9htTn35kbKrxwZITK2RhesC6Z+r0LoD/STSAKF5aJQbuELljgDM4D GIJ2D7t7KAJp8abaNka81LQ+f90A+HVi/51Osi2g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 119C53858C5F for ; Sat, 20 May 2023 11:55:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 119C53858C5F Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2af177f12a5so32652961fa.2 for ; Sat, 20 May 2023 04:55:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684583735; x=1687175735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wkdLbGg2Ogg5ZRQgtOFfnYbrAp4mNkYdTZcEDO9ofj8=; b=ibx877FmM+i8ZKRiXsnkzbSQfknmaH2xh50+Ju5A8ljqSMiYsPYWE7uhy34zkOhy1u xww3rdahXOG/t2BsFq7RzvqtSefvLTM+HRhAWqGcBEEazOT/GzBo2iIfI4BR4WKRxFfK ouCtskORv7T385QsrNjxTCq3wgxpFzxKp9C/riz17SCTyZIBSex010VsUYCkNmrc0vQX MK9ToEIbnILFSUm9dXQxnXWKP/HYTzEg+/0KrqUZlCymbeKPQlzfOcfaZhWlRrgNM6Ty +XLBLbjnYnp3/2d4ht9q7UdveFTFll92/lTQUyDoU74IhcDz8A9AMMHhl1u+dQ0L/9jn tiAQ== X-Gm-Message-State: AC+VfDxkhArYPqqgW2HQ86UKBYUm9usmX4A9znvzPyI8q/eZGVFAJSL+ MqNVCq+gh3Z8yi32V6V61dmOwh20u4Y= X-Google-Smtp-Source: ACHHUZ7/LfvUmPxNJq0hNMJccB9rMWbTO167gjSzugEkZ5sWj+zCoWTE1oT60cdVomZKLHauapbFtA== X-Received: by 2002:a05:6512:25a:b0:4eb:c85:bdc2 with SMTP id b26-20020a056512025a00b004eb0c85bdc2mr1849597lfo.2.1684583734730; Sat, 20 May 2023 04:55:34 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:c81f:63f8:270e:be79]) by smtp.gmail.com with ESMTPSA id k7-20020ac24567000000b004efe9a169d2sm250767lfm.64.2023.05.20.04.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 May 2023 04:55:34 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH 2/3] htl: Use __hurd_fail () instead of assigning errno Date: Sat, 20 May 2023 14:55:30 +0300 Message-Id: <20230520115531.3911877-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230520115531.3911877-1-bugaevc@gmail.com> References: <20230520115531.3911877-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Sergey Bugaev --- *Technically*, sysdeps/htl/ is not Hurd-specific (unlike, say, sysdeps/hurd/htl), but I don't think this distinction is meaningful, and the H in HTL must stand for something. Still, this is in a separate patch so it can be (not) applied easily. sysdeps/htl/sem-destroy.c | 6 ++---- sysdeps/htl/sem-init.c | 6 ++---- sysdeps/htl/sem-post.c | 11 +++-------- sysdeps/htl/sem-trywait.c | 4 ++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/sysdeps/htl/sem-destroy.c b/sysdeps/htl/sem-destroy.c index 3e40151b..84a35ed5 100644 --- a/sysdeps/htl/sem-destroy.c +++ b/sysdeps/htl/sem-destroy.c @@ -19,6 +19,7 @@ #include #include +#include #include int @@ -34,10 +35,7 @@ __sem_destroy (sem_t *sem) #endif ) /* There are threads waiting on *SEM. */ - { - errno = EBUSY; - return -1; - } + return __hurd_fail (EBUSY); return 0; } diff --git a/sysdeps/htl/sem-init.c b/sysdeps/htl/sem-init.c index f04bbfdc..f2954acd 100644 --- a/sysdeps/htl/sem-init.c +++ b/sysdeps/htl/sem-init.c @@ -19,6 +19,7 @@ #include #include +#include #include int @@ -26,10 +27,7 @@ __sem_init (sem_t *sem, int pshared, unsigned value) { #ifdef SEM_VALUE_MAX if (value > SEM_VALUE_MAX) - { - errno = EINVAL; - return -1; - } + return __hurd_fail (EINVAL); #endif struct new_sem *isem = (struct new_sem *) sem; diff --git a/sysdeps/htl/sem-post.c b/sysdeps/htl/sem-post.c index e283161a..c57458c1 100644 --- a/sysdeps/htl/sem-post.c +++ b/sysdeps/htl/sem-post.c @@ -20,6 +20,7 @@ #include #include +#include #include @@ -35,10 +36,7 @@ __sem_post (sem_t *sem) do { if ((d & SEM_VALUE_MASK) == SEM_VALUE_MAX) - { - errno = EOVERFLOW; - return -1; - } + return __hurd_fail (EOVERFLOW); } while (!atomic_compare_exchange_weak_release (&isem->data, &d, d + 1)); @@ -51,10 +49,7 @@ __sem_post (sem_t *sem) do { if ((v >> SEM_VALUE_SHIFT) == SEM_VALUE_MAX) - { - errno = EOVERFLOW; - return -1; - } + return __hurd_fail (EOVERFLOW); } while (!atomic_compare_exchange_weak_release (&isem->value, &v, v + (1 << SEM_VALUE_SHIFT))); diff --git a/sysdeps/htl/sem-trywait.c b/sysdeps/htl/sem-trywait.c index 0959092e..43aa185c 100644 --- a/sysdeps/htl/sem-trywait.c +++ b/sysdeps/htl/sem-trywait.c @@ -19,6 +19,7 @@ #include #include +#include #include int @@ -29,8 +30,7 @@ __sem_trywait (sem_t *sem) if (__sem_waitfast (isem, 1) == 0) return 0; - errno = EAGAIN; - return -1; + return __hurd_fail (EAGAIN); } weak_alias (__sem_trywait, sem_trywait); From patchwork Sat May 20 11:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 69717 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 3CEC8385828D for ; Sat, 20 May 2023 11:56:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CEC8385828D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684583761; bh=irAmpMfBji1D6L+bXVJ+Gt6WzQDqI/BihSNqmCLTLFQ=; 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=HlgSzkXeHa40NADt1u5x0ZF6O7XnGRbIENkqrxae0lmnFnda1dvqyJ33pAr4VS//M gHGs4JeDOkbf6fdUcC39QVDALGCGPXP120hL3Y76IcHcHqRa5Km1w9DfuyW6fx/XWB Ck+8mU9RBXlyhviyKwMhSSc89dHR0egqHM6lb5ec= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 863413858C78 for ; Sat, 20 May 2023 11:55:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 863413858C78 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ab3e8f4efeso21689121fa.0 for ; Sat, 20 May 2023 04:55:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684583736; x=1687175736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=irAmpMfBji1D6L+bXVJ+Gt6WzQDqI/BihSNqmCLTLFQ=; b=NeGXsqVBv0kgYUR65ylclDnnGOmqHhowMLymyWyveAah6Nyi9GADY/+mDqxsyO5lqu S8cMR2E95xqDwmQvpPjNa4yCd/oayzxQS4Fhl+6kpiEfTJtSXQWZOE0JrHfQPZkD73/p /yyGt0byc+ke9NU6xP7enRC3rVeSt+MCv2nNDAx8EQnGO8AsKBdSf6YdDDHRui7gsOVD d7QudMaztt2gviVg7Wk6A0/gqp7ZHElmD5hMGy6U1CPGfi+TrSukDq2MnW+xMeu7Xre5 aQGmflpOoNgSwQFxnt3DgXjpPe4/ZMrTeFpgXNnG7+FbukQvf6UAiRpMtTcUH2RsfC9z 7caw== X-Gm-Message-State: AC+VfDwj7jrQVFXmVWM/4ZriKbf/033n2gRA3vFT2mUzMyFuoului3dB KuOnSIXTL3ciOZyWxzkIX94bptHGAQI= X-Google-Smtp-Source: ACHHUZ4BCprLoIxYDZO4Vq5Qq3Aq/c2QugvWfFqD4CXRzFweXnWjI2H2RiM/SDtnTLsor2EnCQc+DA== X-Received: by 2002:a05:6512:4c2:b0:4f0:27a:8318 with SMTP id w2-20020a05651204c200b004f0027a8318mr2254177lfq.26.1684583735800; Sat, 20 May 2023 04:55:35 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:c81f:63f8:270e:be79]) by smtp.gmail.com with ESMTPSA id k7-20020ac24567000000b004efe9a169d2sm250767lfm.64.2023.05.20.04.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 May 2023 04:55:35 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH 3/3] io: Fix a typo Date: Sat, 20 May 2023 14:55:31 +0300 Message-Id: <20230520115531.3911877-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230520115531.3911877-1-bugaevc@gmail.com> References: <20230520115531.3911877-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Fixes 85f7554cd97e7f03d8dc66278653045ef63a2221 "Add test case for O_TMPFILE handling in open, openat" Signed-off-by: Sergey Bugaev --- io/tst-open-tmpfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/tst-open-tmpfile.c b/io/tst-open-tmpfile.c index 666a3a30..9541a942 100644 --- a/io/tst-open-tmpfile.c +++ b/io/tst-open-tmpfile.c @@ -92,7 +92,7 @@ wrap_openat64 (const char *path, int flags, mode_t mode) /* Return true if FD is flagged as deleted in /proc/self/fd, false if not. */ static bool -is_file_deteted (int fd) +is_file_deleted (int fd) { char *proc_fd_path = xasprintf ("/proc/self/fd/%d", fd); char file_path[4096]; @@ -172,7 +172,7 @@ check_wrapper_flags_mode (const char *op, wrapper_func wrapper, } /* Check that the file is marked as deleted in /proc. */ - if (!is_file_deteted (fd)) + if (!is_file_deleted (fd)) { printf ("error: path in /proc is not marked as deleted\n"); exit (1);