1
0
mirror of https://github.com/systemd/systemd synced 2026-04-06 23:24:52 +02:00

Compare commits

..

No commits in common. "947796eac385651f6a66fc0ce925a301b49f6fa4" and "e6ace91eb7050f2dec21ffb01822dd00d56d4b75" have entirely different histories.

70 changed files with 528 additions and 566 deletions

View File

@ -285,25 +285,6 @@ SPDX-License-Identifier: LGPL-2.1-or-later
one cause, it *really* should have an `int` as the return value for the error
code.
- libc system calls typically return -1 on error (with the error code in
`errno`), and >= 0 on success. Use the RET_NERRNO() helper if you are looking
for a simple way to convert this libc style error returning into systemd
style error returning. e.g.
```c
r = RET_NERRNO(unlink(t));
```
or
```c
r = RET_NERRNO(open("/some/file", O_RDONLY|O_CLOEXEC));
```
- Do not bother with error checking whether writing to stdout/stderr worked.
- Do not log errors from "library" code, only do so from "main program"

View File

@ -209,7 +209,7 @@
<listitem>
<para>Link groups are similar to port ranges found in managed switches. When network interfaces
are added to a numbered group, operations on all the interfaces from that group can be
performed at once. Takes an unsigned integer in the range 0…2147483647. Defaults to unset.
performed at once. Takes an unsigned integer in the range 0…4294967295. Defaults to unset.
</para>
</listitem>
</varlistentry>
@ -952,21 +952,18 @@ Table=1234</programlisting></para>
<term><varname>ConfigureWithoutCarrier=</varname></term>
<listitem>
<para>Takes a boolean. Allows networkd to configure a specific link even if it has no carrier.
Defaults to false. If enabled, and the <varname>IgnoreCarrierLoss=</varname> setting is not
explicitly set, then it is enabled as well.
Defaults to false. If <option>IgnoreCarrierLoss=</option> is not explicitly set, it will
default to this value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>IgnoreCarrierLoss=</varname></term>
<listitem>
<para>Takes a boolean or a timespan. When true, networkd retains both the static and dynamic
configuration of the interface even if its carrier is lost. When a timespan is specified,
networkd waits for the specified timespan, and ignores the carrier loss if the link regain
its carrier within the timespan. Setting a finite timespan may be useful for a wireless
interface connecting to a network which has multiple access points with the same SSID, or an
interface which is reset on changing MTU. When unset, the value specified with
<varname>ConfigureWithoutCarrier=</varname> is used.</para>
<para>Takes a boolean. Allows networkd to retain both the static and dynamic configuration
of the interface even if its carrier is lost. When unset, the value specified with
<option>ConfigureWithoutCarrier=</option> is used.
</para>
<para>When <varname>ActivationPolicy=</varname> is set to <literal>always-up</literal>, this
is forced to <literal>true</literal>.
@ -1285,14 +1282,6 @@ Table=1234</programlisting></para>
unset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>SuppressInterfaceGroup=</varname></term>
<listitem>
<para>Takes an integer in the range 0…2147483647 and rejects routing decisions that have
an interface with the same group id. It has the same meaning as
<option>suppress_ifgroup</option> in <command>ip rule</command>. Defaults to unset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Type=</varname></term>
<listitem>
@ -1816,9 +1805,6 @@ Table=1234</programlisting></para>
<para>When true, the interface maximum transmission unit from the DHCP server will be used on the
current link. If <varname>MTUBytes=</varname> is set, then this setting is ignored. Defaults to
false.</para>
<para>Note, some drivers will reset the interfaces if the MTU is changed. For such
interfaces, please try to use <varname>IgnoreCarrierLoss=</varname> with a short timespan,
e.g. <literal>3 seconds</literal>.</para>
</listitem>
</varlistentry>

View File

