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

Compare commits

..

16 Commits

Author SHA1 Message Date
Lennart Poettering
947796eac3 docs: mention RET_NERRNO() in CODING_STYLE.md 2021-11-16 08:04:09 +01:00
Lennart Poettering
7c248223eb tree-wide: use new RET_NERRNO() helper at various places 2021-11-16 08:04:09 +01:00
Lennart Poettering
ef470ffa23 macro: add new helper RET_NERRNO()
This new helper converts libc style syscall return values into
systemd-kernel (actually: kernel style) negative errno values.

It's implemented as macro-like inline function, and propagates return
values >= 0 as themselves and returns -errno for negative error returns.

THis is supposed to be little more than syntactic sugar so that we can
reduce a lot of (short, but still) boilerplate code whever we convert
libc style error handling into our own.

As discussed here:

https://github.com/systemd/systemd/pull/21326#discussion_r748413537
2021-11-16 08:04:09 +01:00
Lennart Poettering
cb3763d57b cgroup-util: laccess() returns negative errno already 2021-11-16 08:04:09 +01:00
Lennart Poettering
12a9f68f06 units: relax sandbox so that uidmap stuff can work
The uidmap suff requires additional caps and userns to work in some
cases. Allow it.

Follow-up for: 1147c538bbb6a2d3d5ba2e40f1437bcbeb22b33e
2021-11-16 10:41:36 +09:00
Lennart Poettering
228b1decc6 homed: reset HomeSetup.undo_dm field when deactivating home dir the official way
There are two ways to deactivate a home dir: the official way if someone
calls "homectl deactivate" or something similar. Or the
error-case/side-effect code path, where we unwind exactly what we
already set up.

The .undo_dm field is supposed to tell us whether we shall still detach
the DM device. We forgot to update it in the official code path. Add
that. (We did it correctly in the error case codepath already).

