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

This commit is contained in:
Lennart Poettering
2021-11-16 08:04:09 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent ef470ffa23
commit 7c248223eb
51 changed files with 151 additions and 469 deletions
+2 -1
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)
+6 -22
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) {
+7 -28
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) {
+2 -8
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"
+1 -4
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) {
+2 -7
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");
+7 -27
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(
+3 -9
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)
+4 -16
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));
}
+1 -1
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) {
+2 -5
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)
+5 -22
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));
}
+3 -4
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);