@ -409,6 +409,7 @@ possible_cc_flags = possible_common_cc_flags + [
'-Werror=missing-declarations',
'-Werror=missing-prototypes',
'-fdiagnostics-show-option',
'-ffast-math',
'-fno-common',
'-fno-strict-aliasing',
'-fstack-protector',

View File

@ -587,7 +587,10 @@ static int controller_is_v1_accessible(const char *root, const char *controller)
* - we can modify the hierarchy. */
cpath = strjoina("/sys/fs/cgroup/", dn, root, root ? "/cgroup.procs" : NULL);
return laccess(cpath, root ? W_OK : F_OK);
if (laccess(cpath, root ? W_OK : F_OK) < 0)
return -errno;
return 0;
}
int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) {
@ -629,7 +632,10 @@ int cg_set_xattr(const char *controller, const char *path, const char *name, con
if (r < 0)
return r;
return RET_NERRNO(setxattr(fs, name, value, size, flags));
if (setxattr(fs, name, value, size, flags) < 0)
return -errno;
return 0;
}
int cg_get_xattr(const char *controller, const char *path, const char *name, void *value, size_t size) {
@ -694,7 +700,10 @@ int cg_remove_xattr(const char *controller, const char *path, const char *name)
if (r < 0)
return r;
return RET_NERRNO(removexattr(fs, name));
if (removexattr(fs, name) < 0)
return -errno;
return 0;
}
int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {

View File

@ -121,7 +121,10 @@ int read_attr_fd(int fd, unsigned *ret) {
if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
return -ENOTTY;
return RET_NERRNO(ioctl(fd, FS_IOC_GETFLAGS, ret));
if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0)
return -errno;
return 0;
}
int read_attr_path(const char *p, unsigned *ret) {

View File

@ -8,7 +8,6 @@
#include "alloc-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "escape.h"
#include "extract-word.h"
#include "macro.h"
@ -787,12 +786,15 @@ int getenv_bool_secure(const char *p) {
}
int set_unset_env(const char *name, const char *value, bool overwrite) {
assert(name);
int r;
if (value)
return RET_NERRNO(setenv(name, value, overwrite));
return RET_NERRNO(unsetenv(name));
r = setenv(name, value, overwrite);
else
r = unsetenv(name);
if (r < 0)
return -errno;
return 0;
}
int putenv_dup(const char *assignment, bool override) {
@ -805,7 +807,9 @@ 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[]. */
return RET_NERRNO(setenv(n, e + 1, override));
if (setenv(n, e + 1, override) < 0)
return -errno;
return 0;
}
int setenv_systemd_exec_pid(bool update_only) {

View File

@ -31,29 +31,6 @@ static inline int negative_errno(void) {
return -errno;
}
static inline int RET_NERRNO(int ret) {
/* Helper to wrap system calls in to make them return negative errno errors. This brings system call
* error handling in sync with how we usually handle errors in our own code, i.e. with immediate
* returning of negative errno. Usage is like this:
*
*
* r = RET_NERRNO(unlink(t));
*
*
* or
*
*
* fd = RET_NERRNO(open("/etc/fstab", O_RDONLY|O_CLOEXEC));
*
*/
if (ret < 0)
return negative_errno();
return ret;
}
static inline const char *strerror_safe(int error) {
/* 'safe' here does NOT mean thread safety. */
return strerror(abs(error)); /* lgtm [cpp/potentially-dangerous-function] */

View File

@ -152,7 +152,10 @@ int fd_nonblock(int fd, bool nonblock) {
if (nflags == flags)
return 0;
return RET_NERRNO(fcntl(fd, F_SETFL, nflags));
if (fcntl(fd, F_SETFL, nflags) < 0)
return -errno;
return 0;
}
int fd_cloexec(int fd, bool cloexec) {
@ -168,7 +171,10 @@ int fd_cloexec(int fd, bool cloexec) {
if (nflags == flags)
return 0;
return RET_NERRNO(fcntl(fd, F_SETFD, nflags));
if (fcntl(fd, F_SETFD, nflags) < 0)
return -errno;
return 0;
}
_pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) {
@ -796,5 +802,8 @@ int btrfs_defrag_fd(int fd) {
if (r < 0)
return r;
return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL));
if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0)
return -errno;
return 0;
}

View File

@ -30,13 +30,18 @@
#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;
return RET_NERRNO(unlink(path));
int r;
r = unlink(path);
if (r < 0)
return -errno;
return 0;
}
int rmdir_parents(const char *path, const char *stop) {
@ -92,8 +97,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) {
r = RET_NERRNO(unlinkat(olddirfd, oldpath, 0));
if (r < 0) {
if (unlinkat(olddirfd, oldpath, 0) < 0) {
r = -errno; /* Backup errno before the following unlinkat() alters it */
(void) unlinkat(newdirfd, newpath, 0);
return r;
}
@ -112,7 +117,10 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
if (errno != ENOENT)
return -errno;
return RET_NERRNO(renameat(olddirfd, oldpath, newdirfd, newpath));
if (renameat(olddirfd, oldpath, newdirfd, newpath) < 0)
return -errno;
return 0;
}
int readlinkat_malloc(int fd, const char *p, char **ret) {
@ -278,9 +286,14 @@ int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t
}
int fchmod_umask(int fd, mode_t m) {
_cleanup_umask_ mode_t u = umask(0777);
mode_t u;
int r;
return RET_NERRNO(fchmod(fd, m & (~u)));
u = umask(0777);
r = fchmod(fd, m & (~u)) < 0 ? -errno : 0;
umask(u);
return r;
}
int fchmod_opath(int fd, mode_t m) {
@ -809,7 +822,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 r;
int fd, r;
r = path_extract_directory(path, &parent);
if (r < 0)
@ -823,7 +836,11 @@ int open_parent(const char *path, int flags, mode_t mode) {
else if (!FLAGS_SET(flags, O_TMPFILE))
flags |= O_DIRECTORY|O_RDONLY;
return RET_NERRNO(open(parent, flags, mode));
fd = open(parent, flags, mode);
if (fd < 0)
return -errno;
return fd;
}
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) \
RET_NERRNO(faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW))
(faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) < 0 ? -errno : 0)
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,7 +10,6 @@
#include <sys/prctl.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "macro.h"
#include "memfd-util.h"
@ -22,6 +21,7 @@
int memfd_new(const char *name) {
_cleanup_free_ char *g = NULL;
int fd;
if (!name) {
char pr[17] = {};
@ -49,7 +49,11 @@ int memfd_new(const char *name) {
}
}
return RET_NERRNO(memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC));
fd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
if (fd < 0)
return -errno;
return fd;
}
int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
@ -68,6 +72,7 @@ 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;
@ -76,9 +81,15 @@ int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
}
int memfd_set_sealed(int fd) {
int r;
assert(fd >= 0);
return RET_NERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL));
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;
}
int memfd_get_sealed(int fd) {
@ -95,11 +106,13 @@ 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);
if (fstat(fd, &stat) < 0)
r = fstat(fd, &stat);
if (r < 0)
return -errno;
*sz = stat.st_size;
@ -107,9 +120,15 @@ int memfd_get_size(int fd, uint64_t *sz) {
}
int memfd_set_size(int fd, uint64_t sz) {
int r;
assert(fd >= 0);
return RET_NERRNO(ftruncate(fd, sz));
r = ftruncate(fd, sz);
if (r < 0)
return -errno;
return 0;
}
int memfd_new_and_map(const char *name, size_t sz, void **p) {

View File

@ -80,11 +80,15 @@ int mkdir_safe_internal(
}
int mkdir_errno_wrapper(const char *pathname, mode_t mode) {
return RET_NERRNO(mkdir(pathname, mode));
if (mkdir(pathname, mode) < 0)
return -errno;
return 0;
}
int mkdirat_errno_wrapper(int dirfd, const char *pathname, mode_t mode) {
return RET_NERRNO(mkdirat(dirfd, pathname, mode));
if (mkdirat(dirfd, pathname, mode) < 0)
return -errno;
return 0;
}
int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) {

View File

@ -4,7 +4,6 @@
#include <sys/ioctl.h>
#include <sys/mount.h>
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "missing_fs.h"
@ -178,7 +177,10 @@ int detach_mount_namespace(void) {
if (unshare(CLONE_NEWNS) < 0)
return -errno;
return RET_NERRNO(mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL));
if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
return -errno;
return 0;
}
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 = RET_NERRNO(sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)));
r = sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)) < 0 ? -errno : 0;
/* 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 = RET_NERRNO(kill(pid, sig));
r = kill(pid, sig) < 0 ? -errno : 0;
/* 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,7 +3,6 @@
#include <errno.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "format-util.h"
@ -46,7 +45,10 @@ 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);
return RET_NERRNO(setrlimit(resource, &fixed));
if (setrlimit(resource, &fixed) < 0)
return -errno;
return 0;
}
int setrlimit_closest_all(const struct rlimit *const *rlim, int *which_failed) {

View File

@ -3,7 +3,6 @@
#include <errno.h>
#include <stdarg.h>
#include "errno-util.h"
#include "macro.h"
#include "parse-util.h"
#include "signal-util.h"
@ -40,7 +39,10 @@ int reset_signal_mask(void) {
if (sigemptyset(&ss) < 0)
return -errno;
return RET_NERRNO(sigprocmask(SIG_SETMASK, &ss, NULL));
if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0)
return -errno;
return 0;
}
int sigaction_many_internal(const struct sigaction *sa, ...) {
@ -245,7 +247,11 @@ int signal_is_blocked(int sig) {
if (r != 0)
return -r;
return RET_NERRNO(sigismember(&ss, sig));
r = sigismember(&ss, sig);
if (r < 0)
return -errno;
return r;
}
int pop_pending_signal_internal(int sig, ...) {

View File

@ -1226,7 +1226,10 @@ int socket_bind_to_ifname(int fd, const char *ifname) {
/* Call with NULL to drop binding */
return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname)));
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname)) < 0)
return -errno;
return 0;
}
int socket_bind_to_ifindex(int fd, int ifindex) {
@ -1235,9 +1238,13 @@ int socket_bind_to_ifindex(int fd, int ifindex) {
assert(fd >= 0);
if (ifindex <= 0)
if (ifindex <= 0) {
/* Drop binding */
return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0));
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0) < 0)
return -errno;
return 0;
}
r = setsockopt_int(fd, SOL_SOCKET, SO_BINDTOIFINDEX, ifindex);
if (r != -ENOPROTOOPT)
@ -1325,10 +1332,16 @@ int socket_set_unicast_if(int fd, int af, int ifi) {
switch (af) {
case AF_INET:
return RET_NERRNO(setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)));
if (setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0)
return -errno;
return 0;
case AF_INET6:
return RET_NERRNO(setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)));
if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0)
return -errno;
return 0;
default:
return -EAFNOSUPPORT;

View File

