]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use new RET_NERRNO() helper at various places
authorLennart Poettering <lennart@poettering.net>
Sun, 14 Nov 2021 21:40:49 +0000 (22:40 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Nov 2021 07:04:09 +0000 (08:04 +0100)
51 files changed:
src/basic/cgroup-util.c
src/basic/chattr-util.c
src/basic/env-util.c
src/basic/fd-util.c
src/basic/fs-util.c
src/basic/fs-util.h
src/basic/memfd-util.c
src/basic/mkdir.c
src/basic/namespace-util.c
src/basic/process-util.c
src/basic/rlimit-util.c
src/basic/signal-util.c
src/basic/socket-util.c
src/basic/sync-util.c
src/basic/terminal-util.c
src/basic/tmpfile-util.c
src/basic/user-util.c
src/basic/xattr-util.c
src/boot/bootctl.c
src/core/automount.c
src/core/execute.c
src/core/unit.c
src/home/homework-luks.c
src/import/import-tar.c
src/import/pull-tar.c
src/libsystemd/sd-event/sd-event.c
src/login/inhibit.c
src/login/logind-inhibit.c
src/login/logind-session-device.c
src/login/logind-session.c
src/machine/machine.c
src/nspawn/nspawn.c
src/shared/bootspec.c
src/shared/bpf-program.c
src/shared/btrfs-util.c
src/shared/clock-util.c
src/shared/copy.c
src/shared/data-fd-util.c
src/shared/ethtool-util.c
src/shared/label.c
src/shared/loop-util.c
src/shared/mount-setup.c
src/shared/mount-util.c
src/shared/selinux-util.c
src/shared/socket-label.c
src/shutdown/umount.c
src/sysusers/sysusers.c
src/tmpfiles/tmpfiles.c
src/udev/udev-node.c
src/userdb/userwork.c
src/vconsole/vconsole-setup.c

index 87f491808b7df478da9959bc7ff67e257ffd79d8..b8268bc65c1888a3bb13fc9cc06dea531475b995 100644 (file)
@@ -629,10 +629,7 @@ int cg_set_xattr(const char *controller, const char *path, const char *name, con
         if (r < 0)
                 return r;
 
-        if (setxattr(fs, name, value, size, flags) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setxattr(fs, name, value, size, flags));
 }
 
 int cg_get_xattr(const char *controller, const char *path, const char *name, void *value, size_t size) {
@@ -697,10 +694,7 @@ int cg_remove_xattr(const char *controller, const char *path, const char *name)
         if (r < 0)
                 return r;
 
-        if (removexattr(fs, name) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(removexattr(fs, name));
 }
 
 int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
index b5658754a561b6c0232baf343265a333b0272fb4..59707a79c07905062cf03ce196f474a667688985 100644 (file)
@@ -121,10 +121,7 @@ int read_attr_fd(int fd, unsigned *ret) {
         if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
                 return -ENOTTY;
 
-        if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, FS_IOC_GETFLAGS, ret));
 }
 
 int read_attr_path(const char *p, unsigned *ret) {
index 27bbba4e4bf184684875dc9274f4d838071b202a..885967e7f3f3fe66f99054e209da778546c86552 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "alloc-util.h"
 #include "env-util.h"
+#include "errno-util.h"
 #include "escape.h"
 #include "extract-word.h"
 #include "macro.h"
@@ -786,15 +787,12 @@ int getenv_bool_secure(const char *p) {
 }
 
 int set_unset_env(const char *name, const char *value, bool overwrite) {
-        int r;
+        assert(name);
 
         if (value)
-                r = setenv(name, value, overwrite);
-        else
-                r = unsetenv(name);
-        if (r < 0)
-                return -errno;
-        return 0;
+                return RET_NERRNO(setenv(name, value, overwrite));
+
+        return RET_NERRNO(unsetenv(name));
 }
 
 int putenv_dup(const char *assignment, bool override) {
@@ -807,9 +805,7 @@ int putenv_dup(const char *assignment, bool override) {
         n = strndupa_safe(assignment, e - assignment);
 
         /* This is like putenv(), but uses setenv() so that our memory doesn't become part of environ[]. */
-        if (setenv(n, e + 1, override) < 0)
-                return -errno;
-        return 0;
+        return RET_NERRNO(setenv(n, e + 1, override));
 }
 
 int setenv_systemd_exec_pid(bool update_only) {
index 63c37fec4d8257e8abb62ad4a10137edb0323145..2334a30e3ded2d194e282c03cf554c9c03071c1b 100644 (file)
@@ -152,10 +152,7 @@ int fd_nonblock(int fd, bool nonblock) {
         if (nflags == flags)
                 return 0;
 
-        if (fcntl(fd, F_SETFL, nflags) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fcntl(fd, F_SETFL, nflags));
 }
 
 int fd_cloexec(int fd, bool cloexec) {
@@ -171,10 +168,7 @@ int fd_cloexec(int fd, bool cloexec) {
         if (nflags == flags)
                 return 0;
 
-        if (fcntl(fd, F_SETFD, nflags) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fcntl(fd, F_SETFD, nflags));
 }
 
 _pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) {
@@ -802,8 +796,5 @@ int btrfs_defrag_fd(int fd) {
         if (r < 0)
                 return r;
 
-        if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL));
 }
index 65468b51b526305f9131efc750eb10813451bdb8..b9ea654e7aeb3cd02cf487258fa69b5cadc1ce0d 100644 (file)
 #include "strv.h"
 #include "time-util.h"
 #include "tmpfile-util.h"
+#include "umask-util.h"
 #include "user-util.h"
 #include "util.h"
 
 int unlink_noerrno(const char *path) {
         PROTECT_ERRNO;
-        int r;
-
-        r = unlink(path);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(unlink(path));
 }
 
 int rmdir_parents(const char *path, const char *stop) {
@@ -97,8 +92,8 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
          * want â€” though not atomic (i.e. for a short period both the new and the old filename will exist). */
         if (linkat(olddirfd, oldpath, newdirfd, newpath, 0) >= 0) {
 
-                if (unlinkat(olddirfd, oldpath, 0) < 0) {
-                        r = -errno; /* Backup errno before the following unlinkat() alters it */
+                r = RET_NERRNO(unlinkat(olddirfd, oldpath, 0));
+                if (r < 0) {
                         (void) unlinkat(newdirfd, newpath, 0);
                         return r;
                 }
@@ -117,10 +112,7 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
         if (errno != ENOENT)
                 return -errno;
 
-        if (renameat(olddirfd, oldpath, newdirfd, newpath) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(renameat(olddirfd, oldpath, newdirfd, newpath));
 }
 
 int readlinkat_malloc(int fd, const char *p, char **ret) {
@@ -286,14 +278,9 @@ int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t
 }
 
 int fchmod_umask(int fd, mode_t m) {
-        mode_t u;
-        int r;
-
-        u = umask(0777);
-        r = fchmod(fd, m & (~u)) < 0 ? -errno : 0;
-        umask(u);
+        _cleanup_umask_ mode_t u = umask(0777);
 
-        return r;
+        return RET_NERRNO(fchmod(fd, m & (~u)));
 }
 
 int fchmod_opath(int fd, mode_t m) {
@@ -822,7 +809,7 @@ int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
 
 int open_parent(const char *path, int flags, mode_t mode) {
         _cleanup_free_ char *parent = NULL;
-        int fd, r;
+        int r;
 
         r = path_extract_directory(path, &parent);
         if (r < 0)
@@ -836,11 +823,7 @@ int open_parent(const char *path, int flags, mode_t mode) {
         else if (!FLAGS_SET(flags, O_TMPFILE))
                 flags |= O_DIRECTORY|O_RDONLY;
 
-        fd = open(parent, flags, mode);
-        if (fd < 0)
-                return -errno;
-
-        return fd;
+        return RET_NERRNO(open(parent, flags, mode));
 }
 
 int conservative_renameat(
index 0d69fa6edb87dad62fa7887c12a552140ad86836..4cf4cabdd0965af80b3974c1a5c4c57e68bf6064 100644 (file)
@@ -47,7 +47,7 @@ int fd_warn_permissions(const char *path, int fd);
 int stat_warn_permissions(const char *path, const struct stat *st);
 
 #define laccess(path, mode)                                             \
-        (faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) < 0 ? -errno : 0)
+        RET_NERRNO(faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW))
 
 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
 int touch(const char *path);
index 0b8ecea1b1fd396d40759b39479abb71db31e164..f05fb1524e82d8f773229c861324952d8de725c2 100644 (file)
@@ -10,6 +10,7 @@
 #include <sys/prctl.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "macro.h"
 #include "memfd-util.h"
@@ -21,7 +22,6 @@
 
 int memfd_new(const char *name) {
         _cleanup_free_ char *g = NULL;
-        int fd;
 
         if (!name) {
                 char pr[17] = {};
@@ -49,11 +49,7 @@ int memfd_new(const char *name) {
                 }
         }
 
-        fd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
-        if (fd < 0)
-                return -errno;
-
-        return fd;
+        return RET_NERRNO(memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC));
 }
 
 int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
@@ -72,7 +68,6 @@ int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
                 q = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, offset);
         else
                 q = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
-
         if (q == MAP_FAILED)
                 return -errno;
 
@@ -81,15 +76,9 @@ int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
 }
 
 int memfd_set_sealed(int fd) {
-        int r;
-
         assert(fd >= 0);
 
-        r = fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL));
 }
 
 int memfd_get_sealed(int fd) {
@@ -106,13 +95,11 @@ int memfd_get_sealed(int fd) {
 
 int memfd_get_size(int fd, uint64_t *sz) {
         struct stat stat;
-        int r;
 
         assert(fd >= 0);
         assert(sz);
 
-        r = fstat(fd, &stat);
-        if (r < 0)
+        if (fstat(fd, &stat) < 0)
                 return -errno;
 
         *sz = stat.st_size;
@@ -120,15 +107,9 @@ int memfd_get_size(int fd, uint64_t *sz) {
 }
 
 int memfd_set_size(int fd, uint64_t sz) {
-        int r;
-
         assert(fd >= 0);
 
-        r = ftruncate(fd, sz);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ftruncate(fd, sz));
 }
 
 int memfd_new_and_map(const char *name, size_t sz, void **p) {
index bd9cb76ddf0d9f3c7cc6ebd618a515eda3ede316..41638f7a81caa8115c839b4553046c103887ac72 100644 (file)
@@ -80,15 +80,11 @@ int mkdir_safe_internal(
 }
 
 int mkdir_errno_wrapper(const char *pathname, mode_t mode) {
-        if (mkdir(pathname, mode) < 0)
-                return -errno;
-        return 0;
+        return RET_NERRNO(mkdir(pathname, mode));
 }
 
 int mkdirat_errno_wrapper(int dirfd, const char *pathname, mode_t mode) {
-        if (mkdirat(dirfd, pathname, mode) < 0)
-                return -errno;
-        return 0;
+        return RET_NERRNO(mkdirat(dirfd, pathname, mode));
 }
 
 int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) {
index 9d2e59e886305f95e6275b405fc435b1f339eb08..b9120a5ed0e688bd36802e8f5bb94e9f36a7236b 100644 (file)
@@ -4,6 +4,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 
+#include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "missing_fs.h"
@@ -177,10 +178,7 @@ int detach_mount_namespace(void) {
         if (unshare(CLONE_NEWNS) < 0)
                 return -errno;
 
-        if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL));
 }
 
 int userns_acquire(const char *uid_map, const char *gid_map) {
index fe732c0322c0afcc4bd92e4e45951da2a5545028..e5af3a1cc91f2e4ac0fe4e85dfa031e668d9980a 100644 (file)
@@ -813,7 +813,7 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
                 if (n >= until)
                         break;
 
-                r = sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)) < 0 ? -errno : 0;
+                r = RET_NERRNO(sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)));
                 /* Assuming we woke due to the child exiting. */
                 if (waitid(P_PID, pid, &status, WEXITED|WNOHANG) == 0) {
                         if (status.si_pid == pid) {
@@ -871,7 +871,7 @@ void sigterm_wait(pid_t pid) {
 int kill_and_sigcont(pid_t pid, int sig) {
         int r;
 
-        r = kill(pid, sig) < 0 ? -errno : 0;
+        r = RET_NERRNO(kill(pid, sig));
 
         /* If this worked, also send SIGCONT, unless we already just sent a SIGCONT, or SIGKILL was sent which isn't
          * affected by a process being suspended anyway. */
index 1ab41c69741552c57a0b0a59031929b516da28ac..33dfde9d6c1e7eea7bc9e1e641bce75389a33763 100644 (file)
@@ -3,6 +3,7 @@
 #include <errno.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "extract-word.h"
 #include "fd-util.h"
 #include "format-util.h"
@@ -45,10 +46,7 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) {
 
         log_debug("Failed at setting rlimit " RLIM_FMT " for resource RLIMIT_%s. Will attempt setting value " RLIM_FMT " instead.", rlim->rlim_max, rlimit_to_string(resource), fixed.rlim_max);
 
-        if (setrlimit(resource, &fixed) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setrlimit(resource, &fixed));
 }
 
 int setrlimit_closest_all(const struct rlimit *const *rlim, int *which_failed) {
index f945a96f0de0aeb63ca22166ab14a45a6a18465b..b61c18b2dec14970c78078cb98d90d401b515d41 100644 (file)
@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <stdarg.h>
 
+#include "errno-util.h"
 #include "macro.h"
 #include "parse-util.h"
 #include "signal-util.h"
@@ -39,10 +40,7 @@ int reset_signal_mask(void) {
         if (sigemptyset(&ss) < 0)
                 return -errno;
 
-        if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(sigprocmask(SIG_SETMASK, &ss, NULL));
 }
 
 int sigaction_many_internal(const struct sigaction *sa, ...) {
@@ -247,11 +245,7 @@ int signal_is_blocked(int sig) {
         if (r != 0)
                 return -r;
 
-        r = sigismember(&ss, sig);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(sigismember(&ss, sig));
 }
 
 int pop_pending_signal_internal(int sig, ...) {
index 94ae90929a18c684b314561755f13a6ed00a8ea1..ca6085ef64daedc236c6f79992e6ba18068b82de 100644 (file)
@@ -1226,10 +1226,7 @@ int socket_bind_to_ifname(int fd, const char *ifname) {
 
         /* Call with NULL to drop binding */
 
-        if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname)) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname)));
 }
 
 int socket_bind_to_ifindex(int fd, int ifindex) {
@@ -1238,13 +1235,9 @@ int socket_bind_to_ifindex(int fd, int ifindex) {
 
         assert(fd >= 0);
 
-        if (ifindex <= 0) {
+        if (ifindex <= 0)
                 /* Drop binding */
-                if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0) < 0)
-                        return -errno;
-
-                return 0;
-        }
+                return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0));
 
         r = setsockopt_int(fd, SOL_SOCKET, SO_BINDTOIFINDEX, ifindex);
         if (r != -ENOPROTOOPT)
