1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 01:55:22 +03:00

tree-wide: use new RET_NERRNO() helper at various places

This commit is contained in:
Lennart Poettering 2021-11-14 22:40:49 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent ef470ffa23
commit 7c248223eb
51 changed files with 151 additions and 469 deletions

View 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) {

View 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) {

View 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) {

View 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));
}

View File

@ -30,18 +30,13 @@
#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;
_cleanup_umask_ mode_t u = umask(0777);
u = umask(0777);
r = fchmod(fd, m & (~u)) < 0 ? -errno : 0;
umask(u);
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(

View 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);

View 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) {

View 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) {

View 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) {

View 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. */

View 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) {

View 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, ...) {

View 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;

View 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));
}

View 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) {

View 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) {

View 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) {

View 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(

View 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) {

View 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) {

View 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);
}

View 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) {

View 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) {

View 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;

View 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;

View 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) {

View 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) {

View 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) {

View 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) {

View 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) {

View 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);

View 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) {

View 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)

View 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) {

View 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) {

View 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"

View 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) {

View 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");

View 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(

View 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)

View 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));
}

View 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) {

View 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)

View 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));
}

View 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);

View 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) {

View 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) {

View 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)

View 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;

View 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)

View 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) {