diff options
| author | Sergey Bugaev <bugaevc@gmail.com> | 2023-05-20 14:55:29 +0300 |
|---|---|---|
| committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-05-20 18:14:01 +0200 |
| commit | 9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf (patch) | |
| tree | 458e020a274453bacf526e444594138ca67c36ef | |
| parent | 36cc908ed549389713955093bbfeaa35fdaf3e2e (diff) | |
| download | glibc-9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf.tar.xz glibc-9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf.zip | |
hurd: Use __hurd_fail () instead of assigning errno
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 <bugaevc@gmail.com>
Message-Id: <20230520115531.3911877-1-bugaevc@gmail.com>
49 files changed, 109 insertions, 278 deletions
diff --git a/hurd/alloc-fd.c b/hurd/alloc-fd.c index 60c8b00897..4edc742122 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 be6aa30c7e..a1efc5424d 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 2bccc59789..27fc41f420 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 9630cae474..940276396c 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 58c27feb2b..1d04047a02 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 12aaba5212..f1349495f5 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 3a16418f9f..46815f0548 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 87b6c06b67..4f5920bce2 100644 --- a/sysdeps/mach/hurd/cthreads.c +++ b/sysdeps/mach/hurd/cthreads.c @@ -17,6 +17,7 @@ #include <libc-lock.h> #include <errno.h> +#include <hurd.h> #include <stdlib.h> #include <pthreadP.h> @@ -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 9520f3ef89..2cf02c787a 100644 --- a/sysdeps/mach/hurd/dirfd.c +++ b/sysdeps/mach/hurd/dirfd.c @@ -18,6 +18,7 @@ #include <dirent.h> #include <dirstream.h> +#include <hurd.h> #include <hurd/fd.h> #include <errno.h> @@ -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 79ebb0ceb1..7c484d76eb 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 __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 __access (const char *file, int type) { - errno = ENOSYS; - return -1; + return __hurd_fail (ENOSYS); } check_no_hidden(__access_noerrno); int weak_function @@ -697,8 +692,7 @@ check_no_hidden(__getcwd); char *weak_function __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 0bcbbfd663..c5f64bcecb 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 5c60a6347c..9f1b0baa6c 100644 --- a/sysdeps/mach/hurd/f_setlk.c +++ b/sysdeps/mach/hurd/f_setlk.c @@ -19,6 +19,7 @@ #include <sys/types.h> #include <sys/file.h> #include <fcntl.h> +#include <hurd.h> #include <unistd.h> #include <errno.h> @@ -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 a89d6d39df..0b9a64bc57 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; |