@@ -1332,16 +1325,10 @@ int socket_set_unicast_if(int fd, int af, int ifi) {
         switch (af) {
 
         case AF_INET:
-                if (setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0)
-                        return -errno;
-
-                return 0;
+                return RET_NERRNO(setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)));
 
         case AF_INET6:
-                if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0)
-                        return -errno;
-
-                return 0;
+                return RET_NERRNO(setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)));
 
         default:
                 return -EAFNOSUPPORT;
index 479ff73c63f530c5429fd7e2ddda91c7ceeca731..e2d4a3d895f107af0fde76126b222ff7b9833815 100644 (file)
@@ -66,10 +66,7 @@ int fsync_directory_of_file(int fd) {
                         return dfd;
         }
 
-        if (fsync(dfd) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fsync(dfd));
 }
 
 int fsync_full(int fd) {
@@ -77,7 +74,7 @@ int fsync_full(int fd) {
 
         /* Sync both the file and the directory */
 
-        r = fsync(fd) < 0 ? -errno : 0;
+        r = RET_NERRNO(fsync(fd));
 
         q = fsync_directory_of_file(fd);
         if (r < 0) /* Return earlier error */
@@ -109,10 +106,7 @@ int fsync_path_at(int at_fd, const char *path) {
                 fd = opened_fd;
         }
 
-        if (fsync(fd) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fsync(fd));
 }
 
 int fsync_parent_at(int at_fd, const char *path) {
@@ -126,10 +120,7 @@ int fsync_parent_at(int at_fd, const char *path) {
                 if (opened_fd < 0)
                         return -errno;
 
-                if (fsync(opened_fd) < 0)
-                        return -errno;
-
-                return 0;
+                return RET_NERRNO(fsync(opened_fd));
         }
 
         opened_fd = openat(at_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
@@ -160,7 +151,7 @@ int syncfs_path(int at_fd, const char *path) {
 
         if (isempty(path)) {
                 if (at_fd != AT_FDCWD)
-                        return syncfs(at_fd) < 0 ? -errno : 0;
+                        return RET_NERRNO(syncfs(at_fd));
 
                 fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
         } else
@@ -168,8 +159,5 @@ int syncfs_path(int at_fd, const char *path) {
         if (fd < 0)
                 return -errno;
 
-        if (syncfs(fd) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(syncfs(fd));
 }
index 5b8db550527f29e51c3204d28a48b6fa50edc8c2..8ef354ee9aca565193f2799550fa5210291468d9 100644 (file)
@@ -74,10 +74,7 @@ int chvt(int vt) {
                 vt = tiocl[0] <= 0 ? 1 : tiocl[0];
         }
 
-        if (ioctl(fd, VT_ACTIVATE, vt) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, VT_ACTIVATE, vt));
 }
 
 int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
@@ -409,8 +406,7 @@ int acquire_terminal(
                 assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
 
                 /* First, try to get the tty */
-                r = ioctl(fd, TIOCSCTTY,
-                          (flags & ~ACQUIRE_TERMINAL_PERMISSIVE) == ACQUIRE_TERMINAL_FORCE) < 0 ? -errno : 0;
+                r = RET_NERRNO(ioctl(fd, TIOCSCTTY, (flags & ~ACQUIRE_TERMINAL_PERMISSIVE) == ACQUIRE_TERMINAL_FORCE));
 
                 /* Reset signal handler to old value */
                 assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
@@ -500,7 +496,7 @@ int release_terminal(void) {
          * by our own TIOCNOTTY */
         assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
 
-        r = ioctl(fd, TIOCNOTTY) < 0 ? -errno : 0;
+        r = RET_NERRNO(ioctl(fd, TIOCNOTTY));
 
         assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
 
@@ -509,11 +505,7 @@ int release_terminal(void) {
 
 int terminal_vhangup_fd(int fd) {
         assert(fd >= 0);
-
-        if (ioctl(fd, TIOCVHANGUP) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, TIOCVHANGUP));
 }
 
 int terminal_vhangup(const char *name) {
@@ -1361,10 +1353,7 @@ int vt_reset_keyboard(int fd) {
         /* If we can't read the default, then default to unicode. It's 2017 after all. */
         kb = vt_default_utf8() != 0 ? K_UNICODE : K_XLATE;
 
-        if (ioctl(fd, KDSKBMODE, kb) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, KDSKBMODE, kb));
 }
 
 int vt_restore(int fd) {
index 36930cb34b5ed0e2f7e7bf287f5a658ed8f92450..cf3bbad1c427d87d857a602c824c418b05c4fdb2 100644 (file)
@@ -65,16 +65,9 @@ int fopen_temporary(const char *path, FILE **ret_f, char **ret_temp_path) {
 
 /* This is much like mkostemp() but is subject to umask(). */
 int mkostemp_safe(char *pattern) {
-        int fd = -1;  /* avoid false maybe-uninitialized warning */
-
         assert(pattern);
-
-        RUN_WITH_UMASK(0077)
-                fd = mkostemp(pattern, O_CLOEXEC);
-        if (fd < 0)
-                return -errno;
-
-        return fd;
+        BLOCK_WITH_UMASK(0077);
+        return RET_NERRNO(mkostemp(pattern, O_CLOEXEC));
 }
 
 int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
@@ -283,8 +276,6 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
 }
 
 int link_tmpfile(int fd, const char *path, const char *target) {
-        int r;
-
         assert(fd >= 0);
         assert(target);
 
@@ -295,16 +286,10 @@ int link_tmpfile(int fd, const char *path, const char *target) {
          * Note that in both cases we will not replace existing files. This is because linkat() does not support this
          * operation currently (renameat2() does), and there is no nice way to emulate this. */
 
-        if (path) {
-                r = rename_noreplace(AT_FDCWD, path, AT_FDCWD, target);
-                if (r < 0)
-                        return r;
-        } else {
-                if (linkat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), AT_FDCWD, target, AT_SYMLINK_FOLLOW) < 0)
-                        return -errno;
-        }
+        if (path)
+                return rename_noreplace(AT_FDCWD, path, AT_FDCWD, target);
 
-        return 0;
+        return RET_NERRNO(linkat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), AT_FDCWD, target, AT_SYMLINK_FOLLOW));
 }
 
 int mkdtemp_malloc(const char *template, char **ret) {
index aee2d9dc595a24a7936b07db5cb5538a11cdf80b..63bef51b0b2dc4a2fa4671f13b8aa68f64a36ee5 100644 (file)
@@ -680,10 +680,7 @@ int reset_uid_gid(void) {
         if (setresgid(0, 0, 0) < 0)
                 return -errno;
 
-        if (setresuid(0, 0, 0) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setresuid(0, 0, 0));
 }
 
 int take_etc_passwd_lock(const char *root) {
@@ -943,10 +940,7 @@ int maybe_setgroups(size_t size, const gid_t *list) {
                 }
         }
 
-        if (setgroups(size, list) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setgroups(size, list));
 }
 
 bool synthesize_nobody(void) {
index 7bb5b3f6df7c61baa9a96afd119931c170be1560..ebd620604ed26819ff3910d7c75adeb95c162f00 100644 (file)
@@ -8,6 +8,7 @@
 #include <sys/xattr.h>
 
 #include "alloc-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "macro.h"
 #include "missing_syscall.h"
@@ -202,10 +203,7 @@ int fd_setcrtime(int fd, usec_t usec) {
                 usec = now(CLOCK_REALTIME);
 
         le = htole64((uint64_t) usec);
-        if (fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0));
 }
 
 int listxattr_at_malloc(
index 0dc19c4bb6e377c71b04bc43d9cda8115ec851be..c19a51de6268deaf202979507f7a76269cd56bd1 100644 (file)
@@ -335,10 +335,7 @@ static int boot_entry_file_check(const char *root, const char *p) {
         if (!path)
                 return log_oom();
 
-        if (access(path, F_OK) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(access(path, F_OK));
 }
 
 static void boot_entry_file_list(const char *field, const char *root, const char *p, int *ret_status) {
index 1fc3fc0f82736365c6d533bfcc647491d754adfb..550a350a455e431ec0fe481dbfdb9e87701942d4 100644 (file)
@@ -425,10 +425,7 @@ static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, usec_t usec) {
                 /* Convert to seconds, rounding up. */
                 param.timeout.timeout = DIV_ROUND_UP(usec, USEC_PER_SEC);
 
-        if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param));
 }
 
 static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, int status) {
@@ -446,10 +443,7 @@ static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, in
         } else
                 param.ready.token = token;
 
-        if (ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param));
 }
 
 static int automount_send_ready(Automount *a, Set *tokens, int status) {
index 4a57e4077927acaaabae63b789a756668bafec4f..6192a2d33ebdc75af5ad604ff6594fe4f4dfb144 100644 (file)
@@ -306,7 +306,7 @@ static int connect_journal_socket(
                 }
         }
 