@ -66,7 +66,10 @@ int fsync_directory_of_file(int fd) {
return dfd;
}
return RET_NERRNO(fsync(dfd));
if (fsync(dfd) < 0)
return -errno;
return 0;
}
int fsync_full(int fd) {
@ -74,7 +77,7 @@ int fsync_full(int fd) {
/* Sync both the file and the directory */
r = RET_NERRNO(fsync(fd));
r = fsync(fd) < 0 ? -errno : 0;
q = fsync_directory_of_file(fd);
if (r < 0) /* Return earlier error */
@ -106,7 +109,10 @@ int fsync_path_at(int at_fd, const char *path) {
fd = opened_fd;
}
return RET_NERRNO(fsync(fd));
if (fsync(fd) < 0)
return -errno;
return 0;
}
int fsync_parent_at(int at_fd, const char *path) {
@ -120,7 +126,10 @@ int fsync_parent_at(int at_fd, const char *path) {
if (opened_fd < 0)
return -errno;
return RET_NERRNO(fsync(opened_fd));
if (fsync(opened_fd) < 0)
return -errno;
return 0;
}
opened_fd = openat(at_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
@ -151,7 +160,7 @@ int syncfs_path(int at_fd, const char *path) {
if (isempty(path)) {
if (at_fd != AT_FDCWD)
return RET_NERRNO(syncfs(at_fd));
return syncfs(at_fd) < 0 ? -errno : 0;
fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
} else
@ -159,5 +168,8 @@ int syncfs_path(int at_fd, const char *path) {
if (fd < 0)
return -errno;
return RET_NERRNO(syncfs(fd));
if (syncfs(fd) < 0)
return -errno;
return 0;
}

View File

@ -74,7 +74,10 @@ int chvt(int vt) {
vt = tiocl[0] <= 0 ? 1 : tiocl[0];
}
return RET_NERRNO(ioctl(fd, VT_ACTIVATE, vt));
if (ioctl(fd, VT_ACTIVATE, vt) < 0)
return -errno;
return 0;
}
int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
@ -406,7 +409,8 @@ int acquire_terminal(
assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
/* First, try to get the tty */
r = RET_NERRNO(ioctl(fd, TIOCSCTTY, (flags & ~ACQUIRE_TERMINAL_PERMISSIVE) == ACQUIRE_TERMINAL_FORCE));
r = ioctl(fd, TIOCSCTTY,
(flags & ~ACQUIRE_TERMINAL_PERMISSIVE) == ACQUIRE_TERMINAL_FORCE) < 0 ? -errno : 0;
/* Reset signal handler to old value */
assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
@ -496,7 +500,7 @@ int release_terminal(void) {
* by our own TIOCNOTTY */
assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
r = RET_NERRNO(ioctl(fd, TIOCNOTTY));
r = ioctl(fd, TIOCNOTTY) < 0 ? -errno : 0;
assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
@ -505,7 +509,11 @@ int release_terminal(void) {
int terminal_vhangup_fd(int fd) {
assert(fd >= 0);
return RET_NERRNO(ioctl(fd, TIOCVHANGUP));
if (ioctl(fd, TIOCVHANGUP) < 0)
return -errno;
return 0;
}
int terminal_vhangup(const char *name) {
@ -1353,7 +1361,10 @@ 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;
return RET_NERRNO(ioctl(fd, KDSKBMODE, kb));
if (ioctl(fd, KDSKBMODE, kb) < 0)
return -errno;
return 0;
}
int vt_restore(int fd) {

View File

@ -65,9 +65,16 @@ 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);
BLOCK_WITH_UMASK(0077);
return RET_NERRNO(mkostemp(pattern, O_CLOEXEC));
RUN_WITH_UMASK(0077)
fd = mkostemp(pattern, O_CLOEXEC);
if (fd < 0)
return -errno;
return fd;
}
int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
@ -276,6 +283,8 @@ 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);
@ -286,10 +295,16 @@ 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)
return rename_noreplace(AT_FDCWD, path, AT_FDCWD, target);
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;
}
return RET_NERRNO(linkat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), AT_FDCWD, target, AT_SYMLINK_FOLLOW));
return 0;
}
int mkdtemp_malloc(const char *template, char **ret) {

View File

@ -680,7 +680,10 @@ int reset_uid_gid(void) {
if (setresgid(0, 0, 0) < 0)
return -errno;
return RET_NERRNO(setresuid(0, 0, 0));
if (setresuid(0, 0, 0) < 0)
return -errno;
return 0;
}
int take_etc_passwd_lock(const char *root) {
@ -940,7 +943,10 @@ int maybe_setgroups(size_t size, const gid_t *list) {
}
}
return RET_NERRNO(setgroups(size, list));
if (setgroups(size, list) < 0)
return -errno;
return 0;
}
bool synthesize_nobody(void) {

View File

@ -8,7 +8,6 @@
#include <sys/xattr.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "macro.h"
#include "missing_syscall.h"
@ -203,7 +202,10 @@ int fd_setcrtime(int fd, usec_t usec) {
usec = now(CLOCK_REALTIME);
le = htole64((uint64_t) usec);
return RET_NERRNO(fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0));
if (fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0) < 0)
return -errno;
return 0;
}
int listxattr_at_malloc(

View File

@ -335,7 +335,10 @@ static int boot_entry_file_check(const char *root, const char *p) {
if (!path)
return log_oom();
return RET_NERRNO(access(path, F_OK));
if (access(path, F_OK) < 0)
return -errno;
return 0;
}
static void boot_entry_file_list(const char *field, const char *root, const char *p, int *ret_status) {

View File

@ -425,7 +425,10 @@ 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);
return RET_NERRNO(ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param));
if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
return -errno;
return 0;
}
static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, int status) {
@ -443,7 +446,10 @@ static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, in
} else
param.ready.token = token;
return RET_NERRNO(ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param));
if (ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param) < 0)
return -errno;
return 0;
}
static int automount_send_ready(Automount *a, Set *tokens, int status) {

View File

@ -306,7 +306,7 @@ static int connect_journal_socket(
}
}
r = RET_NERRNO(connect(fd, &sa.sa, sa_len));
r = connect(fd, &sa.sa, sa_len) < 0 ? -errno : 0;
/* 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 RET_NERRNO(dup2(socket_fd, STDIN_FILENO));
return dup2(socket_fd, STDIN_FILENO) < 0 ? -errno : STDIN_FILENO;
case EXEC_INPUT_NAMED_FD:
assert(named_iofds[STDIN_FILENO] >= 0);
(void) fd_nonblock(named_iofds[STDIN_FILENO], false);
return RET_NERRNO(dup2(named_iofds[STDIN_FILENO], STDIN_FILENO));
return dup2(named_iofds[STDIN_FILENO], STDIN_FILENO) < 0 ? -errno : 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 RET_NERRNO(dup2(STDOUT_FILENO, fileno));
return dup2(STDOUT_FILENO, fileno) < 0 ? -errno : 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 RET_NERRNO(dup2(STDIN_FILENO, fileno));
return dup2(STDIN_FILENO, fileno) < 0 ? -errno : 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 RET_NERRNO(dup2(STDIN_FILENO, fileno));
return dup2(STDIN_FILENO, fileno) < 0 ? -errno : 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 RET_NERRNO(dup2(socket_fd, fileno));
return dup2(socket_fd, fileno) < 0 ? -errno : fileno;
case EXEC_OUTPUT_NAMED_FD:
assert(named_iofds[fileno] >= 0);
(void) fd_nonblock(named_iofds[fileno], false);
return RET_NERRNO(dup2(named_iofds[fileno], fileno));
return dup2(named_iofds[fileno], fileno) < 0 ? -errno : 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 RET_NERRNO(dup2(STDIN_FILENO, fileno));
return dup2(STDIN_FILENO, fileno) < 0 ? -errno : 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 ?: strerror_safe(ENOMEM));
prefix, cmd ? cmd : strerror_safe(ENOMEM));
exec_status_dump(&c->exec_status, f, prefix2);
}

View File

@ -3224,7 +3224,10 @@ 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 */
return RET_NERRNO(setenv("SYSTEMD_UNIT_PATH", p, 1));
if (setenv("SYSTEMD_UNIT_PATH", p, 1) < 0)
return -errno;
return 0;
}
char *unit_dbus_path(Unit *u) {

View File

@ -185,7 +185,10 @@ static int block_get_size_by_fd(int fd, uint64_t *ret) {
if (!S_ISBLK(st.st_mode))
return -ENOTBLK;
return RET_NERRNO(ioctl(fd, BLKGETSIZE64, ret));
if (ioctl(fd, BLKGETSIZE64, ret) < 0)
return -errno;
return 0;
}
static int block_get_size_by_path(const char *path, uint64_t *ret) {
@ -1506,8 +1509,6 @@ int home_deactivate_luks(UserRecord *h, HomeSetup *setup) {
}
}
setup->undo_dm = false;
if (user_record_luks_offline_discard(h))
log_debug("Not allocating on logout.");
else

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 = RET_NERRNO(mkdir(d, 0755));
r = mkdir(d, 0755) < 0 ? -errno : 0;
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 = RET_NERRNO(mkdir(where, 0755));
r = mkdir(where, 0755) < 0 ? -errno : 0;
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

@ -84,30 +84,6 @@ int event_reset_time(
return created;
}
int event_reset_time_relative(
sd_event *e,
sd_event_source **s,
clockid_t clock,
uint64_t usec,
uint64_t accuracy,
sd_event_time_handler_t callback,
void *userdata,
int64_t priority,
const char *description,
bool force_reset) {
usec_t usec_now;
int r;
assert(e);
r = sd_event_now(e, clock, &usec_now);
if (r < 0)
return log_debug_errno(r, "sd-event: Failed to get the current time: %m");
return event_reset_time(e, s, clock, usec_add(usec_now, usec), accuracy, callback, userdata, priority, description, force_reset);
}
int event_source_disable(sd_event_source *s) {
if (!s)
return 0;

View File

@ -5,27 +5,9 @@
#include "sd-event.h"
int event_reset_time(
sd_event *e,
sd_event_source **s,
clockid_t clock,
uint64_t usec,
uint64_t accuracy,
sd_event_time_handler_t callback,
void *userdata,
int64_t priority,
const char *description,
bool force_reset);
int event_reset_time_relative(
sd_event *e,
sd_event_source **s,
clockid_t clock,
uint64_t usec,
uint64_t accuracy,
sd_event_time_handler_t callback,
void *userdata,
int64_t priority,
const char *description,
bool force_reset);
int event_reset_time(sd_event *e, sd_event_source **s,
clockid_t clock, uint64_t usec, uint64_t accuracy,
sd_event_time_handler_t callback, void *userdata,
int64_t priority, const char *description, bool force_reset);
int event_source_disable(sd_event_source *s);
int event_source_is_enabled(sd_event_source *s);

View File

@ -3793,7 +3793,10 @@ 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;
return RET_NERRNO(timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL));
if (timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL) < 0)
return -errno;
return 0;
}
static int process_watchdog(sd_event *e) {
@ -3903,7 +3906,7 @@ static int epoll_wait_usec(
int maxevents,
usec_t timeout) {
int msec;
int r, msec;
#if 0
static bool epoll_pwait2_absent = false;
@ -3943,7 +3946,14 @@ static int epoll_wait_usec(
msec = (int) k;
}
return RET_NERRNO(epoll_wait(fd, events, maxevents, msec));
r = epoll_wait(fd,
events,
maxevents,
msec);
if (r < 0)
return -errno;
return r;
}
static int process_epoll(sd_event *e, usec_t timeout, int64_t threshold, int64_t *ret_min_priority) {

View File

@ -57,7 +57,11 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) {
if (r < 0)
return r;
return RET_NERRNO(fcntl(fd, F_DUPFD_CLOEXEC, 3));
r = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (r < 0)
return -errno;
return r;
}
static int print_inhibitors(sd_bus *bus) {

View File

@ -9,7 +9,6 @@
#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"
@ -328,7 +327,11 @@ int inhibitor_create_fifo(Inhibitor *i) {
}
/* Open writing side */
return RET_NERRNO(open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK));
r = open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
if (r < 0)
return -errno;
return r;
}
static void inhibitor_remove_fifo(Inhibitor *i) {

View File

@ -105,12 +105,20 @@ static void sd_eviocrevoke(int fd) {
static int sd_drmsetmaster(int fd) {
assert(fd >= 0);
return RET_NERRNO(ioctl(fd, DRM_IOCTL_SET_MASTER, 0));
if (ioctl(fd, DRM_IOCTL_SET_MASTER, 0) < 0)
return -errno;
return 0;
}
static int sd_drmdropmaster(int fd) {
assert(fd >= 0);
return RET_NERRNO(ioctl(fd, DRM_IOCTL_DROP_MASTER, 0));
if (ioctl(fd, DRM_IOCTL_DROP_MASTER, 0) < 0)
return -errno;
return 0;
}
static int session_device_open(SessionDevice *sd, bool active) {

View File

@ -1097,7 +1097,11 @@ int session_create_fifo(Session *s) {
}
/* Open writing side */
return RET_NERRNO(open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK));
r = open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
if (r < 0)
return -errno;
return r;
}
static void session_remove_fifo(Session *s) {

View File

@ -575,8 +575,14 @@ 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 */
return RET_NERRNO(kill(m->leader, signo));
if (who == KILL_LEADER) {
/* If we shall simply kill the leader, do so directly */
if (kill(m->leader, signo) < 0)
return -errno;
return 0;
}
/* Otherwise, make PID 1 do it for us, for the entire cgroup */
return manager_kill_unit(m->manager, m->unit, signo, NULL);

View File

@ -21,7 +21,6 @@
#include "dhcp-lease-internal.h"
#include "env-file.h"
#include "ethtool-util.h"
#include "event-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
@ -245,7 +244,6 @@ static Link *link_free(Link *link) {
strv_free(link->alternative_names);
free(link->kind);
free(link->ssid);
free(link->previous_ssid);
free(link->driver);
unlink_and_free(link->lease_file);
@ -261,8 +259,6 @@ static Link *link_free(Link *link) {
network_unref(link->network);
sd_event_source_disable_unref(link->carrier_lost_timer);
return mfree(link);
}
@ -1585,34 +1581,10 @@ int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, voi
}
static int link_carrier_gained(Link *link) {
bool force_reconfigure;
int r;
assert(link);
r = event_source_disable(link->carrier_lost_timer);
if (r < 0)
log_link_warning_errno(link, r, "Failed to disable carrier lost timer, ignoring: %m");
/* If the SSID is changed, then the connected wireless network could be changed. So, always
* reconfigure the link. Which means e.g. the DHCP client will be restarted, and the correct
* network information will be gained.
* For non-wireless interfaces, we have no way to detect the connected network change. So,
* setting force_reconfigure = false. Note, both ssid and previous_ssid should be NULL for
* non-wireless interfaces, and streq_ptr() returns true. */
force_reconfigure = !streq_ptr(link->previous_ssid, link->ssid);
link->previous_ssid = mfree(link->previous_ssid);
if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) {
/* At this stage, both wlan and link information should be up-to-date. Hence,
* it is not necessary to call RTM_GETLINK, NL80211_CMD_GET_INTERFACE, or
* NL80211_CMD_GET_STATION commands, and simply call link_reconfigure_impl().
* Note, link_reconfigure_impl() returns 1 when the link is reconfigured. */
r = link_reconfigure_impl(link, force_reconfigure);
if (r != 0)
return r;
}
r = link_handle_bound_by_list(link);
if (r < 0)
return r;
@ -1634,45 +1606,6 @@ static int link_carrier_gained(Link *link) {
return 0;
}
static int link_carrier_lost_impl(Link *link) {
int r, ret = 0;
assert(link);
link->previous_ssid = mfree(link->previous_ssid);
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return 0;
if (!link->network)
return 0;
r = link_stop_engines(link, false);
if (r < 0)
ret = r;
r = link_drop_config(link);
if (r < 0 && ret >= 0)
ret = r;
return ret;
}
static int link_carrier_lost_handler(sd_event_source *s, uint64_t usec, void *userdata) {
Link *link = userdata;
int r;
assert(link);
r = link_carrier_lost_impl(link);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to process carrier lost event: %m");
link_enter_failed(link);
}
return 0;
}
static int link_carrier_lost(Link *link) {
int r;
@ -1689,22 +1622,16 @@ static int link_carrier_lost(Link *link) {
if (!link->network)
return 0;
if (link->network->ignore_carrier_loss_usec == USEC_INFINITY)
if (link->network->ignore_carrier_loss)
return 0;
if (link->network->ignore_carrier_loss_usec == 0)
return link_carrier_lost_impl(link);
r = link_stop_engines(link, false);
if (r < 0) {
link_enter_failed(link);
return r;
}
return event_reset_time_relative(link->manager->event,
&link->carrier_lost_timer,
clock_boottime_or_monotonic(),
link->network->ignore_carrier_loss_usec,
0,
link_carrier_lost_handler,
link,
0,
"link-carrier-loss",
true);
return link_drop_config(link);
}
static int link_admin_state_up(Link *link) {
@ -2031,6 +1958,15 @@ static int link_update_flags(Link *link, sd_netlink_message *message) {
if (!had_carrier && link_has_carrier(link)) {
log_link_info(link, "Gained carrier");
if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) {
/* At this stage, both wlan and link information should be up-to-date. Hence,
* it is not necessary to call RTM_GETLINK, NL80211_CMD_GET_INTERFACE, or
* NL80211_CMD_GET_STATION commands, and simply call link_reconfigure_impl(). */
r = link_reconfigure_impl(link, /* force = */ false);
if (r < 0)
return r;
}
r = link_carrier_gained(link);
if (r < 0)
return r;

View File

@ -67,14 +67,11 @@ typedef struct Link {
/* wlan */
enum nl80211_iftype wlan_iftype;
char *ssid;
char *previous_ssid;
struct ether_addr bssid;
unsigned flags;
uint8_t kernel_operstate;
sd_event_source *carrier_lost_timer;
Network *network;
LinkState state;

View File

@ -135,7 +135,7 @@ Network.ProxyARP, config_parse_tristate,
Network.IPv6ProxyNDPAddress, config_parse_ipv6_proxy_ndp_address, 0, 0
Network.BindCarrier, config_parse_strv, 0, offsetof(Network, bind_carrier)
Network.ConfigureWithoutCarrier, config_parse_bool, 0, offsetof(Network, configure_without_carrier)
Network.IgnoreCarrierLoss, config_parse_ignore_carrier_loss, 0, 0
Network.IgnoreCarrierLoss, config_parse_tristate, 0, offsetof(Network, ignore_carrier_loss)
Network.KeepConfiguration, config_parse_keep_configuration, 0, offsetof(Network, keep_configuration)
Network.IPv6SendRA, config_parse_router_prefix_delegation, 0, offsetof(Network, router_prefix_delegation)
Network.DHCPv6PrefixDelegation, config_parse_tristate, 0, offsetof(Network, dhcp6_pd)
@ -171,7 +171,6 @@ RoutingPolicyRule.DestinationPort, config_parse_routing_policy_rule_po
RoutingPolicyRule.InvertRule, config_parse_routing_policy_rule_invert, 0, 0
RoutingPolicyRule.Family, config_parse_routing_policy_rule_family, 0, 0
RoutingPolicyRule.User, config_parse_routing_policy_rule_uid_range, 0, 0
RoutingPolicyRule.SuppressInterfaceGroup, config_parse_routing_policy_rule_suppress_ifgroup, 0, 0
RoutingPolicyRule.SuppressPrefixLength, config_parse_routing_policy_rule_suppress_prefixlen, 0, 0
RoutingPolicyRule.Type, config_parse_routing_policy_rule_type, 0, 0
Route.Gateway, config_parse_gateway, 0, 0

View File

@ -271,17 +271,14 @@ int network_verify(Network *network) {
network->activation_policy = ACTIVATION_POLICY_UP;
if (network->activation_policy == ACTIVATION_POLICY_ALWAYS_UP) {
if (network->ignore_carrier_loss_set && network->ignore_carrier_loss_usec < USEC_INFINITY)
log_warning("%s: IgnoreCarrierLoss=no or finite timespan conflicts with ActivationPolicy=always-up. "
"Setting IgnoreCarrierLoss=yes.", network->filename);
network->ignore_carrier_loss_set = true;
network->ignore_carrier_loss_usec = USEC_INFINITY;
if (network->ignore_carrier_loss == false)
log_warning("%s: IgnoreCarrierLoss=false conflicts with ActivationPolicy=always-up. "
"Setting IgnoreCarrierLoss=true.", network->filename);
network->ignore_carrier_loss = true;
}
if (!network->ignore_carrier_loss_set) {
network->ignore_carrier_loss_set = true;
network->ignore_carrier_loss_usec = network->configure_without_carrier ? USEC_INFINITY : 0;
}
if (network->ignore_carrier_loss < 0)
network->ignore_carrier_loss = network->configure_without_carrier;
if (IN_SET(network->activation_policy, ACTIVATION_POLICY_DOWN, ACTIVATION_POLICY_ALWAYS_DOWN, ACTIVATION_POLICY_MANUAL)) {
if (network->required_for_online < 0 ||
@ -382,6 +379,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.allmulticast = -1,
.promiscuous = -1,
.ignore_carrier_loss = -1,
.keep_configuration = _KEEP_CONFIGURATION_INVALID,
.dhcp_duid.type = _DUID_TYPE_INVALID,
@ -1258,7 +1256,6 @@ int config_parse_link_group(
Network *network = userdata;
int r;
int32_t group;
assert(filename);
assert(lvalue);
@ -1266,69 +1263,19 @@ int config_parse_link_group(
assert(network);
if (isempty(rvalue)) {
network->group = -1;
network->group = 0;
network->group_set = false;
return 0;
}
r = safe_atoi32(rvalue, &group);
r = safe_atou32(rvalue, &network->group);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse Group=, ignoring assignment: %s", rvalue);
return 0;
}
if (group < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Value of Group= must be in the range 0…2147483647, ignoring assignment: %s", rvalue);
return 0;
}
network->group = group;
return 0;
}
int config_parse_ignore_carrier_loss(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Network *network = userdata;
usec_t usec;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(network);
if (isempty(rvalue)) {
network->ignore_carrier_loss_set = false;
return 0;
}
r = parse_boolean(rvalue);
if (r >= 0) {
network->ignore_carrier_loss_set = true;
network->ignore_carrier_loss_usec = r > 0 ? USEC_INFINITY : 0;
return 0;
}
r = parse_sec(rvalue, &usec);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
network->ignore_carrier_loss_set = true;
network->ignore_carrier_loss_usec = usec;
network->group_set = true;
return 0;
}

View File

@ -96,7 +96,8 @@ struct Network {
/* [Link] section */
struct ether_addr *mac;
uint32_t mtu;
int32_t group;
uint32_t group;
bool group_set;
int arp;
int multicast;
int allmulticast;
@ -109,8 +110,7 @@ struct Network {
/* misc settings */
bool configure_without_carrier;
bool ignore_carrier_loss_set;
usec_t ignore_carrier_loss_usec; /* timespan */
int ignore_carrier_loss;
KeepConfiguration keep_configuration;
char **bind_carrier;
bool default_route_on_device;
@ -384,7 +384,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);

View File

@ -65,7 +65,6 @@ static int routing_policy_rule_new(RoutingPolicyRule **ret) {
.uid_range.start = UID_INVALID,
.uid_range.end = UID_INVALID,
.suppress_prefixlen = -1,
.suppress_ifgroup = -1,
.protocol = RTPROT_UNSPEC,
.type = FR_ACT_TO_TBL,
};
@ -166,7 +165,6 @@ void routing_policy_rule_hash_func(const RoutingPolicyRule *rule, struct siphash
siphash24_compress(&rule->priority, sizeof(rule->priority), state);
siphash24_compress(&rule->table, sizeof(rule->table), state);
siphash24_compress(&rule->suppress_prefixlen, sizeof(rule->suppress_prefixlen), state);
siphash24_compress(&rule->suppress_ifgroup, sizeof(rule->suppress_ifgroup), state);
siphash24_compress(&rule->ipproto, sizeof(rule->ipproto), state);
siphash24_compress(&rule->protocol, sizeof(rule->protocol), state);
@ -242,10 +240,6 @@ int routing_policy_rule_compare_func(const RoutingPolicyRule *a, const RoutingPo
if (r != 0)
return r;
r = CMP(a->suppress_ifgroup, b->suppress_ifgroup);
if (r != 0)
return r;
r = CMP(a->ipproto, b->ipproto);
if (r != 0)
return r;
@ -540,12 +534,6 @@ static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule
return log_link_error_errno(link, r, "Could not append FRA_SUPPRESS_PREFIXLEN attribute: %m");
}
if (rule->suppress_ifgroup >= 0) {
r = sd_netlink_message_append_u32(m, FRA_SUPPRESS_IFGROUP, (uint32_t) rule->suppress_ifgroup);
if (r < 0)
return log_link_error_errno(link, r, "Could not append FRA_SUPPRESS_IFGROUP attribute: %m");
}
r = sd_rtnl_message_routing_policy_rule_set_fib_type(m, rule->type);
if (r < 0)
return log_link_error_errno(link, r, "Could not append FIB rule type attribute: %m");
@ -867,11 +855,11 @@ int request_process_routing_policy_rule(Request *req) {
}
static const RoutingPolicyRule kernel_rules[] = {
{ .family = AF_INET, .priority_set = true, .priority = 0, .table = RT_TABLE_LOCAL, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
{ .family = AF_INET, .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
{ .family = AF_INET, .priority_set = true, .priority = 32767, .table = RT_TABLE_DEFAULT, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
{ .family = AF_INET6, .priority_set = true, .priority = 0, .table = RT_TABLE_LOCAL, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
{ .family = AF_INET6, .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
{ .family = AF_INET, .priority_set = true, .priority = 0, .table = RT_TABLE_LOCAL, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, },
{ .family = AF_INET, .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, },
{ .family = AF_INET, .priority_set = true, .priority = 32767, .table = RT_TABLE_DEFAULT, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, },
{ .family = AF_INET6, .priority_set = true, .priority = 0, .table = RT_TABLE_LOCAL, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, },
{ .family = AF_INET6, .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN, .type = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, },
};
static bool routing_policy_rule_is_created_by_kernel(const RoutingPolicyRule *rule) {
@ -1061,28 +1049,8 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
log_warning_errno(r, "rtnl: could not get FRA_SUPPRESS_PREFIXLEN attribute, ignoring: %m");
return 0;
}
if (r >= 0) {
/* kernel does not limit this value, but we do. */
if (suppress_prefixlen > 128) {
log_warning("rtnl: received invalid FRA_SUPPRESS_PREFIXLEN attribute value %"PRIu32", ignoring.", suppress_prefixlen);
return 0;
}
tmp->suppress_prefixlen = (int32_t) suppress_prefixlen;
}
uint32_t suppress_ifgroup;
r = sd_netlink_message_read_u32(message, FRA_SUPPRESS_IFGROUP, &suppress_ifgroup);
if (r < 0 && r != -ENODATA) {
log_warning_errno(r, "rtnl: could not get FRA_SUPPRESS_IFGROUP attribute, ignoring: %m");
return 0;
}
if (r >= 0) {
if (suppress_ifgroup > INT32_MAX) {
log_warning("rtnl: received invalid FRA_SUPPRESS_IFGROUP attribute value %"PRIu32", ignoring.", suppress_ifgroup);
return 0;
}
tmp->suppress_ifgroup = (int32_t) suppress_ifgroup;
}
if (r >= 0)
tmp->suppress_prefixlen = (int) suppress_prefixlen;
if (adjust_protocol)
/* As .network files does not have setting to specify protocol, we can assume the
@ -1654,54 +1622,6 @@ int config_parse_routing_policy_rule_suppress_prefixlen(
return 0;
}
int config_parse_routing_policy_rule_suppress_ifgroup(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_(routing_policy_rule_free_or_set_invalidp) RoutingPolicyRule *n = NULL;
Network *network = userdata;
int32_t suppress_ifgroup;
int r;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
r = routing_policy_rule_new_static(network, filename, section_line, &n);
if (r < 0)
return log_oom();
if (isempty(rvalue)) {
n->suppress_ifgroup = -1;
return 0;
}
r = safe_atoi32(rvalue, &suppress_ifgroup);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse SuppressInterfaceGroup=, ignoring assignment: %s", rvalue);
return 0;
}
if (suppress_ifgroup < 0) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Value of SuppressInterfaceGroup= must be in the range 0…2147483647, ignoring assignment: %s", rvalue);
return 0;
}
n->suppress_ifgroup = suppress_ifgroup;
TAKE_PTR(n);
return 0;
}
int config_parse_routing_policy_rule_type(
const char *unit,
const char *filename,

View File

@ -51,7 +51,6 @@ typedef struct RoutingPolicyRule {
struct fib_rule_uid_range uid_range;
int suppress_prefixlen;
int32_t suppress_ifgroup;
} RoutingPolicyRule;
RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule);
@ -89,5 +88,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_invert);
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_family);
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_uid_range);
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_suppress_prefixlen);
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_suppress_ifgroup);
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_type);

View File

@ -458,7 +458,7 @@ static int link_configure(
break;
}
case SET_LINK_GROUP:
r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) link->network->group);
r = sd_netlink_message_append_u32(req, IFLA_GROUP, link->network->group);
if (r < 0)
return log_link_debug_errno(link, r, "Could not append IFLA_GROUP attribute: %m");
break;
@ -770,7 +770,7 @@ int link_request_to_set_group(Link *link) {
assert(link);
assert(link->network);
if (link->network->group < 0)
if (!link->network->group_set)
return 0;
return link_request_set_link(link, SET_LINK_GROUP, link_set_group_handler, NULL);

View File

@ -273,7 +273,7 @@ int manager_genl_process_nl80211_mlme(sd_netlink *genl, sd_netlink_message *mess
strna(nl80211_cmd_to_string(cmd)), cmd);
link->bssid = ETHER_ADDR_NULL;
free_and_replace(link->previous_ssid, link->ssid);
link->ssid = mfree(link->ssid);
break;
default:

View File

@ -1879,7 +1879,10 @@ int userns_lchown(const char *p, uid_t uid, gid_t gid) {
return -EOVERFLOW;
}
return RET_NERRNO(lchown(p, uid, gid));
if (lchown(p, uid, gid) < 0)
return -errno;
return 0;
}
int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid_t gid) {

View File

@ -19,7 +19,6 @@
#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"
@ -1078,7 +1077,7 @@ static int verify_fsroot_dir(
if (!parent)
return log_oom();
r = RET_NERRNO(stat(parent, &st2));
r = stat(parent, &st2) < 0 ? -errno : 0;
}
if (r < 0)

View File

@ -7,7 +7,6 @@
#include "alloc-util.h"
#include "bpf-program.h"
#include "errno-util.h"
#include "escape.h"
#include "fd-util.h"
#include "memory-util.h"
@ -75,7 +74,10 @@ 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);
return RET_NERRNO(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)));
if (bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) < 0)
return -errno;
return 0;
}
int bpf_program_new(uint32_t prog_type, BPFProgram **ret) {
@ -288,6 +290,7 @@ 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;
@ -296,7 +299,11 @@ 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;
return RET_NERRNO(bpf(BPF_MAP_CREATE, &attr, sizeof(attr)));
fd = bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
if (fd < 0)
return -errno;
return fd;
}
int bpf_map_update_element(int fd, const void *key, void *value) {
@ -307,7 +314,10 @@ int bpf_map_update_element(int fd, const void *key, void *value) {
attr.key = PTR_TO_UINT64(key);
attr.value = PTR_TO_UINT64(value);
return RET_NERRNO(bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)));
if (bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)) < 0)
return -errno;
return 0;
}
int bpf_map_lookup_element(int fd, const void *key, void *value) {
@ -318,7 +328,10 @@ int bpf_map_lookup_element(int fd, const void *key, void *value) {
attr.key = PTR_TO_UINT64(key);
attr.value = PTR_TO_UINT64(value);
return RET_NERRNO(bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)));
if (bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)) < 0)
return -errno;
return 0;
}
int bpf_program_pin(int prog_fd, const char *bpffs_path) {
@ -328,7 +341,10 @@ int bpf_program_pin(int prog_fd, const char *bpffs_path) {
attr.pathname = PTR_TO_UINT64((void *) bpffs_path);
attr.bpf_fd = prog_fd;
return RET_NERRNO(bpf(BPF_OBJ_PIN, &attr, sizeof(attr)));
if (bpf(BPF_OBJ_PIN, &attr, sizeof(attr)) < 0)
return -errno;
return 0;
}
int bpf_program_get_id_by_fd(int prog_fd, uint32_t *ret_id) {

View File

@ -124,7 +124,10 @@ int btrfs_subvol_make_fd(int fd, const char *subvolume) {
strncpy(args.name, subvolume, sizeof(args.name)-1);
return RET_NERRNO(ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args));
if (ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args) < 0)
return -errno;
return 0;
}
int btrfs_subvol_make(const char *path) {
@ -189,7 +192,10 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
if (flags == nflags)
return 0;
return RET_NERRNO(ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &nflags));
if (ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &nflags) < 0)
return -errno;
return 0;
}
int btrfs_subvol_set_read_only(const char *path, bool b) {
@ -232,7 +238,10 @@ int btrfs_reflink(int infd, int outfd) {
if (r < 0)
return r;
return RET_NERRNO(ioctl(outfd, BTRFS_IOC_CLONE, infd));
if (ioctl(outfd, BTRFS_IOC_CLONE, infd) < 0)
return -errno;
return 0;
}
int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offset, uint64_t sz) {
@ -252,7 +261,10 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offs
if (r < 0)
return r;
return RET_NERRNO(ioctl(outfd, BTRFS_IOC_CLONE_RANGE, &args));
if (ioctl(outfd, BTRFS_IOC_CLONE_RANGE, &args) < 0)
return -errno;
return 0;
}
int btrfs_get_block_device_fd(int fd, dev_t *dev) {
@ -763,7 +775,10 @@ int btrfs_quota_enable_fd(int fd, bool b) {
if (!r)
return -ENOTTY;
return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args));
if (ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args) < 0)
return -errno;
return 0;
}
int btrfs_quota_enable(const char *path, bool b) {
@ -967,13 +982,19 @@ int btrfs_quota_scan_start(int fd) {
assert(fd >= 0);
return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args));
if (ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args) < 0)
return -errno;
return 0;
}
int btrfs_quota_scan_wait(int fd) {
assert(fd >= 0);
return RET_NERRNO(ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT));
if (ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT) < 0)
return -errno;
return 0;
}
int btrfs_quota_scan_ongoing(int fd) {

View File

@ -48,7 +48,10 @@ int clock_set_hwclock(const struct tm *tm) {
if (fd < 0)
return -errno;
return RET_NERRNO(ioctl(fd, RTC_SET_TIME, tm));
if (ioctl(fd, RTC_SET_TIME, tm) < 0)
return -errno;
return 0;
}
int clock_is_localtime(const char* adjtime_path) {
@ -128,7 +131,10 @@ 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. */
return RET_NERRNO(settimeofday(NULL, &tz));
if (settimeofday(NULL, &tz) < 0)
return -errno;
return 0;
}
#define EPOCH_FILE "/usr/lib/clock-epoch"

View File

@ -1380,7 +1380,10 @@ int copy_access(int fdf, int fdt) {
if (fstat(fdf, &st) < 0)
return -errno;
return RET_NERRNO(fchmod(fdt, st.st_mode & 07777));
if (fchmod(fdt, st.st_mode & 07777) < 0)
return -errno;
return 0;
}
int copy_rights_with_fallback(int fdf, int fdt, const char *patht) {

View File

@ -49,9 +49,14 @@ 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 */
return RET_NERRNO(open("/dev/null", O_RDONLY|O_CLOEXEC|O_NOCTTY));
r = open("/dev/null", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (r < 0)
return -errno;
return r;
}
if ((flags & ACQUIRE_NO_MEMFD) == 0) {
fd = memfd_new("data-fd");

View File

@ -462,8 +462,10 @@ int ethtool_set_wol(
return 0;
}
r = 0;
ecmd.cmd = ETHTOOL_SWOL;
r = RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
r = -errno;
explicit_bzero_safe(&ecmd, sizeof(ecmd));
return r;
@ -514,7 +516,10 @@ int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netde
return 0;
ecmd.cmd = ETHTOOL_SRINGPARAM;
return RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
return -errno;
return 0;
}
static int get_stringset(int ethtool_fd, const char *ifname, enum ethtool_stringset stringset_id, struct ethtool_gstrings **ret) {
@ -873,7 +878,10 @@ static int set_slinksettings(int fd, struct ifreq *ifr, const struct ethtool_lin
ifr->ifr_data = (void *) &ecmd;
return RET_NERRNO(ioctl(fd, SIOCETHTOOL, ifr));
if (ioctl(fd, SIOCETHTOOL, ifr) < 0)
return -errno;
return 0;
}
static int set_sset(int fd, struct ifreq *ifr, const struct ethtool_link_usettings *u) {
@ -904,7 +912,10 @@ static int set_sset(int fd, struct ifreq *ifr, const struct ethtool_link_usettin
ifr->ifr_data = (void *) &ecmd;
return RET_NERRNO(ioctl(fd, SIOCETHTOOL, ifr));
if (ioctl(fd, SIOCETHTOOL, ifr) < 0)
return -errno;
return 0;
}
int ethtool_set_glinksettings(
@ -1042,7 +1053,10 @@ int ethtool_set_channels(int *fd, const char *ifname, const netdev_channels *cha
return 0;
ecmd.cmd = ETHTOOL_SCHANNELS;
return RET_NERRNO(ioctl(*fd, SIOCETHTOOL, &ifr));
if (ioctl(*fd, SIOCETHTOOL, &ifr) < 0)
return -errno;
return 0;
}
int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg) {
@ -1083,7 +1097,10 @@ int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int au
return 0;
ecmd.cmd = ETHTOOL_SPAUSEPARAM;
return RET_NERRNO(ioctl(*fd, SIOCETHTOOL, &ifr));
if (ioctl(*fd, SIOCETHTOOL, &ifr) < 0)
return -errno;
return 0;
}
int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce) {
@ -1203,7 +1220,10 @@ int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const
return 0;
ecmd.cmd = ETHTOOL_SCOALESCE;
return RET_NERRNO(ioctl(*ethtool_fd, SIOCETHTOOL, &ifr));
if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
return -errno;
return 0;
}
int config_parse_advertise(

View File

@ -35,7 +35,9 @@ int symlink_label(const char *old_path, const char *new_path) {
if (r < 0)
return r;
r = RET_NERRNO(symlink(old_path, new_path));
if (symlink(old_path, new_path) < 0)
r = -errno;
mac_selinux_create_file_clear();
if (r < 0)
@ -54,7 +56,9 @@ int symlink_atomic_label(const char *from, const char *to) {
if (r < 0)
return r;
r = symlink_atomic(from, to);
if (symlink_atomic(from, to) < 0)
r = -errno;
mac_selinux_create_file_clear();
if (r < 0)
@ -72,7 +76,9 @@ int mknod_label(const char *pathname, mode_t mode, dev_t dev) {
if (r < 0)
return r;
r = RET_NERRNO(mknod(pathname, mode, dev));
if (mknod(pathname, mode, dev) < 0)
r = -errno;
mac_selinux_create_file_clear();
if (r < 0)

View File

@ -887,7 +887,10 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) {
.datalen = sizeof(bp),
};
return RET_NERRNO(ioctl(whole_fd, BLKPG, &ba));
if (ioctl(whole_fd, BLKPG, &ba) < 0)
return -errno;
return 0;
}
int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
@ -924,7 +927,10 @@ int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) {
if (offset != UINT64_MAX)
info.lo_offset = offset;
return RET_NERRNO(ioctl(d->fd, LOOP_SET_STATUS64, &info));
if (ioctl(d->fd, LOOP_SET_STATUS64, &info) < 0)
return -errno;
return 0;
}
int loop_device_flock(LoopDevice *d, int operation) {
@ -933,7 +939,10 @@ int loop_device_flock(LoopDevice *d, int operation) {
if (d->fd < 0)
return -EBADF;
return RET_NERRNO(flock(d->fd, operation));
if (flock(d->fd, operation) < 0)
return -errno;
return 0;
}
int loop_device_sync(LoopDevice *d) {
@ -945,5 +954,8 @@ int loop_device_sync(LoopDevice *d) {
if (d->fd < 0)
return -EBADF;
return RET_NERRNO(fsync(d->fd));
if (fsync(d->fd) < 0)
return -errno;
return 0;
}

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 = RET_NERRNO(mount(p->what, p->where, p->type, p->flags, p->options));
r = mount(p->what, p->where, p->type, p->flags, p->options) < 0 ? -errno : 0;
else
r = mount_nofollow(p->what, p->where, p->type, p->flags, p->options);
if (r < 0) {

View File

@ -484,7 +484,10 @@ int mount_move_root(const char *path) {
if (chroot(".") < 0)
return -errno;
return RET_NERRNO(chdir("/"));
if (chdir("/") < 0)
return -errno;
return 0;
}
int repeat_unmount(const char *path, int flags) {
@ -680,7 +683,7 @@ int mount_verbose_full(
strna(what), strna(type), where, strnull(fl), strempty(o));
if (follow_symlink)
r = RET_NERRNO(mount(what, where, type, f, o));
r = mount(what, where, type, f, o) < 0 ? -errno : 0;
else
r = mount_nofollow(what, where, type, f, o);
if (r < 0)

View File

@ -376,7 +376,11 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
if (sclass == 0)
return -ENOSYS;
return RET_NERRNO(security_compute_create_raw(mycon, fcon, sclass, label));
r = security_compute_create_raw(mycon, fcon, sclass, label);
if (r < 0)
return -errno;
return 0;
#else
return -EOPNOTSUPP;
#endif
@ -384,12 +388,18 @@ 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;
return RET_NERRNO(getcon_raw(label));
r = getcon_raw(label);
if (r < 0)
return -errno;
return 0;
#else
return -EOPNOTSUPP;
#endif
@ -451,7 +461,11 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
if (sclass == 0)
return -ENOSYS;
return RET_NERRNO(security_compute_create_raw(mycon, fcon, sclass, label));
r = security_compute_create_raw(mycon, fcon, sclass, label);
if (r < 0)
return -errno;
return 0;
#else
return -EOPNOTSUPP;
#endif
@ -670,7 +684,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
context_changed = true;
}
r = RET_NERRNO(bind(fd, addr, addrlen));
r = bind(fd, addr, addrlen) < 0 ? -errno : 0;
if (context_changed)
(void) setfscreatecon_raw(NULL);
@ -679,5 +693,8 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
skipped:
#endif
return RET_NERRNO(bind(fd, addr, addrlen));
if (bind(fd, addr, addrlen) < 0)
return -errno;
return 0;
}

View File

@ -51,13 +51,14 @@ int socket_address_listen(
return r;
}
fd = RET_NERRNO(socket(socket_address_family(a), a->type | flags, a->protocol));
fd = socket(socket_address_family(a), a->type | flags, a->protocol);
r = fd < 0 ? -errno : 0;
if (label)
mac_selinux_create_socket_clear();
if (fd < 0)
return fd;
if (r < 0)
return r;
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);
return RET_NERRNO(ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
if (ioctl(fd, DM_DEV_REMOVE, &(struct dm_ioctl) {
.version = {
DM_VERSION_MAJOR,
DM_VERSION_MINOR,
@ -480,7 +480,10 @@ 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) {
@ -497,7 +500,10 @@ 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);
return RET_NERRNO(ioctl(fd, STOP_ARRAY, NULL));
if (ioctl(fd, STOP_ARRAY, NULL) < 0)
return -errno;
return 0;
}
static bool nonunmountable_path(const char *path) {

View File

@ -958,7 +958,10 @@ static int root_stat(const char *p, struct stat *st) {
const char *fix;
fix = prefix_roota(arg_root, p);
return RET_NERRNO(stat(fix, st));
if (stat(fix, st) < 0)
return -errno;
return 0;
}
static int read_id_from_file(Item *i, uid_t *_uid, gid_t *_gid) {

View File

@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <float.h>
#include <math.h>
#include "alloc-util.h"
@ -522,58 +521,6 @@ static void test_bisect(void) {
}
}
static void test_float_match(JsonVariant *v) {
const long double delta = 0.0001;
assert_se(json_variant_is_array(v));
assert_se(json_variant_elements(v) == 9);
assert_se(fabsl((long double) 1.0 - ((long double) DBL_MIN / json_variant_real(json_variant_by_index(v, 0)))) <= delta);
assert_se(fabsl((long double) 1.0 - ((long double) DBL_MAX / json_variant_real(json_variant_by_index(v, 1)))) <= delta);
assert_se(json_variant_is_null(json_variant_by_index(v, 2))); /* nan is not supported by json → null */
assert_se(json_variant_is_null(json_variant_by_index(v, 3))); /* +inf is not supported by json → null */
assert_se(json_variant_is_null(json_variant_by_index(v, 4))); /* -inf is not supported by json → null */
assert_se(json_variant_is_null(json_variant_by_index(v, 5)) ||
fabsl((long double) 1.0 - ((long double) HUGE_VAL / json_variant_real(json_variant_by_index(v, 5)))) <= delta); /* HUGE_VAL might be +inf, but might also be something else */
assert_se(json_variant_is_real(json_variant_by_index(v, 6)) &&
json_variant_is_integer(json_variant_by_index(v, 6)) &&
json_variant_integer(json_variant_by_index(v, 6)) == 0);
assert_se(json_variant_is_real(json_variant_by_index(v, 7)) &&
json_variant_is_integer(json_variant_by_index(v, 7)) &&
json_variant_integer(json_variant_by_index(v, 7)) == 10);
assert_se(json_variant_is_real(json_variant_by_index(v, 8)) &&
json_variant_is_integer(json_variant_by_index(v, 8)) &&
json_variant_integer(json_variant_by_index(v, 8)) == -10);
}
static void test_float(void) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
_cleanup_free_ char *text = NULL;
log_info("/* %s */", __func__);
assert_se(json_build(&v, JSON_BUILD_ARRAY(
JSON_BUILD_REAL(DBL_MIN),
JSON_BUILD_REAL(DBL_MAX),
JSON_BUILD_REAL(NAN),
JSON_BUILD_REAL(INFINITY),
JSON_BUILD_REAL(-INFINITY),
JSON_BUILD_REAL(HUGE_VAL),
JSON_BUILD_REAL(0),
JSON_BUILD_REAL(10),
JSON_BUILD_REAL(-10))) >= 0);
json_variant_dump(v, JSON_FORMAT_COLOR|JSON_FORMAT_PRETTY, NULL, NULL);
test_float_match(v);
assert_se(json_variant_format(v, 0, &text) >= 0);
assert_se(json_parse(text, 0, &w, NULL, NULL) >= 0);
json_variant_dump(w, JSON_FORMAT_COLOR|JSON_FORMAT_PRETTY, NULL, NULL);
test_float_match(w);
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
@ -626,7 +573,6 @@ int main(int argc, char *argv[]) {
test_normalize();
test_bisect();
test_float();
return 0;
}

View File

@ -2160,17 +2160,18 @@ 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 = RET_NERRNO(openat(parent_fd, t, O_NOCTTY | O_CLOEXEC | O_DIRECTORY));
next_fd = 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(next_fd, "Failed to open \"%s\" at \"%s\": %m", t, strnull(parent_name));
return log_error_errno(r, "Failed to open \"%s\" at \"%s\": %m", t, strnull(parent_name));
}
r = RET_NERRNO(fstat(next_fd, &parent_st));
if (r < 0) {
if (fstat(next_fd, &parent_st) < 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));
}
@ -2308,7 +2309,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 = RET_NERRNO(symlink(i->argument, i->path));
r = symlink(i->argument, i->path) < 0 ? -errno : 0;
mac_selinux_create_file_clear();
}
if (r < 0)

View File

@ -53,7 +53,10 @@ static int create_symlink(const char *target, const char *slink) {
return r;
mac_selinux_create_file_prepare(slink, S_IFLNK);
r = RET_NERRNO(symlink(target, slink));
if (symlink(target, slink) < 0)
r = -errno;
else
r = 0;
mac_selinux_create_file_clear();
if (r != -ENOENT)
return r;

View File

@ -528,7 +528,11 @@ static int run(int argc, char *argv[]) {
}
(void) rename_process("systemd-userwork: waiting...");
fd = RET_NERRNO(accept4(listen_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC));
fd = accept4(listen_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (fd < 0)
fd = -errno;
(void) rename_process("systemd-userwork: processing...");
if (fd == -EAGAIN)

View File

@ -20,7 +20,6 @@
#include "alloc-util.h"
#include "env-file.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "io-util.h"
@ -41,7 +40,13 @@ static int verify_vc_device(int fd) {
TIOCL_GETFGCONSOLE,
};
return RET_NERRNO(ioctl(fd, TIOCLINUX, data));
int r;
r = ioctl(fd, TIOCLINUX, data);
if (r < 0)
return -errno;
return r;
}
static int verify_vc_allocation(unsigned idx) {
@ -49,7 +54,10 @@ static int verify_vc_allocation(unsigned idx) {
xsprintf(vcname, "/dev/vcs%u", idx);
return RET_NERRNO(access(vcname, F_OK));
if (access(vcname, F_OK) < 0)
return -errno;
return 0;
}
static int verify_vc_allocation_byfd(int fd) {

View File

@ -315,7 +315,6 @@ IPProtocol=
InvertRule=
Family=
SuppressPrefixLength=
SuppressInterfaceGroup=
User=
Type=
[IPv6SendRA]

View File

@ -561,7 +561,6 @@ Scope=
SendHostname=
Source=
SuppressPrefixLength=
SuppressInterfaceGroup=
TCP6SegmentationOffload=
TCPSegmentationOffload=
TOS=

View File

@ -16,7 +16,7 @@ After=home.mount
[Service]
BusName=org.freedesktop.home1
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER CAP_FSETID CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE CAP_SETPCAP CAP_DAC_READ_SEARCH CAP_SETFCAP
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER CAP_FSETID CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE CAP_SETPCAP CAP_DAC_READ_SEARCH
DeviceAllow=/dev/loop-control rw
DeviceAllow=/dev/mapper/control rw
DeviceAllow=block-* rw
@ -28,7 +28,7 @@ LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_ALG AF_INET AF_INET6
RestrictNamespaces=mnt user
RestrictNamespaces=mnt
RestrictRealtime=yes
StateDirectory=systemd/home
SystemCallArchitectures=native