(The issue is minor: if we forget to reset it in the clean code path,
then we'll try to unmount again what is already unmounted in the error
code paths, but since we ignore errors there — to not "stack" errors –
we never noticed and there's no bad effect of it)
2021-11-16 10:35:09 +09:00
Yu Watanabe
50e67237a7
Merge pull request #21377 from poettering/slow-math
meson: stop using -ffast-math
2021-11-16 10:33:48 +09:00
Yu Watanabe
7777024dab
Merge pull request #21344 from yuwata/network-ignore-carrier-loss-timespan
network: make IgnoreCarrierLoss= also take a timespan
2021-11-16 10:27:01 +09:00
Yu Watanabe
d068f3a243
Merge pull request #21235 from bacher09/slava/supress_ifgroup
Add suppress_ifgroup option in routing policy
2021-11-16 10:25:33 +09:00
Lennart Poettering
c79aaff9d5 test-json: add test that makes sure floats are somewhat reasonably implemented
Test that we don't loose accuracy without bounds for extreme values, and
validate that nan/inf/-inf actually get converted to null properly.
2021-11-15 22:24:49 +01:00
Lennart Poettering
394ac84df9 meson: drop -ffast-math
After reading https://simonbyrne.github.io/notes/fastmath/ I think we
should drop -ffast-math. The JSON code actually looks for NaN, so the
fact it becomes unreliable kinda sucks.

Moreover, we don't do any number crunching. We use floating point fields
only sporadical for trivial math. Hence the optimization is entirely
unnecessary.
2021-11-15 22:24:33 +01:00
Yu Watanabe
6706ce2fd2 network: make IgnoreCarrierLoss= also take timespan
Fixes #18738 and #20887.

Replaces #18746.
2021-11-16 02:04:59 +09:00
Slava Bacherikov
af493fb742 network: Add SuppressInterfaceGroup= into routing policy
This adds SuppressInterfaceGroup= option in the [RoutingPolicyRule] section
which has the same semantics as suppress_ifgroup in `ip rule` command.
2021-11-16 01:54:07 +09:00
Slava Bacherikov
10af8bb24b network: change link group type to int32
Both linux kernel kernel and iproute2 uses int32 type for a link group
attribute and -1 has a special meaning, so setting it to 4294967295
would make it -1 in the linux kernel (and ip link cmd).
2021-11-16 01:53:46 +09:00
Yu Watanabe
b7ac128430 network: do not recall link_handle_bound_by_list() or so when the interface is reconfigured 2021-11-14 11:52:49 +09:00
Yu Watanabe
52c3bc708f event-util: introduce event_reset_time_relative() 2021-11-14 10:32:06 +09:00
70 changed files with 566 additions and 528 deletions

View File

@ -285,6 +285,25 @@ 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…4294967295. Defaults to unset.
performed at once. Takes an unsigned integer in the range 0…2147483647. Defaults to unset.
</para>
</listitem>
</varlistentry>
@ -952,18 +952,21 @@ 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 <option>IgnoreCarrierLoss=</option> is not explicitly set, it will
default to this value.
Defaults to false. If enabled, and the <varname>IgnoreCarrierLoss=</varname> setting is not
explicitly set, then it is enabled as well.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>IgnoreCarrierLoss=</varname></term>
<listitem>
<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>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>When <varname>ActivationPolicy=</varname> is set to <literal>always-up</literal>, this
is forced to <literal>true</literal>.
@ -1282,6 +1285,14 @@ 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>
@ -1805,6 +1816,9 @@ 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,7 +409,6 @@ 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,10 +587,7 @@ 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);
if (laccess(cpath, root ? W_OK : F_OK) < 0)
return -errno;
return 0;
return laccess(cpath, root ? W_OK : F_OK);
}
int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) {
@ -632,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) {
@ -700,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

@ -31,6 +31,29 @@ 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,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) {
@ -1509,6 +1506,8 @@ 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 = 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

@ -84,6 +84,30 @@ 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,9 +5,27 @@
#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(
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_source_disable(sd_event_source *s);
int event_source_is_enabled(sd_event_source *s);

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

@ -21,6 +21,7 @@
#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"
@ -244,6 +245,7 @@ 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);
@ -259,6 +261,8 @@ static Link *link_free(Link *link) {
network_unref(link->network);
sd_event_source_disable_unref(link->carrier_lost_timer);
return mfree(link);
}
@ -1581,10 +1585,34 @@ 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;
@ -1606,6 +1634,45 @@ 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;
@ -1622,16 +1689,22 @@ static int link_carrier_lost(Link *link) {
if (!link->network)
return 0;
if (link->network->ignore_carrier_loss)
if (link->network->ignore_carrier_loss_usec == USEC_INFINITY)
return 0;
r = link_stop_engines(link, false);
if (r < 0) {
link_enter_failed(link);
return r;
}
if (link->network->ignore_carrier_loss_usec == 0)
return link_carrier_lost_impl(link);
return link_drop_config(link);
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);
}
static int link_admin_state_up(Link *link) {
@ -1958,15 +2031,6 @@ 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,11 +67,14 @@ 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_tristate, 0, offsetof(Network, ignore_carrier_loss)
Network.IgnoreCarrierLoss, config_parse_ignore_carrier_loss, 0, 0
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,6 +171,7 @@ 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,14 +271,17 @@ int network_verify(Network *network) {
network->activation_policy = ACTIVATION_POLICY_UP;
if (network->activation_policy == ACTIVATION_POLICY_ALWAYS_UP) {
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_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 < 0)
network->ignore_carrier_loss = network->configure_without_carrier;
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 (IN_SET(network->activation_policy, ACTIVATION_POLICY_DOWN, ACTIVATION_POLICY_ALWAYS_DOWN, ACTIVATION_POLICY_MANUAL)) {
if (network->required_for_online < 0 ||
@ -379,7 +382,6 @@ 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,
@ -1256,6 +1258,7 @@ int config_parse_link_group(
Network *network = userdata;
int r;
int32_t group;
assert(filename);
assert(lvalue);
@ -1263,19 +1266,69 @@ int config_parse_link_group(
assert(network);
if (isempty(rvalue)) {
network->group = 0;
network->group_set = false;
network->group = -1;
return 0;
}
r = safe_atou32(rvalue, &network->group);
r = safe_atoi32(rvalue, &group);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse Group=, ignoring assignment: %s", rvalue);
return 0;
}
network->group_set = true;
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;
return 0;
}

View File

@ -96,8 +96,7 @@ struct Network {
/* [Link] section */
struct ether_addr *mac;
uint32_t mtu;
uint32_t group;
bool group_set;
int32_t group;
int arp;
int multicast;
int allmulticast;
@ -110,7 +109,8 @@ struct Network {
/* misc settings */
bool configure_without_carrier;
int ignore_carrier_loss;
bool ignore_carrier_loss_set;
usec_t ignore_carrier_loss_usec; /* timespan */
KeepConfiguration keep_configuration;
char **bind_carrier;
bool default_route_on_device;
@ -384,6 +384,7 @@ 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,6 +65,7 @@ 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,
};
@ -165,6 +166,7 @@ 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);
@ -240,6 +242,10 @@ 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;
@ -534,6 +540,12 @@ 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");
@ -855,11 +867,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, },
{ .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, },
{ .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, },
};
static bool routing_policy_rule_is_created_by_kernel(const RoutingPolicyRule *rule) {
@ -1049,8 +1061,28 @@ 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)
tmp->suppress_prefixlen = (int) suppress_prefixlen;
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 (adjust_protocol)
/* As .network files does not have setting to specify protocol, we can assume the
@ -1622,6 +1654,54 @@ 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,6 +51,7 @@ 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);
@ -88,4 +89,5 @@ 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, link->network->group);
r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) 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_set)
if (link->network->group < 0)
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;
link->ssid = mfree(link->ssid);
free_and_replace(link->previous_ssid, link->ssid);
break;
default:

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

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <float.h>
#include <math.h>
#include "alloc-util.h"
@ -521,6 +522,58 @@ 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);
@ -573,6 +626,7 @@ int main(int argc, char *argv[]) {
test_normalize();
test_bisect();
test_float();
return 0;
}

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

View File

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

View File

@ -561,6 +561,7 @@ 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
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
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
RestrictNamespaces=mnt user
RestrictRealtime=yes
StateDirectory=systemd/home
SystemCallArchitectures=native