-        r = connect(fd, &sa.sa, sa_len) < 0 ? -errno : 0;
+        r = RET_NERRNO(connect(fd, &sa.sa, sa_len));
 
         /* If we fail to restore the uid or gid, things will likely
            fail later on. This should only happen if an LSM interferes. */
@@ -519,13 +519,13 @@ static int setup_input(
         case EXEC_INPUT_SOCKET:
                 assert(socket_fd >= 0);
 
-                return dup2(socket_fd, STDIN_FILENO) < 0 ? -errno : STDIN_FILENO;
+                return RET_NERRNO(dup2(socket_fd, STDIN_FILENO));
 
         case EXEC_INPUT_NAMED_FD:
                 assert(named_iofds[STDIN_FILENO] >= 0);
 
                 (void) fd_nonblock(named_iofds[STDIN_FILENO], false);
-                return dup2(named_iofds[STDIN_FILENO], STDIN_FILENO) < 0 ? -errno : STDIN_FILENO;
+                return RET_NERRNO(dup2(named_iofds[STDIN_FILENO], STDIN_FILENO));
 
         case EXEC_INPUT_DATA: {
                 int fd;
@@ -641,7 +641,7 @@ static int setup_output(
 
                 /* Duplicate from stdout if possible */
                 if (can_inherit_stderr_from_stdout(context, o, e))
-                        return dup2(STDOUT_FILENO, fileno) < 0 ? -errno : fileno;
+                        return RET_NERRNO(dup2(STDOUT_FILENO, fileno));
 
                 o = e;
 
@@ -652,7 +652,7 @@ static int setup_output(
 
                 /* If the input is connected to anything that's not a /dev/null or a data fd, inherit that... */
                 if (!IN_SET(i, EXEC_INPUT_NULL, EXEC_INPUT_DATA))
-                        return dup2(STDIN_FILENO, fileno) < 0 ? -errno : fileno;
+                        return RET_NERRNO(dup2(STDIN_FILENO, fileno));
 
                 /* If we are not started from PID 1 we just inherit STDOUT from our parent process. */
                 if (getppid() != 1)
@@ -669,7 +669,7 @@ static int setup_output(
 
         case EXEC_OUTPUT_TTY:
                 if (is_terminal_input(i))
-                        return dup2(STDIN_FILENO, fileno) < 0 ? -errno : fileno;
+                        return RET_NERRNO(dup2(STDIN_FILENO, fileno));
 
                 /* We don't reset the terminal if this is just about output */
                 return open_terminal_as(exec_context_tty_path(context), O_WRONLY, fileno);
@@ -704,13 +704,13 @@ static int setup_output(
         case EXEC_OUTPUT_SOCKET:
                 assert(socket_fd >= 0);
 
-                return dup2(socket_fd, fileno) < 0 ? -errno : fileno;
+                return RET_NERRNO(dup2(socket_fd, fileno));
 
         case EXEC_OUTPUT_NAMED_FD:
                 assert(named_iofds[fileno] >= 0);
 
                 (void) fd_nonblock(named_iofds[fileno], false);
-                return dup2(named_iofds[fileno], fileno) < 0 ? -errno : fileno;
+                return RET_NERRNO(dup2(named_iofds[fileno], fileno));
 
         case EXEC_OUTPUT_FILE:
         case EXEC_OUTPUT_FILE_APPEND:
@@ -724,7 +724,7 @@ static int setup_output(
                         streq_ptr(context->stdio_file[fileno], context->stdio_file[STDIN_FILENO]);
 
                 if (rw)
-                        return dup2(STDIN_FILENO, fileno) < 0 ? -errno : fileno;
+                        return RET_NERRNO(dup2(STDIN_FILENO, fileno));
 
                 flags = O_WRONLY;
                 if (o == EXEC_OUTPUT_FILE_APPEND)
@@ -6238,7 +6238,7 @@ static void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
         cmd = quote_command_line(c->argv, SHELL_ESCAPE_EMPTY);
         fprintf(f,
                 "%sCommand Line: %s\n",
-                prefix, cmd ? cmd : strerror_safe(ENOMEM));
+                prefix, cmd ?: strerror_safe(ENOMEM));
 
         exec_status_dump(&c->exec_status, f, prefix2);
 }
index 929cc85e13b206fd299135eacedb618bba4295fb..27d750333258d10bd70148ccde7c1cbde9090cba 100644 (file)
@@ -3224,10 +3224,7 @@ int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency
 
 int set_unit_path(const char *p) {
         /* This is mostly for debug purposes */
-        if (setenv("SYSTEMD_UNIT_PATH", p, 1) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(setenv("SYSTEMD_UNIT_PATH", p, 1));
 }
 
 char *unit_dbus_path(Unit *u) {
index 20fbf6270156df0242a80eeac7a7939a741fd536..79d46f73064ec4686eb8a3da304f9cb93d8a9ee6 100644 (file)
@@ -185,10 +185,7 @@ static int block_get_size_by_fd(int fd, uint64_t *ret) {
         if (!S_ISBLK(st.st_mode))
                 return -ENOTBLK;
 
-        if (ioctl(fd, BLKGETSIZE64, ret) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BLKGETSIZE64, ret));
 }
 
 static int block_get_size_by_path(const char *path, uint64_t *ret) {
index 35db30de7810bfab255bcf2df86b12ea71332654..8cbdbaa35f262f3fbc2c1a68bc18903dbc8a4591 100644 (file)
@@ -228,7 +228,7 @@ static int tar_import_fork_tar(TarImport *i) {
         if (i->flags & IMPORT_BTRFS_SUBVOL)
                 r = btrfs_subvol_make_fallback(d, 0755);
         else
-                r = mkdir(d, 0755) < 0 ? -errno : 0;
+                r = RET_NERRNO(mkdir(d, 0755));
         if (r == -EEXIST && (i->flags & IMPORT_DIRECT)) /* EEXIST is OK if in direct mode, but not otherwise,
                                                          * because in that case our temporary path collided */
                 r = 0;
index 67e06a144583e086efde2f28f9695342a1c8d623..9608129e5e2a2b31b76046b84d9f15f89073d675 100644 (file)
@@ -520,7 +520,7 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) {
         if (i->flags & PULL_BTRFS_SUBVOL)
                 r = btrfs_subvol_make_fallback(where, 0755);
         else
-                r = mkdir(where, 0755) < 0 ? -errno : 0;
+                r = RET_NERRNO(mkdir(where, 0755));
         if (r == -EEXIST && (i->flags & PULL_DIRECT)) /* EEXIST is OK if in direct mode, but not otherwise,
                                                        * because in that case our temporary path collided */
                 r = 0;
index f9e2be155e7fe9e4f8d03eb98a4e1825c8c62b94..8d21627b3f24cb49e489cd1d8a3520ea684b1599 100644 (file)
@@ -3793,10 +3793,7 @@ static int arm_watchdog(sd_event *e) {
         if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
                 its.it_value.tv_nsec = 1;
 
-        if (timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL));
 }
 
 static int process_watchdog(sd_event *e) {
@@ -3906,7 +3903,7 @@ static int epoll_wait_usec(
                 int maxevents,
                 usec_t timeout) {
 
-        int r, msec;
+        int msec;
 #if 0
         static bool epoll_pwait2_absent = false;
 
@@ -3946,14 +3943,7 @@ static int epoll_wait_usec(
                         msec = (int) k;
         }
 
-        r = epoll_wait(fd,
-                       events,
-                       maxevents,
-                       msec);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(epoll_wait(fd, events, maxevents, msec));
 }
 
 static int process_epoll(sd_event *e, usec_t timeout, int64_t threshold, int64_t *ret_min_priority) {
index 35a6e8e64a3a799f0058ae688ae151b296ba9108..211af404bd8efedfb3dcd45d52503ebcfbd172c5 100644 (file)
@@ -57,11 +57,7 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) {
         if (r < 0)
                 return r;
 
-        r = fcntl(fd, F_DUPFD_CLOEXEC, 3);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(fcntl(fd, F_DUPFD_CLOEXEC, 3));
 }
 
 static int print_inhibitors(sd_bus *bus) {
index f8048f6d23b7080947a401f4d3c8c60587c1b763..1de71c248128f15f16789189bb670a29f0c1064a 100644 (file)
@@ -9,6 +9,7 @@
 #include "alloc-util.h"
 #include "env-file.h"
 #include "errno-list.h"
+#include "errno-util.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -327,11 +328,7 @@ int inhibitor_create_fifo(Inhibitor *i) {
         }
 
         /* Open writing side */
-        r = open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK));
 }
 
 static void inhibitor_remove_fifo(Inhibitor *i) {
index 09e19a3509db27293415d38a7b0ebcb25b4ca5e3..19e00b996e5fdb173b86619f79c6ffb1f66acb59 100644 (file)
@@ -105,20 +105,12 @@ static void sd_eviocrevoke(int fd) {
 
 static int sd_drmsetmaster(int fd) {
         assert(fd >= 0);
-
-        if (ioctl(fd, DRM_IOCTL_SET_MASTER, 0) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, DRM_IOCTL_SET_MASTER, 0));
 }
 
 static int sd_drmdropmaster(int fd) {
         assert(fd >= 0);
-
-        if (ioctl(fd, DRM_IOCTL_DROP_MASTER, 0) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, DRM_IOCTL_DROP_MASTER, 0));
 }
 
 static int session_device_open(SessionDevice *sd, bool active) {
index cde2b5e8bb39294baee5fc9d32edc98cf599f8d9..d6d67af05a5530b0a7f653283af9281322ac5e14 100644 (file)
@@ -1097,11 +1097,7 @@ int session_create_fifo(Session *s) {
         }
 
         /* Open writing side */
-        r = open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK));
 }
 
 static void session_remove_fifo(Session *s) {
index c0ed24b6452eb051edba21210a1475c9ffbe639e..a42478e87485b17720346c81ee9b5780bfc4d0d5 100644 (file)
@@ -575,14 +575,8 @@ int machine_kill(Machine *m, KillWho who, int signo) {
         if (!m->unit)
                 return -ESRCH;
 
-        if (who == KILL_LEADER) {
-                /* If we shall simply kill the leader, do so directly */
-
-                if (kill(m->leader, signo) < 0)
-                        return -errno;
-
-                return 0;
-        }
+        if (who == KILL_LEADER) /* If we shall simply kill the leader, do so directly */
+                return RET_NERRNO(kill(m->leader, signo));
 
         /* Otherwise, make PID 1 do it for us, for the entire cgroup */
         return manager_kill_unit(m->manager, m->unit, signo, NULL);
index b85b8c3d43cd8511ba34bd0ab75ae52adf5c865b..8098d37962f07e7d3c194137ef0836f6b157ae70 100644 (file)
@@ -1879,10 +1879,7 @@ int userns_lchown(const char *p, uid_t uid, gid_t gid) {
                         return -EOVERFLOW;
         }
 
-        if (lchown(p, uid, gid) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(lchown(p, uid, gid));
 }
 
 int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid_t gid) {
index 8fdb5272e9d7a8ffe46015ebc36c01e38df89dff..298f3df3c7a92a4551f4641fb280eb79f8cc7c27 100644 (file)
@@ -19,6 +19,7 @@
 #include "efi-loader.h"
 #include "env-file.h"
 #include "env-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "parse-util.h"
@@ -1077,7 +1078,7 @@ static int verify_fsroot_dir(
                         if (!parent)
                                 return log_oom();
 
-                        r = stat(parent, &st2) < 0 ? -errno : 0;
+                        r = RET_NERRNO(stat(parent, &st2));
                 }
 
                 if (r < 0)
index a73e1e995b0cc7df29f2bb2c993b5a0a0a55962d..b8ca32a1f01d830cc53c32362a70fe3770a5b4b4 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "alloc-util.h"
 #include "bpf-program.h"
+#include "errno-util.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "memory-util.h"
@@ -74,10 +75,7 @@ static int bpf_program_get_info_by_fd(int prog_fd, struct bpf_prog_info *info, u
         attr.info.info_len = info_len;
         attr.info.info = PTR_TO_UINT64(info);
 
-        if (bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)));
 }
 
 int bpf_program_new(uint32_t prog_type, BPFProgram **ret) {
@@ -290,7 +288,6 @@ int bpf_program_cgroup_detach(BPFProgram *p) {
 
 int bpf_map_new(enum bpf_map_type type, size_t key_size, size_t value_size, size_t max_entries, uint32_t flags) {
         union bpf_attr attr;
-        int fd;
 
         zero(attr);
         attr.map_type = type;
@@ -299,11 +296,7 @@ int bpf_map_new(enum bpf_map_type type, size_t key_size, size_t value_size, size
         attr.max_entries = max_entries;
         attr.map_flags = flags;
 
-        fd = bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-        if (fd < 0)
-                return -errno;
-
-        return fd;
+        return RET_NERRNO(bpf(BPF_MAP_CREATE, &attr, sizeof(attr)));
 }
 
 int bpf_map_update_element(int fd, const void *key, void *value) {
@@ -314,10 +307,7 @@ int bpf_map_update_element(int fd, const void *key, void *value) {
         attr.key = PTR_TO_UINT64(key);
         attr.value = PTR_TO_UINT64(value);
 
-        if (bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)));
 }
 
 int bpf_map_lookup_element(int fd, const void *key, void *value) {
@@ -328,10 +318,7 @@ int bpf_map_lookup_element(int fd, const void *key, void *value) {
         attr.key = PTR_TO_UINT64(key);
         attr.value = PTR_TO_UINT64(value);
 
-        if (bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)));
 }
 
 int bpf_program_pin(int prog_fd, const char *bpffs_path) {
@@ -341,10 +328,7 @@ int bpf_program_pin(int prog_fd, const char *bpffs_path) {
         attr.pathname = PTR_TO_UINT64((void *) bpffs_path);
         attr.bpf_fd = prog_fd;
 
-        if (bpf(BPF_OBJ_PIN, &attr, sizeof(attr)) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(bpf(BPF_OBJ_PIN, &attr, sizeof(attr)));
 }
 
 int bpf_program_get_id_by_fd(int prog_fd, uint32_t *ret_id) {
index b01c72aa9ba5282ceffd58d18afda4da76482097..ec5951b52f6f25741ed45c24ad7763977b71bb02 100644 (file)
@@ -124,10 +124,7 @@ int btrfs_subvol_make_fd(int fd, const char *subvolume) {
 
         strncpy(args.name, subvolume, sizeof(args.name)-1);
 
-        if (ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args));
 }
 
 int btrfs_subvol_make(const char *path) {
@@ -192,10 +189,7 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
         if (flags == nflags)
                 return 0;
 
-        if (ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &nflags) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &nflags));
 }
 
 int btrfs_subvol_set_read_only(const char *path, bool b) {
@@ -238,10 +232,7 @@ int btrfs_reflink(int infd, int outfd) {
         if (r < 0)
                 return r;
 
-        if (ioctl(outfd, BTRFS_IOC_CLONE, infd) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(outfd, BTRFS_IOC_CLONE, infd));
 }
 
 int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offset, uint64_t sz) {
@@ -261,10 +252,7 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offs
         if (r < 0)
                 return r;
 
-        if (ioctl(outfd, BTRFS_IOC_CLONE_RANGE, &args) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(outfd, BTRFS_IOC_CLONE_RANGE, &args));
 }
 
 int btrfs_get_block_device_fd(int fd, dev_t *dev) {
@@ -775,10 +763,7 @@ int btrfs_quota_enable_fd(int fd, bool b) {
         if (!r)
                 return -ENOTTY;
 
-        if (ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args));
 }
 
 int btrfs_quota_enable(const char *path, bool b) {
@@ -982,19 +967,13 @@ int btrfs_quota_scan_start(int fd) {
 
         assert(fd >= 0);
 
-        if (ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args));
 }
 
 int btrfs_quota_scan_wait(int fd) {
         assert(fd >= 0);
 
-        if (ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT));
 }
 
 int btrfs_quota_scan_ongoing(int fd) {
index 7c1c48d0690030db1b154cbb31540ace8da39ac1..febea8ea85463c9340c61042363391f2f4f0f53f 100644 (file)
@@ -48,10 +48,7 @@ int clock_set_hwclock(const struct tm *tm) {
         if (fd < 0)
                 return -errno;
 
-        if (ioctl(fd, RTC_SET_TIME, tm) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, RTC_SET_TIME, tm));
 }
 
 int clock_is_localtime(const char* adjtime_path) {
@@ -131,10 +128,7 @@ int clock_reset_timewarp(void) {
 
         /* The very first call to settimeofday() does time warp magic. Do a dummy call here, so the time
          * warping is sealed and all later calls behave as expected. */
-        if (settimeofday(NULL, &tz) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(settimeofday(NULL, &tz));
 }
 
 #define EPOCH_FILE "/usr/lib/clock-epoch"
index 9053fce33378456945b905b962ca695156c4c45c..51dd08eccd1035ad7214308fb953191fb1c276bf 100644 (file)
@@ -1380,10 +1380,7 @@ int copy_access(int fdf, int fdt) {
         if (fstat(fdf, &st) < 0)
                 return -errno;
 
-        if (fchmod(fdt, st.st_mode & 07777) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fchmod(fdt, st.st_mode & 07777));
 }
 
 int copy_rights_with_fallback(int fdf, int fdt, const char *patht) {
index a827ef5a8bcecf8828c983c61dec79f7a76b0e8f..6ae3f115350f9754048fe7e593ce24bd0a269241 100644 (file)
@@ -49,14 +49,9 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags) {
          * It sucks a bit that depending on the situation we return very different objects here, but that's Linux I
          * figure. */
 
-        if (size == 0 && ((flags & ACQUIRE_NO_DEV_NULL) == 0)) {
+        if (size == 0 && ((flags & ACQUIRE_NO_DEV_NULL) == 0))
                 /* As a special case, return /dev/null if we have been called for an empty data block */
-                r = open("/dev/null", O_RDONLY|O_CLOEXEC|O_NOCTTY);
-                if (r < 0)
-                        return -errno;
-
-                return r;
-        }
+                return RET_NERRNO(open("/dev/null", O_RDONLY|O_CLOEXEC|O_NOCTTY));
 
         if ((flags & ACQUIRE_NO_MEMFD) == 0) {
                 fd = memfd_new("data-fd");
index 8afb51328e5285c03dd1b9de7ffbd8b27c343caa..489a29fa2e846819145a6605763f44aae8f6449a 100644 (file)
@@ -462,10 +462,8 @@ int ethtool_set_wol(
                 return 0;
         }
 
-        r = 0;
         ecmd.cmd = ETHTOOL_SWOL;
-        if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
-                r = -errno;
+        r = RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
 
         explicit_bzero_safe(&ecmd, sizeof(ecmd));
         return r;
@@ -516,10 +514,7 @@ int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netde
                 return 0;
 
         ecmd.cmd = ETHTOOL_SRINGPARAM;
-        if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
 }
 
 static int get_stringset(int ethtool_fd, const char *ifname, enum ethtool_stringset stringset_id, struct ethtool_gstrings **ret) {
@@ -878,10 +873,7 @@ static int set_slinksettings(int fd, struct ifreq *ifr, const struct ethtool_lin
 
         ifr->ifr_data = (void *) &ecmd;
 
-        if (ioctl(fd, SIOCETHTOOL, ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, SIOCETHTOOL, ifr));
 }
 
 static int set_sset(int fd, struct ifreq *ifr, const struct ethtool_link_usettings *u) {
@@ -912,10 +904,7 @@ static int set_sset(int fd, struct ifreq *ifr, const struct ethtool_link_usettin
 
         ifr->ifr_data = (void *) &ecmd;
 
-        if (ioctl(fd, SIOCETHTOOL, ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, SIOCETHTOOL, ifr));
 }
 
 int ethtool_set_glinksettings(
@@ -1053,10 +1042,7 @@ int ethtool_set_channels(int *fd, const char *ifname, const netdev_channels *cha
                 return 0;
 
         ecmd.cmd = ETHTOOL_SCHANNELS;
-        if (ioctl(*fd, SIOCETHTOOL, &ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(*fd, SIOCETHTOOL, &ifr));
 }
 
 int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg) {
@@ -1097,10 +1083,7 @@ int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int au
                 return 0;
 
         ecmd.cmd = ETHTOOL_SPAUSEPARAM;
-        if (ioctl(*fd, SIOCETHTOOL, &ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(*fd, SIOCETHTOOL, &ifr));
 }
 
 int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce) {
@@ -1220,10 +1203,7 @@ int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const
                 return 0;
 
         ecmd.cmd = ETHTOOL_SCOALESCE;
-        if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
 }
 
 int config_parse_advertise(
index 1fc492fb3110e6f3417453964002059fd90417eb..dea15871f61af48494cd1e3569e69f1565c139bb 100644 (file)
@@ -35,9 +35,7 @@ int symlink_label(const char *old_path, const char *new_path) {
         if (r < 0)
                 return r;
 
-        if (symlink(old_path, new_path) < 0)
-                r = -errno;
-
+        r = RET_NERRNO(symlink(old_path, new_path));
         mac_selinux_create_file_clear();
 
         if (r < 0)
@@ -56,9 +54,7 @@ int symlink_atomic_label(const char *from, const char *to) {
         if (r < 0)
                 return r;
 
-        if (symlink_atomic(from, to) < 0)
-                r = -errno;
-
+        r = symlink_atomic(from, to);
         mac_selinux_create_file_clear();
 
         if (r < 0)
@@ -76,9 +72,7 @@ int mknod_label(const char *pathname, mode_t mode, dev_t dev) {
         if (r < 0)
                 return r;
 
-        if (mknod(pathname, mode, dev) < 0)
-                r = -errno;
-
+        r = RET_NERRNO(mknod(pathname, mode, dev));
         mac_selinux_create_file_clear();
 
         if (r < 0)
index 49afa4dac6c9d0a52ce8a9eb68adc01bb89d3b1f..b55d4e44badc18bafe34efb76ce7a59f0349799f 100644 (file)
@@ -887,10 +887,7 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) {
                 .datalen = sizeof(bp),
         };
 
-        if (ioctl(whole_fd, BLKPG, &ba) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(whole_fd, BLKPG, &ba));
 }
 
 int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
@@ -927,10 +924,7 @@ int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
         if (offset != UINT64_MAX)
                 info.lo_offset = offset;
 
-        if (ioctl(d->fd, LOOP_SET_STATUS64, &info) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(d->fd, LOOP_SET_STATUS64, &info));
 }
 
 int loop_device_flock(LoopDevice *d, int operation) {
@@ -939,10 +933,7 @@ int loop_device_flock(LoopDevice *d, int operation) {
         if (d->fd < 0)
                 return -EBADF;
 
-        if (flock(d->fd, operation) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(flock(d->fd, operation));
 }
 
 int loop_device_sync(LoopDevice *d) {
@@ -954,8 +945,5 @@ int loop_device_sync(LoopDevice *d) {
         if (d->fd < 0)
                 return -EBADF;
 
-        if (fsync(d->fd) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(fsync(d->fd));
 }
index 7057a8763edcda3d9cc309bf43d61d154eff226e..da6bf2742637d266715156bbae021b384787c411 100644 (file)
@@ -189,7 +189,7 @@ static int mount_one(const MountPoint *p, bool relabel) {
                   strna(p->options));
 
         if (FLAGS_SET(p->mode, MNT_FOLLOW_SYMLINK))
-                r = mount(p->what, p->where, p->type, p->flags, p->options) < 0 ? -errno : 0;
+                r = RET_NERRNO(mount(p->what, p->where, p->type, p->flags, p->options));
         else
                 r = mount_nofollow(p->what, p->where, p->type, p->flags, p->options);
         if (r < 0) {
index 813fdc1664a53cd3ef11bb521ef56bc771858b2b..fcc900bdce677e45c2e95d295ebf40e13b3e2963 100644 (file)
@@ -484,10 +484,7 @@ int mount_move_root(const char *path) {
         if (chroot(".") < 0)
                 return -errno;
 
-        if (chdir("/") < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(chdir("/"));
 }
 
 int repeat_unmount(const char *path, int flags) {
@@ -683,7 +680,7 @@ int mount_verbose_full(
                           strna(what), strna(type), where, strnull(fl), strempty(o));
 
         if (follow_symlink)
-                r = mount(what, where, type, f, o) < 0 ? -errno : 0;
+                r = RET_NERRNO(mount(what, where, type, f, o));
         else
                 r = mount_nofollow(what, where, type, f, o);
         if (r < 0)
index da43fa22b9fc26050b07cca736f1781e8d64949a..5745fe09a252a501f9d7487c81682124231a04b9 100644 (file)
@@ -376,11 +376,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
         if (sclass == 0)
                 return -ENOSYS;
 
-        r = security_compute_create_raw(mycon, fcon, sclass, label);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(security_compute_create_raw(mycon, fcon, sclass, label));
 #else
         return -EOPNOTSUPP;
 #endif
@@ -388,18 +384,12 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
 
 int mac_selinux_get_our_label(char **label) {
 #if HAVE_SELINUX
-        int r;
-
         assert(label);
 
         if (!mac_selinux_use())
                 return -EOPNOTSUPP;
 
-        r = getcon_raw(label);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(getcon_raw(label));
 #else
         return -EOPNOTSUPP;
 #endif
@@ -461,11 +451,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
         if (sclass == 0)
                 return -ENOSYS;
 
-        r = security_compute_create_raw(mycon, fcon, sclass, label);
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(security_compute_create_raw(mycon, fcon, sclass, label));
 #else
         return -EOPNOTSUPP;
 #endif
@@ -684,7 +670,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
                         context_changed = true;
         }
 
-        r = bind(fd, addr, addrlen) < 0 ? -errno : 0;
+        r = RET_NERRNO(bind(fd, addr, addrlen));
 
         if (context_changed)
                 (void) setfscreatecon_raw(NULL);
@@ -693,8 +679,5 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
 
 skipped:
 #endif
-        if (bind(fd, addr, addrlen) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(bind(fd, addr, addrlen));
 }
index ea78762e657678821510a9ff496b03f4e16195ed..1669dec50e3ea5463e9f5ed34a2bc6114dcbdae3 100644 (file)
@@ -51,14 +51,13 @@ int socket_address_listen(
                         return r;
         }
 
-        fd = socket(socket_address_family(a), a->type | flags, a->protocol);
-        r = fd < 0 ? -errno : 0;
+        fd = RET_NERRNO(socket(socket_address_family(a), a->type | flags, a->protocol));
 
         if (label)
                 mac_selinux_create_socket_clear();
 
-        if (r < 0)
-                return r;
+        if (fd < 0)
+                return fd;
 
         if (socket_address_family(a) == AF_INET6 && only != SOCKET_ADDRESS_DEFAULT) {
                 r = setsockopt_int(fd, IPPROTO_IPV6, IPV6_V6ONLY, only == SOCKET_ADDRESS_IPV6_ONLY);
index 881d4e471e9bb00e41431c4128423fe7f0905c8d..e95d167a6e88f3a73ff46f6906f60705bb322492 100644 (file)
@@ -472,7 +472,7 @@ static int delete_dm(MountPoint *m) {
         if (r < 0)
                 log_debug_errno(r, "Failed to sync DM block device %s, ignoring: %m", m->path);
 
-        if (ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
+        return RET_NERRNO(ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
                 .version = {
                         DM_VERSION_MAJOR,
                         DM_VERSION_MINOR,
@@ -480,10 +480,7 @@ static int delete_dm(MountPoint *m) {
                 },
                 .data_size = sizeof(struct dm_ioctl),
                 .dev = m->devnum,
-        }) < 0)
-                return -errno;
-
-        return 0;
+        }));
 }
 
 static int delete_md(MountPoint *m) {
@@ -500,10 +497,7 @@ static int delete_md(MountPoint *m) {
         if (fsync(fd) < 0)
                 log_debug_errno(errno, "Failed to sync MD block device %s, ignoring: %m", m->path);
 
-        if (ioctl(fd, STOP_ARRAY, NULL) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(ioctl(fd, STOP_ARRAY, NULL));
 }
 
 static bool nonunmountable_path(const char *path) {
index 0e60f2c00fe938a9169d5a7bcfaf54cf425740c2..0011ff47703af771acdc2928c4c059dac23e2ec0 100644 (file)
@@ -958,10 +958,7 @@ static int root_stat(const char *p, struct stat *st) {
         const char *fix;
 
         fix = prefix_roota(arg_root, p);
-        if (stat(fix, st) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(stat(fix, st));
 }
 
 static int read_id_from_file(Item *i, uid_t *_uid, gid_t *_gid) {
index 56a332326fe2d7eb5098a1b20651cc9986394bf8..d6206ffd6afe992a0bfec88506430d953cebfb89 100644 (file)
@@ -2160,18 +2160,17 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
                         /* rm_if_wrong_type_safe already logs errors. */
                         return r;
 
-                next_fd = openat(parent_fd, t, O_NOCTTY | O_CLOEXEC | O_DIRECTORY);
+                next_fd = RET_NERRNO(openat(parent_fd, t, O_NOCTTY | O_CLOEXEC | O_DIRECTORY));
                 if (next_fd < 0) {
                         _cleanup_free_ char *parent_name = NULL;
 
-                        r = -errno;
                         (void) fd_get_path(parent_fd, &parent_name);
-                        return log_error_errno(r, "Failed to open \"%s\" at \"%s\": %m", t, strnull(parent_name));
+                        return log_error_errno(next_fd, "Failed to open \"%s\" at \"%s\": %m", t, strnull(parent_name));
                 }
-                if (fstat(next_fd, &parent_st) < 0) {
+                r = RET_NERRNO(fstat(next_fd, &parent_st));
+                if (r < 0) {
                         _cleanup_free_ char *parent_name = NULL;
 
-                        r = -errno;
                         (void) fd_get_path(parent_fd, &parent_name);
                         return log_error_errno(r, "Failed to stat \"%s\" at \"%s\": %m", t, strnull(parent_name));
                 }
@@ -2309,7 +2308,7 @@ static int create_item(Item *i) {
                                                         return log_error_errno(r, "rm -fr %s failed: %m", i->path);
 
                                                 mac_selinux_create_file_prepare(i->path, S_IFLNK);
-                                                r = symlink(i->argument, i->path) < 0 ? -errno : 0;
+                                                r = RET_NERRNO(symlink(i->argument, i->path));
                                                 mac_selinux_create_file_clear();
                                         }
                                         if (r < 0)
index e1fb387cb99098ee548417209028a260a0946ccd..809db14e60753d5141a4e3d9849191c7d50b243b 100644 (file)
@@ -53,10 +53,7 @@ static int create_symlink(const char *target, const char *slink) {
                         return r;
 
                 mac_selinux_create_file_prepare(slink, S_IFLNK);
-                if (symlink(target, slink) < 0)
-                        r = -errno;
-                else
-                        r = 0;
+                r = RET_NERRNO(symlink(target, slink));
                 mac_selinux_create_file_clear();
                 if (r != -ENOENT)
                         return r;
index 1b1a4835e648e22db375c4fec62e92f09f81b20f..18d58c308c059739ad77ead396c520dbe6488a9b 100644 (file)
@@ -528,11 +528,7 @@ static int run(int argc, char *argv[]) {
                 }
 
                 (void) rename_process("systemd-userwork: waiting...");
-
-                fd = accept4(listen_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
-                if (fd < 0)
-                        fd = -errno;
-
+                fd = RET_NERRNO(accept4(listen_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC));
                 (void) rename_process("systemd-userwork: processing...");
 
                 if (fd == -EAGAIN)
index d1c3febdd5bb95ac91d0b9ac28b4cb72d296266e..50930d4af3b9c3683bd9189edff5b4706a2a81e8 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "alloc-util.h"
 #include "env-file.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "io-util.h"
@@ -40,13 +41,7 @@ static int verify_vc_device(int fd) {
                 TIOCL_GETFGCONSOLE,
         };
 
-        int r;
-
-        r = ioctl(fd, TIOCLINUX, data);
-        if (r < 0)
-                return -errno;
-
-        return r;
+        return RET_NERRNO(ioctl(fd, TIOCLINUX, data));
 }
 
 static int verify_vc_allocation(unsigned idx) {
@@ -54,10 +49,7 @@ static int verify_vc_allocation(unsigned idx) {
 
         xsprintf(vcname, "/dev/vcs%u", idx);
 
-        if (access(vcname, F_OK) < 0)
-                return -errno;
-
-        return 0;
+        return RET_NERRNO(access(vcname, F_OK));
 }
 
 static int verify_vc_allocation_byfd(int fd) {