summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coccinelle/synthetic-errno.cocci35
-rw-r--r--src/ac-power/ac-power.c8
-rw-r--r--src/activate/activate.c39
-rw-r--r--src/analyze/analyze.c43
-rw-r--r--src/ask-password/ask-password.c8
-rw-r--r--src/basic/cgroup-util.c9
-rw-r--r--src/basic/fileio.c10
-rw-r--r--src/basic/log.h4
-rw-r--r--src/basic/process-util.c3
-rw-r--r--src/basic/rm-rf.c16
-rw-r--r--src/binfmt/binfmt.c14
-rw-r--r--src/boot/bless-boot.c54
-rw-r--r--src/boot/bootctl.c41
-rw-r--r--src/busctl/busctl-introspect.c297
-rw-r--r--src/busctl/busctl.c37
-rw-r--r--src/cgls/cgls.c7
-rw-r--r--src/cgtop/cgtop.c31
-rw-r--r--src/core/dbus.c7
-rw-r--r--src/core/job.c8
-rw-r--r--src/core/machine-id-setup.c8
-rw-r--r--src/core/main.c61
-rw-r--r--src/core/namespace.c38
-rw-r--r--src/core/path.c7
-rw-r--r--src/core/shutdown.c7
-rw-r--r--src/core/swap.c8
-rw-r--r--src/coredump/coredump.c40
-rw-r--r--src/coredump/coredumpctl.c28
-rw-r--r--src/cryptsetup/cryptsetup-generator.c15
-rw-r--r--src/cryptsetup/cryptsetup.c26
-rw-r--r--src/debug-generator/debug-generator.c7
-rw-r--r--src/delta/delta.c18
-rw-r--r--src/detect-virt/detect-virt.c8
-rw-r--r--src/dissect/dissect.c22
-rw-r--r--src/escape/escape.c63
-rw-r--r--src/firstboot/firstboot.c42
-rw-r--r--src/fstab-generator/fstab-generator.c7
-rw-r--r--src/hibernate-resume/hibernate-resume-generator.c7
-rw-r--r--src/import/curl-util.c14
-rw-r--r--src/import/export.c7
-rw-r--r--src/import/pull-common.c14
-rw-r--r--src/import/pull-job.c46
-rw-r--r--src/import/pull.c7
-rw-r--r--src/initctl/initctl.c7
-rw-r--r--src/journal-remote/journal-gatewayd.c46
-rw-r--r--src/journal-remote/journal-remote-main.c178
-rw-r--r--src/journal-remote/journal-upload-journal.c7
-rw-r--r--src/journal-remote/journal-upload.c139
-rw-r--r--src/journal-remote/microhttpd-util.c10
-rw-r--r--src/journal/cat.c7
-rw-r--r--src/journal/catalog.c41
-rw-r--r--src/journal/journal-file.c322
-rw-r--r--src/journal/journalctl.c40
-rw-r--r--src/journal/journald-server.c36
-rw-r--r--src/journal/journald-stream.c8
-rw-r--r--src/journal/sd-journal.c46
-rw-r--r--src/libsystemd-network/dhcp-packet.c82
-rw-r--r--src/libsystemd/sd-bus/bus-message.c12
-rw-r--r--src/libsystemd/sd-device/sd-device.c16
-rw-r--r--src/libsystemd/sd-netlink/sd-netlink.c16
-rw-r--r--src/locale/localectl.c7
-rw-r--r--src/login/inhibit.c7
-rw-r--r--src/login/loginctl.c29
-rw-r--r--src/login/logind-button.c8
-rw-r--r--src/login/logind-dbus.c8
-rw-r--r--src/login/logind-session-device.c7
-rw-r--r--src/login/logind-session.c16
-rw-r--r--src/login/logind.c8
-rw-r--r--src/login/user-runtime-dir.c14
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c7
-rw-r--r--src/machine/machinectl.c62
-rw-r--r--src/mount/mount-tool.c99
-rw-r--r--src/notify/notify.c14
-rw-r--r--src/nspawn/nspawn-cgroup.c4
-rw-r--r--src/nspawn/nspawn-mount.c18
-rw-r--r--src/nspawn/nspawn-setuid.c70
-rw-r--r--src/nspawn/nspawn.c377
-rw-r--r--src/partition/growfs.c9
-rw-r--r--src/partition/makefs.c7
-rw-r--r--src/path/path.c4
-rw-r--r--src/portable/portablectl.c28
-rw-r--r--src/quotacheck/quotacheck.c7
-rw-r--r--src/random-seed/random-seed.c21
-rw-r--r--src/remount-fs/remount-fs.c7
-rw-r--r--src/resolve/resolvconf-compat.c37
-rw-r--r--src/resolve/resolvectl.c146
-rw-r--r--src/resolve/resolved-dns-dnssec.c8
-rw-r--r--src/resolve/resolved-dns-packet.c8
-rw-r--r--src/resolve/resolved-dns-transaction.c17
-rw-r--r--src/resolve/resolved-dnssd.c8
-rw-r--r--src/resolve/resolved-dnstls-gnutls.c10
-rw-r--r--src/resolve/resolved-dnstls-openssl.c5
-rw-r--r--src/resolve/resolved-etc-hosts.c16
-rw-r--r--src/resolve/resolved-manager.c21
-rw-r--r--src/rfkill/rfkill.c7
-rw-r--r--src/run/run.c99
-rw-r--r--src/shared/bootspec.c15
-rw-r--r--src/shared/bus-unit-util.c88
-rw-r--r--src/shared/bus-util.c8
-rw-r--r--src/shared/dissect-image.c7
-rw-r--r--src/shared/dropin.c8
-rw-r--r--src/shared/efivars.c7
-rw-r--r--src/shared/generator.c24
-rw-r--r--src/shared/install.c15
-rw-r--r--src/shared/journal-importer.c33
-rw-r--r--src/shared/logs-show.c49
-rw-r--r--src/shared/seccomp-util.c8
-rw-r--r--src/shared/serialize.c8
-rw-r--r--src/shared/sleep-config.c4
-rw-r--r--src/shared/verbs.c14
-rw-r--r--src/sleep/sleep.c38
-rw-r--r--src/socket-proxy/socket-proxyd.c28
-rw-r--r--src/stdio-bridge/stdio-bridge.c4
-rw-r--r--src/sysctl/sysctl.c7
-rw-r--r--src/systemctl/systemctl.c183
-rw-r--r--src/sysusers/sysusers.c29
-rw-r--r--src/timedate/timedatectl.c14
-rw-r--r--src/timesync/timesyncd-manager.c7
-rw-r--r--src/tmpfiles/tmpfiles.c99
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c35
-rw-r--r--src/udev/mtd_probe/probe_smartmedia.c28
-rw-r--r--src/udev/udev-builtin-kmod.c7
-rw-r--r--src/udev/udev-event.c7
-rw-r--r--src/udev/udev-rules.c8
-rw-r--r--src/udev/udevadm-hwdb.c7
-rw-r--r--src/udev/udevadm-settle.c5
-rw-r--r--src/udev/udevadm-test-builtin.c14
-rw-r--r--src/udev/udevadm-test.c14
-rw-r--r--src/user-sessions/user-sessions.c10
-rw-r--r--src/volatile-root/volatile-root.c35
129 files changed, 1946 insertions, 2325 deletions
diff --git a/coccinelle/synthetic-errno.cocci b/coccinelle/synthetic-errno.cocci
new file mode 100644
index 0000000000..c5533dd7fb
--- /dev/null
+++ b/coccinelle/synthetic-errno.cocci
@@ -0,0 +1,35 @@
+@@
+expression e;
+expression list args;
+@@
+- log_debug(args);
+- return -e;
++ return log_debug_errno(SYNTHETIC_ERRNO(e), args);
+@@
+expression e;
+expression list args;
+@@
+- log_info(args);
+- return -e;
++ return log_info_errno(SYNTHETIC_ERRNO(e), args);
+@@
+expression e;
+expression list args;
+@@
+- log_notice(args);
+- return -e;
++ return log_notice_errno(SYNTHETIC_ERRNO(e), args);
+@@
+expression e;
+expression list args;
+@@
+- log_error(args);
+- return -e;
++ return log_error_errno(SYNTHETIC_ERRNO(e), args);
+@@
+expression e;
+expression list args;
+@@
+- log_emergency(args);
+- return -e;
++ return log_emergency_errno(SYNTHETIC_ERRNO(e), args);
diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c
index 090b6b1783..90ba5d2b68 100644
--- a/src/ac-power/ac-power.c
+++ b/src/ac-power/ac-power.c
@@ -56,10 +56,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
- log_error("%s takes no arguments.", program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s takes no arguments.",
+ program_invocation_short_name);
return 1;
}
diff --git a/src/activate/activate.c b/src/activate/activate.c
index 4bc133a639..912772d590 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -122,10 +122,9 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd,
char **s;
int r;
- if (arg_inetd && n_fds != 1) {
- log_error("--inetd only supported for single file descriptors.");
- return -EINVAL;
- }
+ if (arg_inetd && n_fds != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--inetd only supported for single file descriptors.");
length = strv_length(arg_setenv);
@@ -384,19 +383,17 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'd':
- if (arg_socket_type == SOCK_SEQPACKET) {
- log_error("--datagram may not be combined with --seqpacket.");
- return -EINVAL;
- }
+ if (arg_socket_type == SOCK_SEQPACKET)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--datagram may not be combined with --seqpacket.");
arg_socket_type = SOCK_DGRAM;
break;
case ARG_SEQPACKET:
- if (arg_socket_type == SOCK_DGRAM) {
- log_error("--seqpacket may not be combined with --datagram.");
- return -EINVAL;
- }
+ if (arg_socket_type == SOCK_DGRAM)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--seqpacket may not be combined with --datagram.");
arg_socket_type = SOCK_SEQPACKET;
break;
@@ -448,17 +445,15 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind == argc) {
- log_error("%s: command to execute is missing.",
- program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind == argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s: command to execute is missing.",
+ program_invocation_short_name);
- if (arg_socket_type == SOCK_DGRAM && arg_accept) {
- log_error("Datagram sockets do not accept connections. "
- "The --datagram and --accept options may not be combined.");
- return -EINVAL;
- }
+ if (arg_socket_type == SOCK_DGRAM && arg_accept)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Datagram sockets do not accept connections. "
+ "The --datagram and --accept options may not be combined.");
arg_args = argv + optind;
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 5e0e03f53d..757ddea098 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -1360,10 +1360,10 @@ static int cat_config(int argc, char *argv[], void *userdata) {
break;
}
- if (!t) {
- log_error("Path %s does not start with any known prefix.", *arg);
- return -EINVAL;
- }
+ if (!t)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path %s does not start with any known prefix.",
+ *arg);
} else
t = *arg;
@@ -1638,10 +1638,9 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
}
#else
-static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
- log_error("Not compiled with syscall filters, sorry.");
- return -EOPNOTSUPP;
-}
+static int dump_syscall_filters(int argc, char *argv[], void *userdata)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Not compiled with syscall filters, sorry.");
#endif
static int dump_timespan(int argc, char *argv[], void *userdata) {
@@ -1948,10 +1947,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_MAN:
if (optarg) {
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("Failed to parse --man= argument.");
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --man= argument.");
arg_man = r;
} else
@@ -1962,10 +1960,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_GENERATORS:
if (optarg) {
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("Failed to parse --generators= argument.");
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --generators= argument.");
arg_generators = r;
} else
@@ -1981,15 +1978,13 @@ static int parse_argv(int argc, char *argv[]) {
}
if (arg_scope == UNIT_FILE_GLOBAL &&
- !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify")) {
- log_error("Option --global only makes sense with verbs dot, unit-paths, verify.");
- return -EINVAL;
- }
+ !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --global only makes sense with verbs dot, unit-paths, verify.");
- if (arg_root && !streq_ptr(argv[optind], "cat-config")) {
- log_error("Option --root is only supported for cat-config right now.");
- return -EINVAL;
- }
+ if (arg_root && !streq_ptr(argv[optind], "cat-config"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --root is only supported for cat-config right now.");
return 1; /* work to do */
}
diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c
index 530dc1ee6e..4637c32819 100644
--- a/src/ask-password/ask-password.c
+++ b/src/ask-password/ask-password.c
@@ -102,10 +102,10 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_TIMEOUT:
- if (parse_sec(optarg, &arg_timeout) < 0) {
- log_error("Failed to parse --timeout parameter %s", optarg);
- return -EINVAL;
- }
+ if (parse_sec(optarg, &arg_timeout) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --timeout parameter %s",
+ optarg);
break;
case ARG_ECHO:
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 613801f2c5..94ae37dcb0 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -2545,11 +2545,10 @@ static int cg_unified_update(void) {
unified_cache = CGROUP_UNIFIED_NONE;
}
}
- } else {
- log_debug("Unknown filesystem type %llx mounted on /sys/fs/cgroup.",
- (unsigned long long) fs.f_type);
- return -ENOMEDIUM;
- }
+ } else
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
+ "Unknown filesystem type %llx mounted on /sys/fs/cgroup.",
+ (unsigned long long)fs.f_type);
return 0;
}
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index d3593f196f..5e771a0aae 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -638,16 +638,18 @@ static int check_utf8ness_and_warn(
_cleanup_free_ char *p = NULL;
p = utf8_escape_invalid(key);
- log_error("%s:%u: invalid UTF-8 in key '%s', ignoring.", strna(filename), line, p);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s:%u: invalid UTF-8 in key '%s', ignoring.",
+ strna(filename), line, p);
}
if (value && !utf8_is_valid(value)) {
_cleanup_free_ char *p = NULL;
p = utf8_escape_invalid(value);
- log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", strna(filename), line, key, p);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.",
+ strna(filename), line, key, p);
}
return 0;
diff --git a/src/basic/log.h b/src/basic/log.h
index ddec8116ff..af01f50952 100644
--- a/src/basic/log.h
+++ b/src/basic/log.h
@@ -202,10 +202,10 @@ void log_assert_failed_return_realm(
#define log_full_errno_realm(realm, level, error, ...) \
({ \
int _level = (level), _e = (error), _realm = (realm); \
- (log_get_max_level_realm(_realm) >= LOG_PRI(_level)) \
+ (log_get_max_level_realm(_realm) >= LOG_PRI(_level)) \
? log_internal_realm(LOG_REALM_PLUS_LEVEL(_realm, _level), _e, \
__FILE__, __LINE__, __func__, __VA_ARGS__) \
- : -abs(_e); \
+ : -ERRNO_VALUE(_e); \
})
#define log_full_errno(level, error, ...) \
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 8f7f4b5e25..d1a34338f6 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -1227,8 +1227,7 @@ int must_be_root(void) {
if (geteuid() == 0)
return 0;
- log_error("Need to be root.");
- return -EPERM;
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Need to be root.");
}
int safe_fork_full(
diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c
index 54f6dc2059..1503f1032a 100644
--- a/src/basic/rm-rf.c
+++ b/src/basic/rm-rf.c
@@ -168,10 +168,10 @@ int rm_rf(const char *path, RemoveFlags flags) {
/* We refuse to clean the root file system with this
* call. This is extra paranoia to never cause a really
* seriously broken system. */
- if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW)) {
- log_error("Attempted to remove entire root file system (\"%s\"), and we can't allow that.", path);
- return -EPERM;
- }
+ if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW))
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Attempted to remove entire root file system (\"%s\"), and we can't allow that.",
+ path);
if (FLAGS_SET(flags, REMOVE_SUBVOLUME | REMOVE_ROOT | REMOVE_PHYSICAL)) {
/* Try to remove as subvolume first */
@@ -194,10 +194,10 @@ int rm_rf(const char *path, RemoveFlags flags) {
if (statfs(path, &s) < 0)
return -errno;
- if (is_physical_fs(&s)) {
- log_error("Attempted to remove files from a disk file system under \"%s\", refusing.", path);
- return -EPERM;
- }
+ if (is_physical_fs(&s))
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Attempted to remove files from a disk file system under \"%s\", refusing.",
+ path);
}
if ((flags & REMOVE_ROOT) && !(flags & REMOVE_ONLY_DIRECTORIES))
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index c3219d0873..af31f0967e 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -39,10 +39,9 @@ static int delete_rule(const char *rule) {
e = strchrnul(x+1, x[0]);
*e = 0;
- if (!filename_is_valid(x + 1)) {
- log_error("Rule file name '%s' is not valid, refusing.", x+1);
- return -EINVAL;
- }
+ if (!filename_is_valid(x + 1))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Rule file name '%s' is not valid, refusing.", x + 1);
fn = strappend("/proc/sys/fs/binfmt_misc/", x+1);
if (!fn)
@@ -170,10 +169,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_cat_config && argc > optind) {
- log_error("Positional arguments are not allowed with --cat-config");
- return -EINVAL;
- }
+ if (arg_cat_config && argc > optind)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Positional arguments are not allowed with --cat-config");
return 1;
}
diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c
index 92661122c5..42b9618aa9 100644
--- a/src/boot/bless-boot.c
+++ b/src/boot/bless-boot.c
@@ -121,10 +121,10 @@ static int parse_counter(
e++;
k = strspn(e, DIGITS);
- if (k == 0) {
- log_error("Can't parse empty 'tries left' counter from LoaderBootCountPath: %s", path);
- return -EINVAL;
- }
+ if (k == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
+ path);
z = strndupa(e, k);
r = safe_atou64(z, &left);
@@ -137,10 +137,10 @@ static int parse_counter(
e++;
k = strspn(e, DIGITS);
- if (k == 0) { /* If there's a "-" there also needs to be at least one digit */
- log_error("Can't parse empty 'tries done' counter from LoaderBootCountPath: %s", path);
- return -EINVAL;
- }
+ if (k == 0) /* If there's a "-" there also needs to be at least one digit */
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
+ path);
z = strndupa(e, k);
r = safe_atou64(z, &done);
@@ -185,22 +185,22 @@ static int acquire_boot_count_path(
efi_tilt_backslashes(path);
- if (!path_is_normalized(path)) {
- log_error("Path read from LoaderBootCountPath is not normalized, refusing: %s", path);
- return -EINVAL;
- }
+ if (!path_is_normalized(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path read from LoaderBootCountPath is not normalized, refusing: %s",
+ path);
- if (!path_is_absolute(path)) {
- log_error("Path read from LoaderBootCountPath is not absolute, refusing: %s", path);
- return -EINVAL;
- }
+ if (!path_is_absolute(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path read from LoaderBootCountPath is not absolute, refusing: %s",
+ path);
last = last_path_component(path);
e = strrchr(last, '+');
- if (!e) {
- log_error("Path read from LoaderBootCountPath does not contain a counter, refusing: %s", path);
- return -EINVAL;
- }
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path read from LoaderBootCountPath does not contain a counter, refusing: %s",
+ path);
if (ret_prefix) {
prefix = strndup(path, e - path);
@@ -458,15 +458,13 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
- if (detect_container() > 0) {
- log_error("Marking a boot is not supported in containers.");
- return -EOPNOTSUPP;
- }
+ if (detect_container() > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Marking a boot is not supported in containers.");
- if (!is_efi_boot()) {
- log_error("Marking a boot is only supported on EFI systems.");
- return -EOPNOTSUPP;
- }
+ if (!is_efi_boot())
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Marking a boot is only supported on EFI systems.");
return dispatch_verb(argc, argv, verbs, NULL);
}
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 3ff3b3ffa3..608b35b715 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -372,18 +372,18 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
r = get_file_version(fd_from, &a);
if (r < 0)
return r;
- if (r == 0) {
- log_error("Source file \"%s\" does not carry version information!", from);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Source file \"%s\" does not carry version information!",
+ from);
r = get_file_version(fd_to, &b);
if (r < 0)
return r;
- if (r == 0 || compare_product(a, b) != 0) {
- log_notice("Skipping \"%s\", since it's owned by another boot loader.", to);
- return -EEXIST;
- }
+ if (r == 0 || compare_product(a, b) != 0)
+ return log_notice_errno(SYNTHETIC_ERRNO(EEXIST),
+ "Skipping \"%s\", since it's owned by another boot loader.",
+ to);
if (compare_version(a, b) < 0) {
log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to);
@@ -1193,10 +1193,9 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
const char *name;
int r;
- if (!is_efi_boot()) {
- log_error("Not booted with UEFI.");
- return -EOPNOTSUPP;
- }
+ if (!is_efi_boot())
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Not booted with UEFI.");
if (access("/sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK) < 0) {
if (errno == ENOENT) {
@@ -1207,15 +1206,15 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
return log_error_errno(errno, "Failed to detect whether boot loader supports '%s' operation: %m", argv[0]);
}
- if (detect_container() > 0) {
- log_error("'%s' operation not supported in a container.", argv[0]);
- return -EOPNOTSUPP;
- }
-
- if (!arg_touch_variables) {
- log_error("'%s' operation cannot be combined with --touch-variables=no.", argv[0]);
- return -EINVAL;
- }
+ if (detect_container() > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "'%s' operation not supported in a container.",
+ argv[0]);
+
+ if (!arg_touch_variables)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "'%s' operation cannot be combined with --touch-variables=no.",
+ argv[0]);
name = streq(argv[0], "set-default") ? "LoaderEntryDefault" : "LoaderEntryOneShot";
diff --git a/src/busctl/busctl-introspect.c b/src/busctl/busctl-introspect.c
index 4af3481a5f..18254efd2d 100644
--- a/src/busctl/busctl-introspect.c
+++ b/src/busctl/busctl-introspect.c
@@ -67,10 +67,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
return t;
}
- if (t == XML_END) {
- log_error("Premature end of XML data.");
- return -EBADMSG;
- }
+ if (t == XML_END)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Premature end of XML data.");
switch (state) {
@@ -84,10 +83,10 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
else if (streq_ptr(name, "value"))
state = STATE_VALUE;
- else {
- log_error("Unexpected <annotation> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <annotation> attribute %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "annotation"))) {
@@ -116,10 +115,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
return 0;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <annotation>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <annotation>. (1)");
break;
@@ -129,10 +127,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(field, name);
state = STATE_ANNOTATION;
- } else {
- log_error("Unexpected token in <annotation>. (2)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <annotation>. (2)");
break;
@@ -142,10 +139,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(value, name);
state = STATE_ANNOTATION;
- } else {
- log_error("Unexpected token in <annotation>. (3)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <annotation>. (3)");
break;
@@ -187,10 +183,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
assert(context);
assert(prefix);
- if (n_depth > NODE_DEPTH_MAX) {
- log_error("<node> depth too high.");
- return -EINVAL;
- }
+ if (n_depth > NODE_DEPTH_MAX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "<node> depth too high.");
for (;;) {
_cleanup_free_ char *name = NULL;
@@ -202,10 +196,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
return t;
}
- if (t == XML_END) {
- log_error("Premature end of XML data.");
- return -EBADMSG;
- }
+ if (t == XML_END)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Premature end of XML data.");
switch (state) {
@@ -214,10 +206,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (streq_ptr(name, "name"))
state = STATE_NODE_NAME;
- else {
- log_error("Unexpected <node> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <node> attribute %s.", name);
} else if (t == XML_TAG_OPEN) {
@@ -228,10 +219,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_node(context, np, n_depth+1);
if (r < 0)
return r;
- } else {
- log_error("Unexpected <node> tag %s.", name);
- return -EBADMSG;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <node> tag %s.", name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "node"))) {
@@ -244,10 +234,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
return 0;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <node>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <node>. (1)");
break;
@@ -271,10 +260,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
np = node_path;
state = STATE_NODE;
- } else {
- log_error("Unexpected token in <node>. (2)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <node>. (2)");
break;
@@ -283,10 +271,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_INTERFACE_NAME;
- else {
- log_error("Unexpected <interface> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <interface> attribute %s.",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "method"))
@@ -300,10 +288,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->interface_flags);
if (r < 0)
return r;
- } else {
- log_error("Unexpected <interface> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected <interface> tag %s.", name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "interface"))) {
@@ -319,10 +306,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_NODE;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <interface>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <interface>. (1)");
break;
@@ -333,10 +319,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->interface_name, name);
state = STATE_INTERFACE;
- } else {
- log_error("Unexpected token in <interface>. (2)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <interface>. (2)");
break;
@@ -345,10 +330,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_METHOD_NAME;
- else {
- log_error("Unexpected <method> attribute %s", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <method> attribute %s",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "arg"))
state = STATE_METHOD_ARG;
@@ -356,10 +341,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->member_flags);
if (r < 0)
return r;
- } else {
- log_error("Unexpected <method> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected <method> tag %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "method"))) {
@@ -375,10 +360,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <method> (1).");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <method> (1).");
break;
@@ -389,10 +373,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name);
state = STATE_METHOD;
- } else {
- log_error("Unexpected token in <method> (2).");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <method> (2).");
break;
@@ -405,19 +388,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_METHOD_ARG_TYPE;
else if (streq_ptr(name, "direction"))
state = STATE_METHOD_ARG_DIRECTION;
- else {
- log_error("Unexpected method <arg> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected method <arg> attribute %s.",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL);
if (r < 0)
return r;
- } else {
- log_error("Unexpected method <arg> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected method <arg> tag %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) {
@@ -439,10 +422,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
}
state = STATE_METHOD;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in method <arg>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in method <arg>. (1)");
break;
@@ -450,10 +432,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE)
state = STATE_METHOD_ARG;
- else {
- log_error("Unexpected token in method <arg>. (2)");
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in method <arg>. (2)");
break;
@@ -463,10 +444,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name);
state = STATE_METHOD_ARG;
- } else {
- log_error("Unexpected token in method <arg>. (3)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in method <arg>. (3)");
break;
@@ -476,10 +456,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name);
state = STATE_METHOD_ARG;
- } else {
- log_error("Unexpected token in method <arg>. (4)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in method <arg>. (4)");
break;
@@ -488,10 +467,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_SIGNAL_NAME;
- else {
- log_error("Unexpected <signal> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <signal> attribute %s.",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "arg"))
state = STATE_SIGNAL_ARG;
@@ -499,10 +478,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->member_flags);
if (r < 0)
return r;
- } else {
- log_error("Unexpected <signal> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected <signal> tag %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "signal"))) {
@@ -518,10 +497,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <signal>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <signal>. (1)");
break;
@@ -532,10 +510,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name);
state = STATE_SIGNAL;
- } else {
- log_error("Unexpected token in <signal>. (2)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <signal>. (2)");
break;
@@ -548,19 +525,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_SIGNAL_ARG_TYPE;
else if (streq_ptr(name, "direction"))
state = STATE_SIGNAL_ARG_DIRECTION;
- else {
- log_error("Unexpected signal <arg> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected signal <arg> attribute %s.",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL);
if (r < 0)
return r;
- } else {
- log_error("Unexpected signal <arg> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected signal <arg> tag %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) {
@@ -575,10 +552,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
}
state = STATE_SIGNAL;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in signal <arg> (1).");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in signal <arg> (1).");
break;
@@ -586,10 +562,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE)
state = STATE_SIGNAL_ARG;
- else {
- log_error("Unexpected token in signal <arg> (2).");
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in signal <arg> (2).");
break;
@@ -599,10 +574,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name);
state = STATE_SIGNAL_ARG;
- } else {
- log_error("Unexpected token in signal <arg> (3).");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in signal <arg> (3).");
break;
@@ -612,10 +586,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name);
state = STATE_SIGNAL_ARG;
- } else {
- log_error("Unexpected token in signal <arg>. (4)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in signal <arg>. (4)");
break;
@@ -628,20 +601,20 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_PROPERTY_TYPE;
else if (streq_ptr(name, "access"))
state = STATE_PROPERTY_ACCESS;
- else {
- log_error("Unexpected <property> attribute %s.", name);
- return -EBADMSG;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Unexpected <property> attribute %s.",
+ name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, &context->member_flags);
if (r < 0)
return r;
- } else {
- log_error("Unexpected <property> tag %s.", name);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected <property> tag %s.",
+ name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "property"))) {
@@ -658,10 +631,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE;
- } else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
- log_error("Unexpected token in <property>. (1)");
- return -EINVAL;
- }
+ } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <property>. (1)");
break;
@@ -672,10 +644,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name);
state = STATE_PROPERTY;
- } else {
- log_error("Unexpected token in <property>. (2)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <property>. (2)");
break;
@@ -686,10 +657,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_signature, name);
state = STATE_PROPERTY;
- } else {
- log_error("Unexpected token in <property>. (3)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <property>. (3)");
break;
@@ -701,10 +671,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
context->member_writable = true;
state = STATE_PROPERTY;
- } else {
- log_error("Unexpected token in <property>. (4)");
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected token in <property>. (4)");
break;
}
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 5ad2a7d12f..04c0b73fd2 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -1257,10 +1257,9 @@ static int verb_monitor(int argc, char **argv, void *userdata) {
static int verb_capture(int argc, char **argv, void *userdata) {
int r;
- if (isatty(fileno(stdout)) > 0) {
- log_error("Refusing to write message data to console, please redirect output to a file.");
- return -EINVAL;
- }
+ if (isatty(fileno(stdout)) > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Refusing to write message data to console, please redirect output to a file.");
bus_pcap_header(arg_snaplen, stdout);
@@ -1346,10 +1345,9 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
if (t == 0)
break;
- if (!v) {
- log_error("Too few parameters for signature.");
- return -EINVAL;
- }
+ if (!v)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too few parameters for signature.");
signature++;
p++;
@@ -1539,12 +1537,12 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
}
case SD_BUS_TYPE_UNIX_FD:
- log_error("UNIX file descriptor not supported as type.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "UNIX file descriptor not supported as type.");
default:
- log_error("Unknown signature type %c.", t);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown signature type %c.", t);
}
if (r < 0)
@@ -2291,10 +2289,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to parse size '%s': %m", optarg);
- if ((uint64_t) (size_t) sz != sz) {
- log_error("Size out of range.");
- return -E2BIG;
- }
+ if ((uint64_t) (size_t) sz != sz)
+ return log_error_errno(SYNTHETIC_ERRNO(E2BIG),
+ "Size out of range.");
arg_snaplen = (size_t) sz;
break;
@@ -2385,10 +2382,10 @@ static int parse_argv(int argc, char *argv[]) {
fputs("short\n"
"pretty\n", stdout);
return 0;
- } else {
- log_error("Unknown JSON out mode: %s", optarg);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown JSON out mode: %s",
+ optarg);
break;
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c
index 3cdadc8fad..b6b15cf114 100644
--- a/src/cgls/cgls.c
+++ b/src/cgls/cgls.c
@@ -146,10 +146,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_machine && arg_show_unit != SHOW_UNIT_NONE) {
- log_error("Cannot combine --unit or --user-unit with --machine=.");
- return -EINVAL;
- }
+ if (arg_machine && arg_show_unit != SHOW_UNIT_NONE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot combine --unit or --user-unit with --machine=.");
return 1;
}
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 562e6ece5b..5f6e778a38 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -779,10 +779,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_cpu_type = CPU_TIME;
else if (streq(optarg, "percentage"))
arg_cpu_type = CPU_PERCENT;
- else {
- log_error("Unknown argument to --cpu=: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown argument to --cpu=: %s",
+ optarg);
} else
arg_cpu_type = CPU_TIME;
@@ -799,10 +799,10 @@ static int parse_argv(int argc, char *argv[]) {
r = parse_sec(optarg, &arg_delay);
if (r < 0)
return log_error_errno(r, "Failed to parse delay parameter '%s': %m", optarg);
- if (arg_delay <= 0) {
- log_error("Invalid delay parameter '%s'", optarg);
- return -EINVAL;
- }
+ if (arg_delay <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid delay parameter '%s'",
+ optarg);
break;
@@ -856,10 +856,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_order = ORDER_MEMORY;
else if (streq(optarg, "io"))
arg_order = ORDER_IO;
- else {
- log_error("Invalid argument to --order=: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid argument to --order=: %s",
+ optarg);
break;
case 'k':
@@ -892,10 +892,9 @@ static int parse_argv(int argc, char *argv[]) {
if (optind == argc - 1)
arg_root = argv[optind];
- else if (optind < argc) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ else if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
return 1;
}
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 6c00f734a4..5908ad792a 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -994,10 +994,9 @@ int bus_init_private(Manager *m) {
const char *e, *joined;
e = secure_getenv("XDG_RUNTIME_DIR");
- if (!e) {
- log_error("XDG_RUNTIME_DIR is not set, refusing.");
- return -EHOSTDOWN;
- }
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
+ "XDG_RUNTIME_DIR is not set, refusing.");
joined = strjoina(e, "/systemd/private");
salen = sockaddr_un_set_path(&sa.un, joined);
diff --git a/src/core/job.c b/src/core/job.c
index 8f36e02eb9..1f6b36033d 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -244,10 +244,10 @@ int job_install_deserialized(Job *j) {
assert(!j->installed);
- if (j->type < 0 || j->type >= _JOB_TYPE_MAX_IN_TRANSACTION) {
- log_debug("Invalid job type %s in deserialization.", strna(job_type_to_string(j->type)));
- return -EINVAL;
- }
+ if (j->type < 0 || j->type >= _JOB_TYPE_MAX_IN_TRANSACTION)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid job type %s in deserialization.",
+ strna(job_type_to_string(j->type)));
pj = (j->type == JOB_NOP) ? &j->unit->nop_job : &j->unit->job;
if (*pj) {
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 248a83847e..4dfdc475ba 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -200,10 +200,10 @@ int machine_id_commit(const char *root) {
r = fd_is_temporary_fs(fd);
if (r < 0)
return log_error_errno(r, "Failed to determine whether %s is on a temporary file system: %m", etc_machine_id);
- if (r == 0) {
- log_error("%s is not on a temporary file system.", etc_machine_id);
- return -EROFS;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EROFS),
+ "%s is not on a temporary file system.",
+ etc_machine_id);
r = id128_read_fd(fd, ID128_PLAIN, &id);
if (r < 0)
diff --git a/src/core/main.c b/src/core/main.c
index 6ad34aaae5..34794ccdd1 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1031,10 +1031,10 @@ static int parse_argv(int argc, char *argv[]) {
r = safe_atoi(optarg, &fd);
if (r < 0)
log_error_errno(r, "Failed to parse deserialize option \"%s\": %m", optarg);
- if (fd < 0) {
- log_error("Invalid deserialize fd: %d", fd);
- return -EINVAL;
- }
+ if (fd < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid deserialize fd: %d",
+ fd);
(void) fd_cloexec(fd, true);
@@ -1088,8 +1088,8 @@ static int parse_argv(int argc, char *argv[]) {
/* Hmm, when we aren't run as init system
* let's complain about excess arguments */
- log_error("Excess arguments.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Excess arguments.");
}
return 0;
@@ -2149,50 +2149,43 @@ static int load_configuration(int argc, char **argv, const char **ret_error_mess
static int safety_checks(void) {
if (getpid_cached() == 1 &&
- arg_action != ACTION_RUN) {
- log_error("Unsupported execution mode while PID 1.");
- return -EPERM;
- }
+ arg_action != ACTION_RUN)
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Unsupported execution mode while PID 1.");
if (getpid_cached() == 1 &&
- !arg_system) {
- log_error("Can't run --user mode as PID 1.");
- return -EPERM;
- }
+ !arg_system)
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Can't run --user mode as PID 1.");
if (arg_action == ACTION_RUN &&
arg_system &&
- getpid_cached() != 1) {
- log_error("Can't run system mode unless PID 1.");
- return -EPERM;
- }
+ getpid_cached() != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Can't run system mode unless PID 1.");
if (arg_action == ACTION_TEST &&
- geteuid() == 0) {
- log_error("Don't run test mode as root.");
- return -EPERM;
- }
+ geteuid() == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Don't run test mode as root.");
if (!arg_system &&
arg_action == ACTION_RUN &&
- sd_booted() <= 0) {
- log_error("Trying to run as user instance, but the system has not been booted with systemd.");
- return -EOPNOTSUPP;
- }
+ sd_booted() <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Trying to run as user instance, but the system has not been booted with systemd.");
if (!arg_system &&
arg_action == ACTION_RUN &&
- !getenv("XDG_RUNTIME_DIR")) {
- log_error("Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.");
- return -EUNATCH;
- }
+ !getenv("XDG_RUNTIME_DIR"))
+ return log_error_errno(SYNTHETIC_ERRNO(EUNATCH),
+ "Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.");
if (arg_system &&
arg_action == ACTION_RUN &&
- running_in_chroot() > 0) {
- log_error("Cannot be run in a chroot() environment.");
- return -EOPNOTSUPP;
- }
+ running_in_chroot() > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Cannot be run in a chroot() environment.");
return 0;
}
diff --git a/src/core/namespace.c b/src/core/namespace.c
index c7cc1c7550..01516072a0 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -235,10 +235,9 @@ static int append_access_mounts(MountEntry **p, char **strv, MountMode mode, boo
needs_prefix = true;
}
- if (!path_is_absolute(e)) {
- log_debug("Path is not absolute: %s", e);
- return -EINVAL;
- }
+ if (!path_is_absolute(e))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path is not absolute: %s", e);
*((*p)++) = (MountEntry) {
.path_const = e,
@@ -306,10 +305,10 @@ static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs,
unsigned long flags;
bool ro = false;
- if (!path_is_absolute(t->path)) {
- log_debug("Path is not absolute: %s", t->path);
- return -EINVAL;
- }
+ if (!path_is_absolute(t->path))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path is not absolute: %s",
+ t->path);
str = strjoin("mode=0755,", t->options);
if (!str)
@@ -575,10 +574,10 @@ static int clone_device_node(
}
if (!S_ISBLK(st.st_mode) &&
- !S_ISCHR(st.st_mode)) {
- log_debug("Device node '%s' to clone is not a device node, ignoring.", d);
- return -EINVAL;
- }
+ !S_ISCHR(st.st_mode))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Device node '%s' to clone is not a device node, ignoring.",
+ d);
dn = strjoina(temporary_mount, d);
@@ -855,10 +854,10 @@ static int follow_symlink(
if (r > 0) /* Reached the end, nothing more to resolve */
return 1;
- if (m->n_followed >= CHASE_SYMLINKS_MAX) { /* put a boundary on things */
- log_debug("Symlink loop on '%s'.", mount_entry_path(m));
- return -ELOOP;
- }
+ if (m->n_followed >= CHASE_SYMLINKS_MAX) /* put a boundary on things */
+ return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
+ "Symlink loop on '%s'.",
+ mount_entry_path(m));
log_debug("Followed mount entry path symlink %s → %s.", mount_entry_path(m), target);
@@ -900,10 +899,9 @@ static int apply_mount(
}
what = mode_to_inaccessible_node(target.st_mode);
- if (!what) {
- log_debug("File type not supported for inaccessible mounts. Note that symlinks are not allowed");
- return -ELOOP;
- }
+ if (!what)
+ return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
+ "File type not supported for inaccessible mounts. Note that symlinks are not allowed");
break;
}
diff --git a/src/core/path.c b/src/core/path.c
index e649cc232e..01019b0cf7 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -146,10 +146,9 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
ssize_t l;
int r = 0;
- if (revents != EPOLLIN) {
- log_error("Got invalid poll event on inotify.");
- return -EINVAL;
- }
+ if (revents != EPOLLIN)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Got invalid poll event on inotify.");
l = read(s->inotify_fd, &buffer, sizeof(buffer));
if (l < 0) {
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index 181e08de23..eae7295acb 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -137,10 +137,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option code.");
}
- if (!arg_verb) {
- log_error("Verb argument missing.");
- return -EINVAL;
- }
+ if (!arg_verb)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Verb argument missing.");
return 0;
}
diff --git a/src/core/swap.c b/src/core/swap.c
index 6a2e13f56e..db806fe0bb 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -372,10 +372,10 @@ static int swap_setup_unit(
if (u &&
SWAP(u)->from_proc_swaps &&
- !path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps)) {
- log_error("Swap %s appeared twice with different device paths %s and %s", e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps);
- return -EEXIST;
- }
+ !path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps))
+ return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+ "Swap %s appeared twice with different device paths %s and %s",
+ e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps);
if (!u) {
delete = true;
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 243a880542..8c2cf7daa6 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -351,16 +351,15 @@ static int save_external_coredump(
/* Is coredumping disabled? Then don't bother saving/processing the coredump.
* Anything below PAGE_SIZE cannot give a readable coredump (the kernel uses
* ELF_EXEC_PAGESIZE which is not easily accessible, but is usually the same as PAGE_SIZE. */
- log_info("Resource limits disable core dumping for process %s (%s).",
- context[CONTEXT_PID], context[CONTEXT_COMM]);
- return -EBADSLT;
+ return log_info_errno(SYNTHETIC_ERRNO(EBADSLT),
+ "Resource limits disable core dumping for process %s (%s).",
+ context[CONTEXT_PID], context[CONTEXT_COMM]);
}
process_limit = MAX(arg_process_size_max, storage_size_max());
- if (process_limit == 0) {
- log_debug("Limits for coredump processing and storage are both 0, not dumping core.");
- return -EBADSLT;
- }
+ if (process_limit == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADSLT),
+ "Limits for coredump processing and storage are both 0, not dumping core.");
/* Never store more than the process configured, or than we actually shall keep or process */
max_size = MIN(rlimit, process_limit);
@@ -484,10 +483,9 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
n = read(fd, field + 9, size);
if (n < 0)
return log_error_errno((int) n, "Failed to read core data: %m");
- if ((size_t) n < size) {
- log_error("Core data too short.");
- return -EIO;
- }
+ if ((size_t) n < size)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Core data too short.");
*ret = TAKE_PTR(field);
*ret_size = size + 9;
@@ -1236,10 +1234,10 @@ static int process_kernel(int argc, char* argv[]) {
log_debug("Processing coredump received from the kernel...");
- if (argc < CONTEXT_COMM + 1) {
- log_error("Not enough arguments passed by the kernel (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1);
- return -EINVAL;
- }
+ if (argc < CONTEXT_COMM + 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not enough arguments passed by the kernel (%i, expected %i).",
+ argc - 1, CONTEXT_COMM + 1 - 1);
context[CONTEXT_PID] = argv[1 + CONTEXT_PID];
context[CONTEXT_UID] = argv[1 + CONTEXT_UID];
@@ -1293,10 +1291,10 @@ static int process_backtrace(int argc, char *argv[]) {
log_debug("Processing backtrace on stdin...");
- if (argc < CONTEXT_COMM + 1) {
- log_error("Not enough arguments passed (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1);
- return -EINVAL;
- }
+ if (argc < CONTEXT_COMM + 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not enough arguments passed (%i, expected %i).",
+ argc - 1, CONTEXT_COMM + 1 - 1);
context[CONTEXT_PID] = argv[2 + CONTEXT_PID];
context[CONTEXT_UID] = argv[2 + CONTEXT_UID];
@@ -1407,8 +1405,8 @@ static int run(int argc, char *argv[]) {
} else if (r == 1)
return process_socket(SD_LISTEN_FDS_START);
- log_error("Received unexpected number of file descriptors.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Received unexpected number of file descriptors.");
}
DEFINE_MAIN_FUNCTION(run);
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 9f867bb1e7..1f85d3deab 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -225,10 +225,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'o':
- if (arg_output) {
- log_error("Cannot set output more than once.");
- return -EINVAL;
- }
+ if (arg_output)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot set output more than once.");
arg_output = optarg;
break;
@@ -246,10 +245,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'F':
- if (arg_field) {
- log_error("Cannot use --field/-F more than once.");
- return -EINVAL;
- }
+ if (arg_field)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot use --field/-F more than once.");
arg_field = optarg;
break;
@@ -277,10 +275,9 @@ static int parse_argv(int argc, char *argv[]) {
}
if (arg_since != USEC_INFINITY && arg_until != USEC_INFINITY &&
- arg_since > arg_until) {
- log_error("--since= must be before --until=.");
- return -EINVAL;
- }
+ arg_since > arg_until)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--since= must be before --until=.");
return 1;
}
@@ -628,10 +625,9 @@ static int focus(sd_journal *j) {
r = sd_journal_previous(j);
if (r < 0)
return log_error_errno(r, "Failed to search journal: %m");
- if (r == 0) {
- log_error("No match found.");
- return -ESRCH;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "No match found.");
return r;
}
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 15bfe9348f..7da13dc207 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -123,10 +123,10 @@ static int create_disk(
swap = fstab_test_option(options, "swap\0");
netdev = fstab_test_option(options, "_netdev\0");
- if (tmp && swap) {
- log_error("Device '%s' cannot be both 'tmp' and 'swap'. Ignoring.", name);
- return -EINVAL;
- }
+ if (tmp && swap)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Device '%s' cannot be both 'tmp' and 'swap'. Ignoring.",
+ name);
name_escaped = specifier_escape(name);
if (!name_escaped)
@@ -158,10 +158,9 @@ static int create_disk(
return log_oom();
}
- if (keydev && !password) {
- log_error("Key device is specified, but path to the password file is missing.");
- return -EINVAL;
- }
+ if (keydev && !password)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Key device is specified, but path to the password file is missing.");
r = generator_open_unit_file(arg_dest, NULL, n, &f);
if (r < 0)
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 8afff73990..daf26aad70 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -173,15 +173,13 @@ static int parse_one_option(const char *option) {
} else if ((val = startswith(option, "header="))) {
arg_type = ANY_LUKS;
- if (!path_is_absolute(val)) {
- log_error("Header path \"%s\" is not absolute, refusing.", val);
- return -EINVAL;
- }
+ if (!path_is_absolute(val))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Header path \"%s\" is not absolute, refusing.", val);
- if (arg_header) {
- log_error("Duplicate header= option, refusing.");
- return -EINVAL;
- }
+ if (arg_header)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Duplicate header= option, refusing.");
arg_header = strdup(val);
if (!arg_header)
@@ -216,8 +214,8 @@ static int parse_one_option(const char *option) {
arg_type = CRYPT_TCRYPT;
arg_tcrypt_veracrypt = true;
#else
- log_error("This version of cryptsetup does not support tcrypt-veracrypt; refusing.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This version of cryptsetup does not support tcrypt-veracrypt; refusing.");
#endif
} else if (STR_IN_SET(option, "plain", "swap", "tmp"))
arg_type = CRYPT_PLAIN;
@@ -463,10 +461,10 @@ static int attach_tcrypt(
r = crypt_load(cd, CRYPT_TCRYPT, &params);
if (r < 0) {
- if (key_file && r == -EPERM) {
- log_error("Failed to activate using password file '%s'.", key_file);
- return -EAGAIN;
- }
+ if (key_file && r == -EPERM)
+ return log_error_errno(SYNTHETIC_ERRNO(EAGAIN),
+ "Failed to activate using password file '%s'.",
+ key_file);
return r;
}
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c
index 6e30aa475c..24bc4bd7e2 100644
--- a/src/debug-generator/debug-generator.c
+++ b/src/debug-generator/debug-generator.c
@@ -145,10 +145,9 @@ static int generate_wants_symlinks(void) {
static int run(int argc, char *argv[]) {
int r, q;
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
+ if (argc > 1 && argc != 4)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes three or no arguments.");
if (argc > 1)
arg_dest = argv[2];
diff --git a/src/delta/delta.c b/src/delta/delta.c
index f3a23f95d4..328f5654e8 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -513,8 +513,8 @@ static int process_suffix_chop(const char *arg) {
}
}
- log_error("Invalid suffix specification %s.", arg);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid suffix specification %s.", arg);
}
static int help(void) {
@@ -604,10 +604,9 @@ static int parse_argv(int argc, char *argv[]) {
case 't': {
int f;
f = parse_flags(optarg, arg_flags);
- if (f < 0) {
- log_error("Failed to parse flags field.");
- return -EINVAL;
- }
+ if (f < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse flags field.");
arg_flags = f;
break;
}
@@ -619,10 +618,9 @@ static int parse_argv(int argc, char *argv[]) {
int b;
b = parse_boolean(optarg);
- if (b < 0) {
- log_error("Failed to parse diff boolean.");
- return -EINVAL;
- }
+ if (b < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse diff boolean.");
arg_diff = b;
}
diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c
index 1812218daf..f05f2279b3 100644
--- a/src/detect-virt/detect-virt.c
+++ b/src/detect-virt/detect-virt.c
@@ -113,10 +113,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
- log_error("%s takes no arguments.", program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s takes no arguments.",
+ program_invocation_short_name);
return 1;
}
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index 0e12f51be6..50de0afce6 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -94,10 +94,10 @@ static int parse_argv(int argc, char *argv[]) {
flags = DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD;
else if (streq(optarg, "crypt"))
flags = DISSECT_IMAGE_DISCARD_ANY;
- else {
- log_error("Unknown --discard= parameter: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown --discard= parameter: %s",
+ optarg);
arg_flags = (arg_flags & ~DISSECT_IMAGE_DISCARD_ANY) | flags;
break;
@@ -134,20 +134,18 @@ static int parse_argv(int argc, char *argv[]) {
switch (arg_action) {
case ACTION_DISSECT:
- if (optind + 1 != argc) {
- log_error("Expected a file path as only argument.");
- return -EINVAL;
- }
+ if (optind + 1 != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected a file path as only argument.");
arg_image = argv[optind];
arg_flags |= DISSECT_IMAGE_READ_ONLY;
break;
case ACTION_MOUNT:
- if (optind + 2 != argc) {
- log_error("Expected a file path and mount point path as only arguments.");
- return -EINVAL;
- }
+ if (optind + 2 != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected a file path and mount point path as only arguments.");
arg_image = argv[optind];
arg_path = argv[optind + 1];
diff --git a/src/escape/escape.c b/src/escape/escape.c
index 2b3cff0f3d..8b38d9f679 100644
--- a/src/escape/escape.c
+++ b/src/escape/escape.c
@@ -85,20 +85,18 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_SUFFIX:
- if (unit_type_from_string(optarg) < 0) {
- log_error("Invalid unit suffix type %s.", optarg);
- return -EINVAL;
- }
+ if (unit_type_from_string(optarg) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid unit suffix type %s.", optarg);
arg_suffix = optarg;
break;
case ARG_TEMPLATE:
- if (!unit_name_is_valid(optarg, UNIT_NAME_TEMPLATE)) {
- log_error("Template name %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!unit_name_is_valid(optarg, UNIT_NAME_TEMPLATE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Template name %s is not valid.", optarg);
arg_template = optarg;
break;
@@ -126,40 +124,33 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind >= argc) {
- log_error("Not enough arguments.");
- return -EINVAL;
- }
+ if (optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not enough arguments.");
- if (arg_template && arg_suffix) {
- log_error("--suffix= and --template= may not be combined.");
- return -EINVAL;
- }
+ if (arg_template && arg_suffix)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--suffix= and --template= may not be combined.");
- if ((arg_template || arg_suffix) && arg_action == ACTION_MANGLE) {
- log_error("--suffix= and --template= are not compatible with --mangle.");
- return -EINVAL;
- }
+ if ((arg_template || arg_suffix) && arg_action == ACTION_MANGLE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--suffix= and --template= are not compatible with --mangle.");
- if (arg_suffix && arg_action == ACTION_UNESCAPE) {
- log_error("--suffix is not compatible with --unescape.");
- return -EINVAL;
- }
+ if (arg_suffix && arg_action == ACTION_UNESCAPE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--suffix is not compatible with --unescape.");
- if (arg_path && !IN_SET(arg_action, ACTION_ESCAPE, ACTION_UNESCAPE)) {
- log_error("--path may not be combined with --mangle.");
- return -EINVAL;
- }
+ if (arg_path && !IN_SET(arg_action, ACTION_ESCAPE, ACTION_UNESCAPE))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--path may not be combined with --mangle.");
- if (arg_instance && arg_action != ACTION_UNESCAPE) {
- log_error("--instance must be used in conjunction with --unescape.");
- return -EINVAL;
- }
+ if (arg_instance && arg_action != ACTION_UNESCAPE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--instance must be used in conjunction with --unescape.");
- if (arg_instance && arg_template) {
- log_error("--instance may not be combined with --template.");
- return -EINVAL;
- }
+ if (arg_instance && arg_template)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--instance may not be combined with --template.");
return 1;
}
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 27dd494980..8e429481f1 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -806,10 +806,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_LOCALE:
- if (!locale_is_valid(optarg)) {
- log_error("Locale %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!locale_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Locale %s is not valid.", optarg);
r = free_and_strdup(&arg_locale, optarg);
if (r < 0)
@@ -818,10 +817,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_LOCALE_MESSAGES:
- if (!locale_is_valid(optarg)) {
- log_error("Locale %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!locale_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Locale %s is not valid.", optarg);
r = free_and_strdup(&arg_locale_messages, optarg);
if (r < 0)
@@ -830,10 +828,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_KEYMAP:
- if (!keymap_is_valid(optarg)) {
- log_error("Keymap %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!keymap_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Keymap %s is not valid.", optarg);
r = free_and_strdup(&arg_keymap, optarg);
if (r < 0)
@@ -842,10 +839,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_TIMEZONE:
- if (!timezone_is_valid(optarg, LOG_ERR)) {
- log_error("Timezone %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!timezone_is_valid(optarg, LOG_ERR))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Timezone %s is not valid.", optarg);
r = free_and_strdup(&arg_timezone, optarg);
if (r < 0)
@@ -869,10 +865,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_HOSTNAME:
- if (!hostname_is_valid(optarg, true)) {
- log_error("Host name %s is not valid.", optarg);
- return -EINVAL;
- }
+ if (!hostname_is_valid(optarg, true))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Host name %s is not valid.", optarg);
hostname_cleanup(optarg);
r = free_and_strdup(&arg_hostname, optarg);
@@ -882,10 +877,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_MACHINE_ID:
- if (sd_id128_from_string(optarg, &arg_machine_id) < 0) {
- log_error("Failed to parse machine id %s.", optarg);
- return -EINVAL;
- }
+ if (sd_id128_from_string(optarg, &arg_machine_id) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse machine id %s.", optarg);
break;
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 15ac20dd71..c74ad075c0 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -870,10 +870,9 @@ static int determine_root(void) {
static int run(int argc, char *argv[]) {
int r;
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
+ if (argc > 1 && argc != 4)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes three or no arguments.");
if (argc > 1)
arg_dest = argv[1];
diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c
index e225424ce2..8b127ca85c 100644
--- a/src/hibernate-resume/hibernate-resume-generator.c
+++ b/src/hibernate-resume/hibernate-resume-generator.c
@@ -74,10 +74,9 @@ static int run(int argc, char *argv[]) {
log_setup_generator();
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
+ if (argc > 1 && argc != 4)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes three or no arguments.");
if (argc > 1)
arg_dest = argv[1];
diff --git a/src/import/curl-util.c b/src/import/curl-util.c
index 539e2c28ac..48dc9d1963 100644
--- a/src/import/curl-util.c
+++ b/src/import/curl-util.c
@@ -41,10 +41,9 @@ static int curl_glue_on_io(sd_event_source *s, int fd, uint32_t revents, void *u
else
action = 0;
- if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK) {
- log_debug("Failed to propagate IO event.");
- return -EINVAL;
- }
+ if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to propagate IO event.");
curl_glue_check_finished(g);
return 0;
@@ -151,10 +150,9 @@ static int curl_glue_on_timer(sd_event_source *s, uint64_t usec, void *userdata)
assert(s);
assert(g);
- if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK) {
- log_debug("Failed to propagate timeout.");
- return -EINVAL;
- }
+ if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to propagate timeout.");
curl_glue_check_finished(g);
return 0;
diff --git a/src/import/export.c b/src/import/export.c
index e07aa5d6d5..f81485bbc7 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -253,10 +253,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_compress = IMPORT_COMPRESS_GZIP;
else if (streq(optarg, "bzip2"))
arg_compress = IMPORT_COMPRESS_BZIP2;
- else {
- log_error("Unknown format: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown format: %s", optarg);
break;
case '?':
diff --git a/src/import/pull-common.c b/src/import/pull-common.c
index 459024fb22..a90693c802 100644
--- a/src/import/pull-common.c
+++ b/src/import/pull-common.c
@@ -338,10 +338,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
if (r < 0)
return log_oom();
- if (!filename_is_valid(fn)) {
- log_error("Cannot verify checksum, could not determine server-side file name.");
- return -EBADMSG;
- }
+ if (!filename_is_valid(fn))
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Cannot verify checksum, could not determine server-side file name.");
line = strjoina(job->checksum, " *", fn, "\n");
@@ -359,10 +358,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
strlen(line));
}
- if (!p || (p != (char*) checksum_job->payload && p[-1] != '\n')) {
- log_error("DOWNLOAD INVALID: Checksum of %s file did not checkout, file has been tampered with.", fn);
- return -EBADMSG;
- }
+ if (!p || (p != (char*) checksum_job->payload && p[-1] != '\n'))
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "DOWNLOAD INVALID: Checksum of %s file did not checkout, file has been tampered with.", fn);
log_info("SHA256 checksum of %s is valid.", job->url);
return 1;
diff --git a/src/import/pull-job.c b/src/import/pull-job.c
index c494bbec3c..3d3a8713d7 100644
--- a/src/import/pull-job.c
+++ b/src/import/pull-job.c
@@ -214,15 +214,13 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
if (sz <= 0)
return 0;
- if (j->written_uncompressed + sz < j->written_uncompressed) {
- log_error("File too large, overflow");
- return -EOVERFLOW;
- }
+ if (j->written_uncompressed + sz < j->written_uncompressed)
+ return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW),
+ "File too large, overflow");
- if (j->written_uncompressed + sz > j->uncompressed_max) {
- log_error("File overly large, refusing");
- return -EFBIG;
- }
+ if (j->written_uncompressed + sz > j->uncompressed_max)
+ return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
+ "File overly large, refusing");
if (j->disk_fd >= 0) {
@@ -240,10 +238,8 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
}
if (n < 0)
return log_error_errno((int) n, "Failed to write file: %m");
- if ((size_t) n < sz) {
- log_error("Short write");
- return -EIO;
- }
+ if ((size_t) n < sz)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write");
} else {
if (!GREEDY_REALLOC(j->payload, j->payload_allocated, j->payload_size + sz))
@@ -268,21 +264,16 @@ static int pull_job_write_compressed(PullJob *j, void *p, size_t sz) {
if (sz <= 0)
return 0;
- if (j->written_compressed + sz < j->written_compressed) {
- log_error("File too large, overflow");
- return -EOVERFLOW;
- }
+ if (j->written_compressed + sz < j->written_compressed)
+ return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW), "File too large, overflow");
- if (j->written_compressed + sz > j->compressed_max) {
- log_error("File overly large, refusing.");
- return -EFBIG;
- }
+ if (j->written_compressed + sz > j->compressed_max)
+ return log_error_errno(SYNTHETIC_ERRNO(EFBIG), "File overly large, refusing.");
if (j->content_length != (uint64_t) -1 &&
- j->written_compressed + sz > j->content_length) {
- log_error("Content length incorrect.");
- return -EFBIG;
- }
+ j->written_compressed + sz > j->content_length)
+ return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
+ "Content length incorrect.");
if (j->checksum_context)
gcry_md_write(j->checksum_context, p, sz);
@@ -323,10 +314,9 @@ static int pull_job_open_disk(PullJob *j) {
if (j->calc_checksum) {
initialize_libgcrypt(false);
- if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0) {
- log_error("Failed to initialize hash context.");
- return -EIO;
- }
+ if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Failed to initialize hash context.");
}
return 0;
diff --git a/src/import/pull.c b/src/import/pull.c
index 810cab53ba..3376992588 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -271,10 +271,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_VERIFY:
arg_verify = import_verify_from_string(optarg);
- if (arg_verify < 0) {
- log_error("Invalid verification setting '%s'", optarg);
- return -EINVAL;
- }
+ if (arg_verify < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid verification setting '%s'", optarg);
break;
diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c
index 259908a885..c60d4bd740 100644
--- a/src/initctl/initctl.c
+++ b/src/initctl/initctl.c
@@ -322,10 +322,9 @@ static int process_event(Server *s, struct epoll_event *ev) {
assert(s);
- if (!(ev->events & EPOLLIN)) {
- log_info("Got invalid event from epoll. (3)");
- return -EIO;
- }
+ if (!(ev->events & EPOLLIN))
+ return log_info_errno(SYNTHETIC_ERRNO(EIO),
+ "Got invalid event from epoll. (3)");
f = (Fifo*) ev->data.ptr;
r = fifo_process(f);
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c
index b39c7e3388..91e25a87ab 100644
--- a/src/journal-remote/journal-gatewayd.c
+++ b/src/journal-remote/journal-gatewayd.c
@@ -921,10 +921,9 @@ static int parse_argv(int argc, char *argv[]) {
return version();
case ARG_KEY:
- if (arg_key_pem) {
- log_error("Key file specified twice");
- return -EINVAL;
- }
+ if (arg_key_pem)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Key file specified twice");
r = read_full_file(optarg, &arg_key_pem, NULL);
if (r < 0)
return log_error_errno(r, "Failed to read key file: %m");
@@ -932,10 +931,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CERT:
- if (arg_cert_pem) {
- log_error("Certificate file specified twice");
- return -EINVAL;
- }
+ if (arg_cert_pem)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Certificate file specified twice");
r = read_full_file(optarg, &arg_cert_pem, NULL);
if (r < 0)
return log_error_errno(r, "Failed to read certificate file: %m");
@@ -944,18 +942,17 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_TRUST:
#if HAVE_GNUTLS
- if (arg_trust_pem) {
- log_error("CA certificate file specified twice");
- return -EINVAL;
- }
+ if (arg_trust_pem)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "CA certificate file specified twice");
r = read_full_file(optarg, &arg_trust_pem, NULL);
if (r < 0)
return log_error_errno(r, "Failed to read CA certificate file: %m");
assert(arg_trust_pem);
break;
#else
- log_error("Option --trust is not available.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --trust is not available.");
#endif
case 'D':
arg_directory = optarg;
@@ -968,20 +965,17 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
- log_error("This program does not take arguments.");
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program does not take arguments.");
- if (!!arg_key_pem != !!arg_cert_pem) {
- log_error("Certificate and key files must be specified together");
- return -EINVAL;
- }
+ if (!!arg_key_pem != !!arg_cert_pem)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Certificate and key files must be specified together");
- if (arg_trust_pem && !arg_key_pem) {
- log_error("CA certificate can only be used with certificate file");
- return -EINVAL;
- }
+ if (arg_trust_pem && !arg_key_pem)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "CA certificate can only be used with certificate file");
return 1;
}
diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c
index af927046c6..44f3450d87 100644
--- a/src/journal-remote/journal-remote-main.c
+++ b/src/journal-remote/journal-remote-main.c
@@ -494,11 +494,10 @@ static int dispatch_http_event(sd_event_source *event,
assert(d);
r = MHD_run(d->daemon);
- if (r == MHD_NO) {
- log_error("MHD_run failed!");
- // XXX: unregister daemon
- return -EINVAL;
- }
+ if (r == MHD_NO)
+ // FIXME: unregister daemon
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "MHD_run failed!");
if (MHD_get_timeout(d->daemon, &timeout) == MHD_NO)
timeout = ULONG_LONG_MAX;
@@ -570,10 +569,9 @@ static int create_remoteserver(
else
log_debug("Received %d descriptors", n);
- if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n) {
- log_error("Received fewer sockets than expected");
- return -EBADFD;
- }
+ if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADFD),
+ "Received fewer sockets than expected");
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
if (sd_is_socket(fd, AF_UNSPEC, 0, true)) {
@@ -595,15 +593,12 @@ static int create_remoteserver(
log_debug("Received a connection socket (fd:%d) from %s", fd, hostname);
r = journal_remote_add_source(s, fd, hostname, true);
- } else {
- log_error("Unknown socket passed on fd:%d", fd);
-
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown socket passed on fd:%d", fd);
if (r < 0)
- return log_error_errno(r, "Failed to register socket (fd:%d): %m",
- fd);
+ return log_error_errno(r, "Failed to register socket (fd:%d): %m", fd);
}
if (arg_getter) {
@@ -692,10 +687,9 @@ static int create_remoteserver(
return r;
}
- if (s->active == 0) {
- log_error("Zero sources specified");
- return -EINVAL;
- }
+ if (s->active == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Zero sources specified");
if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE) {
/* In this case we know what the writer will be
@@ -830,37 +824,33 @@ static int parse_argv(int argc, char *argv[]) {
return version();
case ARG_URL:
- if (arg_url) {
- log_error("cannot currently set more than one --url");
- return -EINVAL;
- }
+ if (arg_url)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot currently set more than one --url");
arg_url = optarg;
break;
case ARG_GETTER:
- if (arg_getter) {
- log_error("cannot currently use --getter more than once");
- return -EINVAL;
- }
+ if (arg_getter)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot currently use --getter more than once");
arg_getter = optarg;
break;
case ARG_LISTEN_RAW:
- if (arg_listen_raw) {
- log_error("cannot currently use --listen-raw more than once");
- return -EINVAL;
- }
+ if (arg_listen_raw)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot currently use --listen-raw more than once");
arg_listen_raw = optarg;
break;
case ARG_LISTEN_HTTP:
- if (arg_listen_http || http_socket >= 0) {
- log_error("cannot currently use --listen-http more than once");
- return -EINVAL;
- }
+ if (arg_listen_http || http_socket >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot currently use --listen-http more than once");
r = negative_fd(optarg);
if (r >= 0)
@@ -870,10 +860,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_LISTEN_HTTPS:
- if (arg_listen_https || https_socket >= 0) {
- log_error("cannot currently use --listen-https more than once");
- return -EINVAL;
- }
+ if (arg_listen_https || https_socket >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot currently use --listen-https more than once");
r = negative_fd(optarg);
if (r >= 0)
@@ -884,10 +873,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_KEY:
- if (arg_key) {
- log_error("Key file specified twice");
- return -EINVAL;
- }
+ if (arg_key)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Key file specified twice");
arg_key = strdup(optarg);
if (!arg_key)
@@ -896,10 +884,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CERT:
- if (arg_cert) {
- log_error("Certificate file specified twice");
- return -EINVAL;
- }
+ if (arg_cert)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Certificate file specified twice");
arg_cert = strdup(optarg);
if (!arg_cert)
@@ -908,10 +895,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_TRUST:
- if (arg_trust || arg_trust_all) {
- log_error("Confusing trusted CA configuration");
- return -EINVAL;
- }
+ if (arg_trust || arg_trust_all)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Confusing trusted CA configuration");
if (streq(optarg, "all"))
arg_trust_all = true;
@@ -921,37 +907,34 @@ static int parse_argv(int argc, char *argv[]) {
if (!arg_trust)
return log_oom();
#else
- log_error("Option --trust is not available.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --trust is not available.");
#endif
}
break;
case 'o':
- if (arg_output) {
- log_error("cannot use --output/-o more than once");
- return -EINVAL;
- }
+ if (arg_output)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use --output/-o more than once");
arg_output = optarg;
break;
case ARG_SPLIT_MODE:
arg_split_mode = journal_write_split_mode_from_string(optarg);
- if (arg_split_mode == _JOURNAL_WRITE_SPLIT_INVALID) {
- log_error("Invalid split mode: %s", optarg);
- return -EINVAL;
- }
+ if (arg_split_mode == _JOURNAL_WRITE_SPLIT_INVALID)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid split mode: %s", optarg);
break;
case ARG_COMPRESS:
if (optarg) {
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("Failed to parse --compress= parameter.");
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --compress= parameter.");
arg_compress = !!r;
} else
@@ -962,10 +945,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_SEAL:
if (optarg) {
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("Failed to parse --seal= parameter.");
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --seal= parameter.");
arg_seal = !!r;
} else
@@ -982,7 +964,6 @@ static int parse_argv(int argc, char *argv[]) {
r = extract_first_word(&p, &word, ",", 0);
if (r < 0)
return log_error_errno(r, "Failed to parse --gnutls-log= argument: %m");
-
if (r == 0)
break;
@@ -993,8 +974,8 @@ static int parse_argv(int argc, char *argv[]) {
}
break;
#else
- log_error("Option --gnutls-log is not available.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --gnutls-log is not available.");
#endif
}
@@ -1013,21 +994,18 @@ static int parse_argv(int argc, char *argv[]) {
|| arg_listen_raw
|| arg_listen_http || arg_listen_https
|| sd_listen_fds(false) > 0;
- if (type_a && type_b) {
- log_error("Cannot use file input or --getter with "
- "--arg-listen-... or socket activation.");
- return -EINVAL;
- }
+ if (type_a && type_b)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot use file input or --getter with "
+ "--arg-listen-... or socket activation.");
if (type_a) {
- if (!arg_output) {
- log_error("Option --output must be specified with file input or --getter.");
- return -EINVAL;
- }
+ if (!arg_output)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --output must be specified with file input or --getter.");
- if (!IN_SET(arg_split_mode, JOURNAL_WRITE_SPLIT_NONE, _JOURNAL_WRITE_SPLIT_INVALID)) {
- log_error("For active sources, only --split-mode=none is allowed.");
- return -EINVAL;
- }
+ if (!IN_SET(arg_split_mode, JOURNAL_WRITE_SPLIT_NONE, _JOURNAL_WRITE_SPLIT_INVALID))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "For active sources, only --split-mode=none is allowed.");
arg_split_mode = JOURNAL_WRITE_SPLIT_NONE;
}
@@ -1036,21 +1014,18 @@ static int parse_argv(int argc, char *argv[]) {
arg_split_mode = JOURNAL_WRITE_SPLIT_HOST;
if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE && arg_output) {
- if (is_dir(arg_output, true) > 0) {
- log_error("For SplitMode=none, output must be a file.");
- return -EINVAL;
- }
- if (!endswith(arg_output, ".journal")) {
- log_error("For SplitMode=none, output file name must end with .journal.");
- return -EINVAL;
- }
+ if (is_dir(arg_output, true) > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "For SplitMode=none, output must be a file.");
+ if (!endswith(arg_output, ".journal"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "For SplitMode=none, output file name must end with .journal.");
}
if (arg_split_mode == JOURNAL_WRITE_SPLIT_HOST
- && arg_output && is_dir(arg_output, true) <= 0) {
- log_error("For SplitMode=host, output must be a directory.");
- return -EINVAL;
- }
+ && arg_output && is_dir(arg_output, true) <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "For SplitMode=host, output must be a directory.");
log_debug("Full config: SplitMode=%s Key=%s Cert=%s Trust=%s",
journal_write_split_mode_to_string(arg_split_mode),
@@ -1083,10 +1058,9 @@ static int load_certificates(char **key, char **cert, char **trust) {
arg_trust ?: TRUST_FILE);
}
- if ((arg_listen_raw || arg_listen_http) && *trust) {
- log_error("Option --trust makes all non-HTTPS connections untrusted.");
- return -EINVAL;
- }
+ if ((arg_listen_raw || arg_listen_http) && *trust)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --trust makes all non-HTTPS connections untrusted.");
return 0;
}
diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c
index 205ce182a2..be39f7c047 100644
--- a/src/journal-remote/journal-upload-journal.c
+++ b/src/journal-remote/journal-upload-journal.c
@@ -184,10 +184,9 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
size_t len;
c = memchr(u->field_data, '=', u->field_length);
- if (!c || c == u->field_data) {
- log_error("Invalid field.");
- return -EINVAL;
- }
+ if (!c || c == u->field_data)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid field.");
len = c - (const char*)u->field_data;
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index b9f98cda0a..8b0816ba1f 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -198,10 +198,9 @@ int start_upload(Uploader *u,
CURL *curl;
curl = curl_easy_init();
- if (!curl) {
- log_error("Call to curl_easy_init failed.");
- return -ENOSR;
- }
+ if (!curl)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOSR),
+ "Call to curl_easy_init failed.");
/* tell it to POST to the URL */
easy_setopt(curl, CURLOPT_POST, 1L,
@@ -265,11 +264,10 @@ int start_upload(Uploader *u,
/* upload to this place */
code = curl_easy_setopt(u->easy, CURLOPT_URL, u->url);
- if (code) {
- log_error("curl_easy_setopt CURLOPT_URL failed: %s",
- curl_easy_strerror(code));
- return -EXFULL;
- }
+ if (code)
+ return log_error_errno(SYNTHETIC_ERRNO(EXFULL),
+ "curl_easy_setopt CURLOPT_URL failed: %s",
+ curl_easy_strerror(code));
u->uploading = true;
@@ -488,21 +486,20 @@ static int perform_upload(Uploader *u) {
}
code = curl_easy_getinfo(u->easy, CURLINFO_RESPONSE_CODE, &status);
- if (code) {
- log_error("Failed to retrieve response code: %s",
- curl_easy_strerror(code));
- return -EUCLEAN;
- }
-
- if (status >= 300) {
- log_error("Upload to %s failed with code %ld: %s",
- u->url, status, strna(u->answer));
- return -EIO;
- } else if (status < 200) {
- log_error("Upload to %s finished with unexpected code %ld: %s",
- u->url, status, strna(u->answer));
- return -EIO;
- } else
+ if (code)
+ return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
+ "Failed to retrieve response code: %s",
+ curl_easy_strerror(code));
+
+ if (status >= 300)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Upload to %s failed with code %ld: %s",
+ u->url, status, strna(u->answer));
+ else if (status < 200)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Upload to %s finished with unexpected code %ld: %s",
+ u->url, status, strna(u->answer));
+ else
log_debug("Upload finished successfully with code %ld: %s",
status, strna(u->answer));
@@ -615,37 +612,33 @@ static int parse_argv(int argc, char *argv[]) {
return version();
case 'u':
- if (arg_url) {
- log_error("cannot use more than one --url");
- return -EINVAL;
- }
+ if (arg_url)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --url");
arg_url = optarg;
break;
case ARG_KEY:
- if (arg_key) {
- log_error("cannot use more than one --key");
- return -EINVAL;
- }
+ if (arg_key)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --key");
arg_key = optarg;
break;
case ARG_CERT:
- if (arg_cert) {
- log_error("cannot use more than one --cert");
- return -EINVAL;
- }
+ if (arg_cert)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --cert");
arg_cert = optarg;
break;
case ARG_TRUST:
- if (arg_trust) {
- log_error("cannot use more than one --trust");
- return -EINVAL;
- }
+ if (arg_trust)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --trust");
arg_trust = optarg;
break;
@@ -663,19 +656,17 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'M':
- if (arg_machine) {
- log_error("cannot use more than one --machine/-M");
- return -EINVAL;
- }
+ if (arg_machine)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --machine/-M");
arg_machine = optarg;
break;
case 'D':
- if (arg_directory) {
- log_error("cannot use more than one --directory/-D");
- return -EINVAL;
- }
+ if (arg_directory)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --directory/-D");
arg_directory = optarg;
break;
@@ -687,19 +678,17 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CURSOR:
- if (arg_cursor) {
- log_error("cannot use more than one --cursor/--after-cursor");
- return -EINVAL;
- }
+ if (arg_cursor)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --cursor/--after-cursor");
arg_cursor = optarg;
break;
case ARG_AFTER_CURSOR:
- if (arg_cursor) {
- log_error("cannot use more than one --cursor/--after-cursor");
- return -EINVAL;
- }
+ if (arg_cursor)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "cannot use more than one --cursor/--after-cursor");
arg_cursor = optarg;
arg_after_cursor = true;
@@ -708,10 +697,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_FOLLOW:
if (optarg) {
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("Failed to parse --follow= parameter.");
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --follow= parameter.");
arg_follow = !!r;
} else
@@ -724,31 +712,30 @@ static int parse_argv(int argc, char *argv[]) {
break;
case '?':
- log_error("Unknown option %s.", argv[optind-1]);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown option %s.",
+ argv[optind - 1]);
case ':':
- log_error("Missing argument to %s.", argv[optind-1]);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Missing argument to %s.",
+ argv[optind - 1]);
default:
assert_not_reached("Unhandled option code.");
}
- if (!arg_url) {
- log_error("Required --url/-u option missing.");
- return -EINVAL;
- }
+ if (!arg_url)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Required --url/-u option missing.");
- if (!!arg_key != !!arg_cert) {
- log_error("Options --key and --cert must be used together.");
- return -EINVAL;
- }
+ if (!!arg_key != !!arg_cert)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Options --key and --cert must be used together.");
- if (optind < argc && (arg_directory || arg_file || arg_machine || arg_journal_type)) {
- log_error("Input arguments make no sense with journal input.");
- return -EINVAL;
- }
+ if (optind < argc && (arg_directory || arg_file || arg_machine || arg_journal_type))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Input arguments make no sense with journal input.");
return 1;
}
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c
index 34dd9ea555..adf40b5abd 100644
--- a/src/journal-remote/microhttpd-util.c
+++ b/src/journal-remote/microhttpd-util.c
@@ -153,8 +153,7 @@ static int log_enable_gnutls_category(const char *cat) {
log_reset_gnutls_level();
return 0;
}
- log_error("No such log category: %s", cat);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No such log category: %s", cat);
}
int setup_gnutls_logger(char **categories) {
@@ -206,10 +205,9 @@ static int get_client_cert(gnutls_session_t session, gnutls_x509_crt_t *client_c
assert(client_cert);
pcert = gnutls_certificate_get_peers(session, &listsize);
- if (!pcert || !listsize) {
- log_error("Failed to retrieve certificate chain");
- return -EINVAL;
- }
+ if (!pcert || !listsize)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to retrieve certificate chain");
r = gnutls_x509_crt_init(&cert);
if (r < 0) {
diff --git a/src/journal/cat.c b/src/journal/cat.c
index 570515783a..a84350fbc9 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -86,10 +86,9 @@ static int parse_argv(int argc, char *argv[]) {
case 'p':
arg_priority = log_level_from_string(optarg);
- if (arg_priority < 0) {
- log_error("Failed to parse priority value.");
- return -EINVAL;
- }
+ if (arg_priority < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse priority value.");
break;
case ARG_LEVEL_PREFIX: {
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index 3c8f2f92be..63d27337b5 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -217,14 +217,14 @@ static int catalog_entry_lang(const char* filename, int line,
size_t c;
c = strlen(t);
- if (c == 0) {
- log_error("[%s:%u] Language too short.", filename, line);
- return -EINVAL;
- }
- if (c > 31) {
- log_error("[%s:%u] language too long.", filename, line);
- return -EINVAL;
- }
+ if (c == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "[%s:%u] Language too short.",
+ filename, line);
+ if (c > 31)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "[%s:%u] language too long.", filename,
+ line);
if (deflang) {
if (streq(t, deflang)) {
@@ -304,10 +304,11 @@ int catalog_import_file(Hashmap *h, const char *path) {
if (sd_id128_from_string(line + 2 + 1, &jd) >= 0) {
if (got_id) {
- if (payload_size == 0) {
- log_error("[%s:%u] No payload text.", path, n);
- return -EINVAL;
- }
+ if (payload_size == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "[%s:%u] No payload text.",
+ path,
+ n);
r = finish_item(h, id, lang ?: deflang, payload, payload_size);
if (r < 0)
@@ -335,10 +336,10 @@ int catalog_import_file(Hashmap *h, const char *path) {
}
/* Payload */
- if (!got_id) {
- log_error("[%s:%u] Got payload before ID.", path, n);
- return -EINVAL;
- }
+ if (!got_id)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "[%s:%u] Got payload before ID.",
+ path, n);
line_len = strlen(line);
if (!GREEDY_REALLOC(payload, payload_allocated,
@@ -356,10 +357,10 @@ int catalog_import_file(Hashmap *h, const char *path) {
}
if (got_id) {
- if (payload_size == 0) {
- log_error("[%s:%u] No payload text.", path, n);
- return -EINVAL;
- }
+ if (payload_size == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "[%s:%u] No payload text.",
+ path, n);
r = finish_item(h, id, lang ?: deflang, payload, payload_size);
if (r < 0)
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 1174a52a66..3e5733da6b 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -566,13 +566,14 @@ static int journal_file_verify_header(JournalFile *f) {
if (state == STATE_ARCHIVED)
return -ESHUTDOWN; /* Already archived */
- else if (state == STATE_ONLINE) {
- log_debug("Journal file %s is already online. Assuming unclean closing.", f->path);
- return -EBUSY;
- } else if (state != STATE_OFFLINE) {
- log_debug("Journal file %s has unknown state %i.", f->path, state);
- return -EBUSY;
- }
+ else if (state == STATE_ONLINE)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
+ "Journal file %s is already online. Assuming unclean closing.",
+ f->path);
+ else if (state != STATE_OFFLINE)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
+ "Journal file %s has unknown state %i.",
+ f->path, state);
if (f->header->field_hash_table_size == 0 || f->header->data_hash_table_size == 0)
return -EBADMSG;
@@ -580,10 +581,10 @@ static int journal_file_verify_header(JournalFile *f) {
/* Don't permit appending to files from the future. Because otherwise the realtime timestamps wouldn't
* be strictly ordered in the entries in the file anymore, and we can't have that since it breaks
* bisection. */
- if (le64toh(f->header->tail_entry_realtime) > now(CLOCK_REALTIME)) {
- log_debug("Journal file %s is from the future, refusing to append new data to it that'd be older.", f->path);
- return -ETXTBSY;
- }
+ if (le64toh(f->header->tail_entry_realtime) > now(CLOCK_REALTIME))
+ return log_debug_errno(SYNTHETIC_ERRNO(ETXTBSY),
+ "Journal file %s is from the future, refusing to append new data to it that'd be older.",
+ f->path);
}
f->compress_xz = JOURNAL_HEADER_COMPRESSED_XZ(f->header);
@@ -747,153 +748,124 @@ static int journal_file_check_object(JournalFile *f, uint64_t offset, Object *o)
switch (o->object.type) {
case OBJECT_DATA: {
- if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0)) {
- log_debug("Bad n_entries: %"PRIu64": %"PRIu64,
- le64toh(o->data.n_entries), offset);
- return -EBADMSG;
- }
-
- if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0) {
- log_debug("Bad object size (<= %zu): %"PRIu64": %"PRIu64,
- offsetof(DataObject, payload),
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
+ if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Bad n_entries: %" PRIu64 ": %" PRIu64,
+ le64toh(o->data.n_entries),
+ offset);
+
+ if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Bad object size (<= %zu): %" PRIu64 ": %" PRIu64,
+ offsetof(DataObject, payload),
+ le64toh(o->object.size),
+ offset);
if (!VALID64(le64toh(o->data.next_hash_offset)) ||
!VALID64(le64toh(o->data.next_field_offset)) ||
!VALID64(le64toh(o->data.entry_offset)) ||
- !VALID64(le64toh(o->data.entry_array_offset))) {
- log_debug("Invalid offset, next_hash_offset="OFSfmt", next_field_offset="OFSfmt
- ", entry_offset="OFSfmt", entry_array_offset="OFSfmt": %"PRIu64,
- le64toh(o->data.next_hash_offset),
- le64toh(o->data.next_field_offset),
- le64toh(o->data.entry_offset),
- le64toh(o->data.entry_array_offset),
- offset);
- return -EBADMSG;
- }
+ !VALID64(le64toh(o->data.entry_array_offset)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid offset, next_hash_offset=" OFSfmt ", next_field_offset=" OFSfmt ", entry_offset=" OFSfmt ", entry_array_offset=" OFSfmt ": %" PRIu64,
+ le64toh(o->data.next_hash_offset),
+ le64toh(o->data.next_field_offset),
+ le64toh(o->data.entry_offset),
+ le64toh(o->data.entry_array_offset),
+ offset);
break;
}
case OBJECT_FIELD:
- if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0) {
- log_debug(
- "Bad field size (<= %zu): %"PRIu64": %"PRIu64,
- offsetof(FieldObject, payload),
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
+ if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Bad field size (<= %zu): %" PRIu64 ": %" PRIu64,
+ offsetof(FieldObject, payload),
+ le64toh(o->object.size),
+ offset);
if (!VALID64(le64toh(o->field.next_hash_offset)) ||
- !VALID64(le64toh(o->field.head_data_offset))) {
- log_debug(
- "Invalid offset, next_hash_offset="OFSfmt
- ", head_data_offset="OFSfmt": %"PRIu64,
- le64toh(o->field.next_hash_offset),
- le64toh(o->field.head_data_offset),
- offset);
- return -EBADMSG;
- }
+ !VALID64(le64toh(o->field.head_data_offset)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid offset, next_hash_offset=" OFSfmt ", head_data_offset=" OFSfmt ": %" PRIu64,
+ le64toh(o->field.next_hash_offset),
+ le64toh(o->field.head_data_offset),
+ offset);
break;
case OBJECT_ENTRY:
- if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0) {
- log_debug(
- "Bad entry size (<= %zu): %"PRIu64": %"PRIu64,
- offsetof(EntryObject, items),
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
-
- if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0) {
- log_debug(
- "Invalid number items in entry: %"PRIu64": %"PRIu64,
- (le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem),
- offset);
- return -EBADMSG;
- }
-
- if (le64toh(o->entry.seqnum) <= 0) {
- log_debug(
- "Invalid entry seqnum: %"PRIx64": %"PRIu64,
- le64toh(o->entry.seqnum),
- offset);
- return -EBADMSG;
- }
-
- if (!VALID_REALTIME(le64toh(o->entry.realtime))) {
- log_debug(
- "Invalid entry realtime timestamp: %"PRIu64": %"PRIu64,
- le64toh(o->entry.realtime),
- offset);
- return -EBADMSG;
- }
-
- if (!VALID_MONOTONIC(le64toh(o->entry.monotonic))) {
- log_debug(
- "Invalid entry monotonic timestamp: %"PRIu64": %"PRIu64,
- le64toh(o->entry.monotonic),
- offset);
- return -EBADMSG;
- }
+ if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Bad entry size (<= %zu): %" PRIu64 ": %" PRIu64,
+ offsetof(EntryObject, items),
+ le64toh(o->object.size),
+ offset);
+
+ if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid number items in entry: %" PRIu64 ": %" PRIu64,
+ (le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem),
+ offset);
+
+ if (le64toh(o->entry.seqnum) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid entry seqnum: %" PRIx64 ": %" PRIu64,
+ le64toh(o->entry.seqnum),
+ offset);
+
+ if (!VALID_REALTIME(le64toh(o->entry.realtime)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid entry realtime timestamp: %" PRIu64 ": %" PRIu64,
+ le64toh(o->entry.realtime),
+ offset);
+
+ if (!VALID_MONOTONIC(le64toh(o->entry.monotonic)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid entry monotonic timestamp: %" PRIu64 ": %" PRIu64,
+ le64toh(o->entry.monotonic),
+ offset);
break;
case OBJECT_DATA_HASH_TABLE:
case OBJECT_FIELD_HASH_TABLE:
if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) % sizeof(HashItem) != 0 ||
- (le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0) {
- log_debug(
- "Invalid %s hash table size: %"PRIu64": %"PRIu64,
- o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field",
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
+ (le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid %s hash table size: %" PRIu64 ": %" PRIu64,
+ o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field",
+ le64toh(o->object.size),
+ offset);
break;
case OBJECT_ENTRY_ARRAY:
if ((le64toh(o->object.size) - offsetof(EntryArrayObject, items)) % sizeof(le64_t) != 0 ||
- (le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0) {
- log_debug(
- "Invalid object entry array size: %"PRIu64": %"PRIu64,
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
-
- if (!VALID64(le64toh(o->entry_array.next_entry_array_offset))) {
- log_debug(
- "Invalid object entry array next_entry_array_offset: "OFSfmt": %"PRIu64,
- le64toh(o->entry_array.next_entry_array_offset),
- offset);
- return -EBADMSG;
- }
+ (le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid object entry array size: %" PRIu64 ": %" PRIu64,
+ le64toh(o->object.size),
+ offset);
+
+ if (!VALID64(le64toh(o->entry_array.next_entry_array_offset)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid object entry array next_entry_array_offset: " OFSfmt ": %" PRIu64,
+ le64toh(o->entry_array.next_entry_array_offset),
+ offset);
break;
case OBJECT_TAG:
- if (le64toh(o->object.size) != sizeof(TagObject)) {
- log_debug(
- "Invalid object tag size: %"PRIu64": %"PRIu64,
- le64toh(o->object.size),
- offset);
- return -EBADMSG;
- }
+ if (le64toh(o->object.size) != sizeof(TagObject))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid object tag size: %" PRIu64 ": %" PRIu64,
+ le64toh(o->object.size),
+ offset);
- if (!VALID_EPOCH(le64toh(o->tag.epoch))) {
- log_debug(
- "Invalid object tag epoch: %"PRIu64": %"PRIu64,
- le64toh(o->tag.epoch),
- offset);
- return -EBADMSG;
- }
+ if (!VALID_EPOCH(le64toh(o->tag.epoch)))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid object tag epoch: %" PRIu64 ": %" PRIu64,
+ le64toh(o->tag.epoch), offset);
break;
}
@@ -912,16 +884,16 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
assert(ret);
/* Objects may only be located at multiple of 64 bit */
- if (!VALID64(offset)) {
- log_debug("Attempt to move to object at non-64bit boundary: %" PRIu64, offset);
- return -EBADMSG;
- }
+ if (!VALID64(offset))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to object at non-64bit boundary: %" PRIu64,
+ offset);
/* Object may not be located in the file header */
- if (offset < le64toh(f->header->header_size)) {
- log_debug("Attempt to move to object located in file header: %" PRIu64, offset);
- return -EBADMSG;
- }
+ if (offset < le64toh(f->header->header_size))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to object located in file header: %" PRIu64,
+ offset);
r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t, &tsize);
if (r < 0)
@@ -930,29 +902,29 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
o = (Object*) t;
s = le64toh(o->object.size);
- if (s == 0) {
- log_debug("Attempt to move to uninitialized object: %" PRIu64, offset);
- return -EBADMSG;
- }
- if (s < sizeof(ObjectHeader)) {
- log_debug("Attempt to move to overly short object: %" PRIu64, offset);
- return -EBADMSG;
- }
-
- if (o->object.type <= OBJECT_UNUSED) {
- log_debug("Attempt to move to object with invalid type: %" PRIu64, offset);
- return -EBADMSG;
- }
-
- if (s < minimum_header_size(o)) {
- log_debug("Attempt to move to truncated object: %" PRIu64, offset);
- return -EBADMSG;
- }
-
- if (type > OBJECT_UNUSED && o->object.type != type) {
- log_debug("Attempt to move to object of unexpected type: %" PRIu64, offset);
- return -EBADMSG;
- }
+ if (s == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to uninitialized object: %" PRIu64,
+ offset);
+ if (s < sizeof(ObjectHeader))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to overly short object: %" PRIu64,
+ offset);
+
+ if (o->object.type <= OBJECT_UNUSED)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to object with invalid type: %" PRIu64,
+ offset);
+
+ if (s < minimum_header_size(o))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to truncated object: %" PRIu64,
+ offset);
+
+ if (type > OBJECT_UNUSED && o->object.type != type)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Attempt to move to object of unexpected type: %" PRIu64,
+ offset);
if (s > tsize) {
r = journal_file_move_to(f, type, false, offset, s, &t, NULL);
@@ -1953,14 +1925,14 @@ int journal_file_append_entry(
assert(iovec || n_iovec == 0);
if (ts) {
- if (!VALID_REALTIME(ts->realtime)) {
- log_debug("Invalid realtime timestamp %"PRIu64", refusing entry.", ts->realtime);
- return -EBADMSG;
- }
- if (!VALID_MONOTONIC(ts->monotonic)) {
- log_debug("Invalid monotomic timestamp %"PRIu64", refusing entry.", ts->monotonic);
- return -EBADMSG;
- }
+ if (!VALID_REALTIME(ts->realtime))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid realtime timestamp %" PRIu64 ", refusing entry.",
+ ts->realtime);
+ if (!VALID_MONOTONIC(ts->monotonic))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid monotomic timestamp %" PRIu64 ", refusing entry.",
+ ts->monotonic);
} else {
dual_timestamp_get(&_ts);
ts = &_ts;
@@ -2744,10 +2716,10 @@ int journal_file_next_entry(
}
/* Ensure our array is properly ordered. */
- if (p > 0 && !check_properly_ordered(ofs, p, direction)) {
- log_debug("%s: entry array not properly ordered at entry %" PRIu64, f->path, i);
- return -EBADMSG;
- }
+ if (p > 0 && !check_properly_ordered(ofs, p, direction))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s: entry array not properly ordered at entry %" PRIu64,
+ f->path, i);
if (offset)
*offset = ofs;
@@ -2820,10 +2792,10 @@ int journal_file_next_entry_for_data(
}
/* Ensure our array is properly ordered. */
- if (p > 0 && check_properly_ordered(ofs, p, direction)) {
- log_debug("%s data entry array not properly ordered at entry %" PRIu64, f->path, i);
- return -EBADMSG;
- }
+ if (p > 0 && check_properly_ordered(ofs, p, direction))
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s data entry array not properly ordered at entry %" PRIu64,
+ f->path, i);
if (offset)
*offset = ofs;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index a2c812ba57..4fe6ae7367 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -85,10 +85,9 @@ static int pattern_compile(const char *pattern, unsigned flags, pcre2_code **out
r = pcre2_get_error_message(errorcode, buf, sizeof buf);
- log_error("Bad pattern \"%s\": %s",
- pattern,
- r < 0 ? "unknown error" : (char*) buf);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Bad pattern \"%s\": %s", pattern,
+ r < 0 ? "unknown error" : (char *)buf);
}
*out = p;
@@ -1070,10 +1069,10 @@ static int add_matches(sd_journal *j, char **args) {
r = add_matches_for_device(j, p);
if (r < 0)
return r;
- } else {
- log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "File is neither a device node, nor regular file, nor executable: %s",
+ *i);
have_term = true;
} else {
@@ -1085,10 +1084,9 @@ static int add_matches(sd_journal *j, char **args) {
return log_error_errno(r, "Failed to add match '%s': %m", *i);
}
- if (!strv_isempty(args) && !have_term) {
- log_error("\"+\" can only be used between terms");
- return -EINVAL;
- }
+ if (!strv_isempty(args) && !have_term)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "\"+\" can only be used between terms");
return 0;
}
@@ -1179,10 +1177,9 @@ static int discover_next_boot(sd_journal *j,
r = sd_journal_previous(j);
if (r < 0)
return r;
- else if (r == 0) {
- log_debug("Whoopsie! We found a boot ID but can't read its last entry.");
- return -ENODATA; /* This shouldn't happen. We just came from this very boot ID. */
- }
+ else if (r == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENODATA),
+ "Whoopsie! We found a boot ID but can't read its last entry."); /* This shouldn't happen. We just came from this very boot ID. */
r = sd_journal_get_realtime_usec(j, &next_boot->last);
if (r < 0)
@@ -1833,8 +1830,8 @@ finish:
return r;
#else
- log_error("Forward-secure sealing not available.");
- return -EOPNOTSUPP;
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Forward-secure sealing not available.");
#endif
}
@@ -2066,10 +2063,9 @@ static int wait_for_change(sd_journal *j, int poll_fd) {
return log_error_errno(errno, "Couldn't wait for journal event: %m");
}
- if (pollfds[1].revents & (POLLHUP|POLLERR)) { /* STDOUT has been closed? */
- log_debug("Standard output has been closed.");
- return -ECANCELED;
- }
+ if (pollfds[1].revents & (POLLHUP|POLLERR)) /* STDOUT has been closed? */
+ return log_debug_errno(SYNTHETIC_ERRNO(ECANCELED),
+ "Standard output has been closed.");
r = sd_journal_process(j);
if (r < 0)
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index cd89886414..9a5e7f615f 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1247,10 +1247,10 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
assert(s);
assert(fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd);
- if (revents != EPOLLIN) {
- log_error("Got invalid event from epoll for datagram fd: %"PRIx32, revents);
- return -EIO;
- }
+ if (revents != EPOLLIN)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Got invalid event from epoll for datagram fd: %" PRIx32,
+ revents);
/* Try to get the right size, if we can. (Not all sockets support SIOCINQ, hence we just try, but don't rely on
* it.) */
@@ -1884,38 +1884,34 @@ int server_init(Server *s) {
if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/socket", 0) > 0) {
- if (s->native_fd >= 0) {
- log_error("Too many native sockets passed.");
- return -EINVAL;
- }
+ if (s->native_fd >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many native sockets passed.");
s->native_fd = fd;
} else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) {
- if (s->stdout_fd >= 0) {
- log_error("Too many stdout sockets passed.");
- return -EINVAL;
- }
+ if (s->stdout_fd >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many stdout sockets passed.");
s->stdout_fd = fd;
} else if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/dev/log", 0) > 0 ||
sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/dev-log", 0) > 0) {
- if (s->syslog_fd >= 0) {
- log_error("Too many /dev/log sockets passed.");
- return -EINVAL;
- }
+ if (s->syslog_fd >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many /dev/log sockets passed.");
s->syslog_fd = fd;
} else if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
- if (s->audit_fd >= 0) {
- log_error("Too many audit sockets passed.");
- return -EINVAL;
- }
+ if (s->audit_fd >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many audit sockets passed.");
s->audit_fd = fd;
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index e4df814cc7..ebe49850f5 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -596,10 +596,10 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
assert(s);
- if (revents != EPOLLIN) {
- log_error("Got invalid event from epoll for stdout server fd: %"PRIx32, revents);
- return -EIO;
- }
+ if (revents != EPOLLIN)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Got invalid event from epoll for stdout server fd: %" PRIx32,
+ revents);
fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (fd < 0) {
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 1edabbde72..a81e0e94c7 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -2825,31 +2825,30 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
return r;
/* Let's do the type check by hand, since we used 0 context above. */
- if (o->object.type != OBJECT_DATA) {
- log_debug("%s:offset " OFSfmt ": object has type %d, expected %d",
- j->unique_file->path, j->unique_offset,
- o->object.type, OBJECT_DATA);
- return -EBADMSG;
- }
+ if (o->object.type != OBJECT_DATA)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s:offset " OFSfmt ": object has type %d, expected %d",
+ j->unique_file->path,
+ j->unique_offset,
+ o->object.type, OBJECT_DATA);
r = return_data(j, j->unique_file, o, &odata, &ol);
if (r < 0)
return r;
/* Check if we have at least the field name and "=". */
- if (ol <= k) {
- log_debug("%s:offset " OFSfmt ": object has size %zu, expected at least %zu",
- j->unique_file->path, j->unique_offset,
- ol, k + 1);
- return -EBADMSG;
- }
-
- if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=') {
- log_debug("%s:offset " OFSfmt ": object does not start with \"%s=\"",
- j->unique_file->path, j->unique_offset,
- j->unique_field);
- return -EBADMSG;
- }
+ if (ol <= k)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s:offset " OFSfmt ": object has size %zu, expected at least %zu",
+ j->unique_file->path,
+ j->unique_offset, ol, k + 1);
+
+ if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=')
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s:offset " OFSfmt ": object does not start with \"%s=\"",
+ j->unique_file->path,
+ j->unique_offset,
+ j->unique_field);
/* OK, now let's see if we already returned this data
* object by checking if it exists in the earlier
@@ -2980,10 +2979,11 @@ _public_ int sd_journal_enumerate_fields(sd_journal *j, const char **field) {
return r;
/* Because we used OBJECT_UNUSED above, we need to do our type check manually */
- if (o->object.type != OBJECT_FIELD) {
- log_debug("%s:offset " OFSfmt ": object has type %i, expected %i", f->path, j->fields_offset, o->object.type, OBJECT_FIELD);
- return -EBADMSG;
- }
+ if (o->object.type != OBJECT_FIELD)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "%s:offset " OFSfmt ": object has type %i, expected %i",
+ f->path, j->fields_offset,
+ o->object.type, OBJECT_FIELD);
sz = le64toh(o->object.size) - offsetof(Object, field.payload);
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index d29cd06cb1..ad5f8e267a 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -106,70 +106,62 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, ui
/* IP */
- if (packet->ip.version != IPVERSION) {
- log_debug("ignoring packet: not IPv4");
- return -EINVAL;
- }
+ if (packet->ip.version != IPVERSION)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: not IPv4");
- if (packet->ip.ihl < 5) {
- log_debug("ignoring packet: IPv4 IHL (%u words) invalid",
- packet->ip.ihl);
- return -EINVAL;
- }
+ if (packet->ip.ihl < 5)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: IPv4 IHL (%u words) invalid",
+ packet->ip.ihl);
hdrlen = packet->ip.ihl * 4;
- if (hdrlen < 20) {
- log_debug("ignoring packet: IPv4 IHL (%zu bytes) "
- "smaller than minimum (20 bytes)", hdrlen);
- return -EINVAL;
- }
-
- if (len < hdrlen) {
- log_debug("ignoring packet: packet (%zu bytes) "
- "smaller than expected (%zu) by IP header", len,
- hdrlen);
- return -EINVAL;
- }
+ if (hdrlen < 20)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: IPv4 IHL (%zu bytes) "
+ "smaller than minimum (20 bytes)",
+ hdrlen);
+
+ if (len < hdrlen)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: packet (%zu bytes) "
+ "smaller than expected (%zu) by IP header",
+ len, hdrlen);
/* UDP */
- if (packet->ip.protocol != IPPROTO_UDP) {
- log_debug("ignoring packet: not UDP");
- return -EINVAL;
- }
+ if (packet->ip.protocol != IPPROTO_UDP)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: not UDP");
- if (len < hdrlen + be16toh(packet->udp.len)) {
- log_debug("ignoring packet: packet (%zu bytes) "
- "smaller than expected (%zu) by UDP header", len,
- hdrlen + be16toh(packet->udp.len));
- return -EINVAL;
- }
+ if (len < hdrlen + be16toh(packet->udp.len))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: packet (%zu bytes) "
+ "smaller than expected (%zu) by UDP header",
+ len, hdrlen + be16toh(packet->udp.len));
- if (be16toh(packet->udp.dest) != port) {
- log_debug("ignoring packet: to port %u, which "
- "is not the DHCP client port (%u)",
- be16toh(packet->udp.dest), port);
- return -EINVAL;
- }
+ if (be16toh(packet->udp.dest) != port)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: to port %u, which "
+ "is not the DHCP client port (%u)",
+ be16toh(packet->udp.dest), port);
/* checksums - computing these is relatively expensive, so only do it
if all the other checks have passed
*/
- if (dhcp_packet_checksum((uint8_t*)&packet->ip, hdrlen)) {
- log_debug("ignoring packet: invalid IP checksum");
- return -EINVAL;
- }
+ if (dhcp_packet_checksum((uint8_t*)&packet->ip, hdrlen))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: invalid IP checksum");
if (checksum && packet->udp.check) {
packet->ip.check = packet->udp.len;
packet->ip.ttl = 0;
if (dhcp_packet_checksum((uint8_t*)&packet->ip.ttl,
- be16toh(packet->udp.len) + 12)) {
- log_debug("ignoring packet: invalid UDP checksum");
- return -EINVAL;
- }
+ be16toh(packet->udp.len) + 12))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "ignoring packet: invalid UDP checksum");
}
return 0;
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index bd3e1f3446..e80cfc882a 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -3832,11 +3832,13 @@ static int build_struct_offsets(
x = size - (n_variable * sz);
offset = m->rindex + x;
- if (offset < start) {
- log_debug("For type %s with alignment %zu, message specifies offset %zu which is smaller than previous end %zu + alignment = %zu",
- t, align, offset, previous, start);
- return -EBADMSG;
- }
+ if (offset < start)
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "For type %s with alignment %zu, message specifies offset %zu which is smaller than previous end %zu + alignment = %zu",
+ t, align,
+ offset,
+ previous,
+ start);
} else
/* Fixed size */
offset = start + k;
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 11115400dc..d8df1250fe 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -137,10 +137,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
assert(_syspath);
/* must be a subdirectory of /sys */
- if (!path_startswith(_syspath, "/sys/")) {
- log_debug("sd-device: Syspath '%s' is not a subdirectory of /sys", _syspath);
- return -EINVAL;
- }
+ if (!path_startswith(_syspath, "/sys/"))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "sd-device: Syspath '%s' is not a subdirectory of /sys",
+ _syspath);
if (verify) {
r = chase_symlinks(_syspath, NULL, 0, &syspath);
@@ -159,10 +159,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
return log_debug_errno(r, "sd-device: Failed to chase symlink /sys: %m");
p = path_startswith(syspath, real_sys);
- if (!p) {
- log_debug("sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'", syspath, real_sys);
- return -ENODEV;
- }
+ if (!p)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
+ "sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'",
+ syspath, real_sys);
new_syspath = strjoin("/sys/", p);
if (!new_syspath)
diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c
index 7b497d1ccb..f177c6c09c 100644
--- a/src/libsystemd/sd-netlink/sd-netlink.c
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
@@ -224,10 +224,10 @@ int sd_netlink_send(sd_netlink *nl,
int rtnl_rqueue_make_room(sd_netlink *rtnl) {
assert(rtnl);
- if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX) {
- log_debug("rtnl: exhausted the read queue size (%d)", RTNL_RQUEUE_MAX);
- return -ENOBUFS;
- }
+ if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
+ "rtnl: exhausted the read queue size (%d)",
+ RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue, rtnl->rqueue_allocated, rtnl->rqueue_size + 1))
return -ENOMEM;
@@ -238,10 +238,10 @@ int rtnl_rqueue_make_room(sd_netlink *rtnl) {
int rtnl_rqueue_partial_make_room(sd_netlink *rtnl) {
assert(rtnl);
- if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX) {
- log_debug("rtnl: exhausted the partial read queue size (%d)", RTNL_RQUEUE_MAX);
- return -ENOBUFS;
- }
+ if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
+ "rtnl: exhausted the partial read queue size (%d)",
+ RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue_partial, rtnl->rqueue_partial_allocated,
rtnl->rqueue_partial_size + 1))
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 9d76518bf1..34065a98c7 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -363,10 +363,9 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
return log_oom();
}
- if (strv_isempty(list)) {
- log_error("Couldn't find any entries.");
- return -ENOENT;
- }
+ if (strv_isempty(list))
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "Couldn't find any entries.");
strv_sort(list);
strv_uniq(list);
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index 332cfdbba8..2394c5d937 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -259,10 +259,9 @@ static int parse_argv(int argc, char *argv[]) {
if (arg_action == ACTION_INHIBIT && optind == argc)
arg_action = ACTION_LIST;
- else if (arg_action == ACTION_INHIBIT && optind >= argc) {
- log_error("Missing command line to execute.");
- return -EINVAL;
- }
+ else if (arg_action == ACTION_INHIBIT && optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Missing command line to execute.");
return 1;
}
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 427bb431cf..fb5240d7d3 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -763,10 +763,10 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (!uid_is_valid(uid)) {
- log_error("Invalid user ID: " UID_FMT, uid);
- return -EINVAL;
- }
+ if (!uid_is_valid(uid))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid user ID: " UID_FMT,
+ uid);
bus_print_property_value(name, expected_value, value, UID_FMT, uid);
return 1;
@@ -1419,10 +1419,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'n':
- if (safe_atou(optarg, &arg_lines) < 0) {
- log_error("Failed to parse lines '%s'", optarg);
- return -EINVAL;
- }
+ if (safe_atou(optarg, &arg_lines) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse lines '%s'", optarg);
break;
case 'o':
@@ -1432,10 +1431,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_output = output_mode_from_string(optarg);
- if (arg_output < 0) {
- log_error("Unknown output '%s'.", optarg);
- return -EINVAL;
- }
+ if (arg_output < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown output '%s'.", optarg);
break;
case ARG_NO_PAGER:
@@ -1461,10 +1459,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_signal = signal_from_string(optarg);
- if (arg_signal < 0) {
- log_error("Failed to parse signal string %s.", optarg);
- return -EINVAL;
- }
+ if (arg_signal < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse signal string %s.", optarg);
break;
case 'H':
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 0defa6b9ba..7c9cf05dd7 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -329,10 +329,10 @@ int button_open(Button *b) {
r = button_suitable(b);
if (r < 0)
return log_warning_errno(r, "Failed to determine whether input device is relevant to us: %m");
- if (r == 0) {
- log_debug("Device %s does not expose keys or switches relevant to us, ignoring.", p);
- return -EADDRNOTAVAIL;
- }
+ if (r == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
+ "Device %s does not expose keys or switches relevant to us, ignoring.",
+ p);
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
r = log_error_errno(errno, "Failed to get input name: %m");
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index ec190d1b04..ab4561a555 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1660,10 +1660,10 @@ int bus_manager_shutdown_or_sleep_now_or_later(
if (r < 0)
return r;
- if (!streq(load_state, "loaded")) {
- log_notice("Unit %s is %s, refusing operation.", unit_name, load_state);
- return -EACCES;
- }
+ if (!streq(load_state, "loaded"))
+ return log_notice_errno(SYNTHETIC_ERRNO(EACCES),
+ "Unit %s is %s, refusing operation.",
+ unit_name, load_state);
/* Tell everybody to prepare for shutdown/sleep */
(void) send_prepare_for(m, w, true);
diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c
index 2ec28b2fab..f358524ebc 100644
--- a/src/login/logind-session-device.c
+++ b/src/login/logind-session-device.c
@@ -175,10 +175,9 @@ static int session_device_start(SessionDevice *sd) {
switch (sd->type) {
case DEVICE_TYPE_DRM:
- if (sd->fd < 0) {
- log_error("Failed to re-activate DRM fd, as the fd was lost (maybe logind restart went wrong?)");
- return -EBADF;
- }
+ if (sd->fd < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADF),
+ "Failed to re-activate DRM fd, as the fd was lost (maybe logind restart went wrong?)");
/* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
* keep the device paused. Maybe at some point we have a drmStealMaster(). */
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index e8be1ffbed..576a17a7f0 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -441,10 +441,10 @@ int session_load(Session *s) {
uid_t u;
User *user;
- if (!uid) {
- log_error("UID not specified for session %s", s->id);
- return -ENOENT;
- }
+ if (!uid)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "UID not specified for session %s",
+ s->id);
r = parse_uid(uid, &u);
if (r < 0) {
@@ -453,10 +453,10 @@ int session_load(Session *s) {
}
user = hashmap_get(s->manager->users, UID_TO_PTR(u));
- if (!user) {
- log_error("User of session %s not known.", s->id);
- return -ENOENT;
- }
+ if (!user)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "User of session %s not known.",
+ s->id);
session_set_user(s, user);
}
diff --git a/src/login/logind.c b/src/login/logind.c
index b8530520ef..8d85de9b43 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -824,10 +824,10 @@ static int manager_connect_console(Manager *m) {
* release events immediately.
*/
- if (SIGRTMIN + 1 > SIGRTMAX) {
- log_error("Not enough real-time signals available: %u-%u", SIGRTMIN, SIGRTMAX);
- return -EINVAL;
- }
+ if (SIGRTMIN + 1 > SIGRTMAX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not enough real-time signals available: %u-%u",
+ SIGRTMIN, SIGRTMAX);
assert_se(ignore_signals(SIGRTMIN + 1, -1) >= 0);
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGRTMIN, -1) >= 0);
diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c
index 8a1110491a..edb62a2d30 100644
--- a/src/login/user-runtime-dir.c
+++ b/src/login/user-runtime-dir.c
@@ -175,14 +175,12 @@ static int run(int argc, char *argv[]) {
log_parse_environment();
log_open();
- if (argc != 3) {
- log_error("This program takes two arguments.");
- return -EINVAL;
- }
- if (!STR_IN_SET(argv[1], "start", "stop")) {
- log_error("First argument must be either \"start\" or \"stop\".");
- return -EINVAL;
- }
+ if (argc != 3)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes two arguments.");
+ if (!STR_IN_SET(argv[1], "start", "stop"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "First argument must be either \"start\" or \"stop\".");
r = mac_selinux_init();
if (r < 0)
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index bfadd5881d..1b575d7725 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -97,10 +97,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
- log_error("Extraneous arguments");
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Extraneous arguments");
return 1;
}
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index db768ffff4..094ee9d360 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -1710,10 +1710,9 @@ static int make_service_name(const char *name, char **ret) {
assert(name);
assert(ret);
- if (!machine_name_is_valid(name)) {
- log_error("Invalid machine name %s.", name);
- return -EINVAL;
- }
+ if (!machine_name_is_valid(name))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid machine name %s.", name);
r = unit_name_build("systemd-nspawn", name, ".service", ret);
if (r < 0)
@@ -2837,10 +2836,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'n':
- if (safe_atou(optarg, &arg_lines) < 0) {
- log_error("Failed to parse lines '%s'", optarg);
- return -EINVAL;
- }
+ if (safe_atou(optarg, &arg_lines) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse lines '%s'", optarg);
break;
case 'o':
@@ -2850,10 +2848,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_output = output_mode_from_string(optarg);
- if (arg_output < 0) {
- log_error("Unknown output '%s'.", optarg);
- return -EINVAL;
- }
+ if (arg_output < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown output '%s'.", optarg);
break;
case ARG_NO_PAGER:
@@ -2875,10 +2872,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_signal = signal_from_string(optarg);
- if (arg_signal < 0) {
- log_error("Failed to parse signal string %s.", optarg);
- return -EINVAL;
- }
+ if (arg_signal < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse signal string %s.", optarg);
break;
case ARG_NO_ASK_PASSWORD:
@@ -2914,10 +2910,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_verify = import_verify_from_string(optarg);
- if (arg_verify < 0) {
- log_error("Failed to parse --verify= setting: %s", optarg);
- return -EINVAL;
- }
+ if (arg_verify < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --verify= setting: %s", optarg);
break;
case ARG_FORCE:
@@ -2925,10 +2920,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_FORMAT:
- if (!STR_IN_SET(optarg, "uncompressed", "xz", "gzip", "bzip2")) {
- log_error("Unknown format: %s", optarg);
- return -EINVAL;
- }
+ if (!STR_IN_SET(optarg, "uncompressed", "xz", "gzip", "bzip2"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown format: %s", optarg);
arg_format = optarg;
break;
@@ -2938,10 +2932,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'E':
- if (!env_assignment_is_valid(optarg)) {
- log_error("Environment assignment invalid: %s", optarg);
- return -EINVAL;
- }
+ if (!env_assignment_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Environment assignment invalid: %s", optarg);
r = strv_extend(&arg_setenv, optarg);
if (r < 0)
@@ -2951,13 +2944,12 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NUMBER_IPS:
if (streq(optarg, "all"))
arg_addrs = ALL_IP_ADDRESSES;
- else if (safe_atoi(optarg, &arg_addrs) < 0) {
- log_error("Invalid number of IPs");
- return -EINVAL;
- } else if (arg_addrs < 0) {
- log_error("Number of IPs cannot be negative");
- return -EINVAL;
- }
+ else if (safe_atoi(optarg, &arg_addrs) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid number of IPs");
+ else if (arg_addrs < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Number of IPs cannot be negative");
break;
case '?':
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index 349128c6b7..4d53bc5597 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -309,46 +309,39 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Execution in user context is not supported on non-local systems.");
- return -EINVAL;
- }
+ if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Execution in user context is not supported on non-local systems.");
if (arg_action == ACTION_LIST) {
- if (optind < argc) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
- if (arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Listing devices only supported locally.");
- return -EOPNOTSUPP;
- }
+ if (arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Listing devices only supported locally.");
} else if (arg_action == ACTION_UMOUNT) {
- if (optind >= argc) {
- log_error("At least one argument required.");
- return -EINVAL;
- }
+ if (optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "At least one argument required.");
if (arg_transport != BUS_TRANSPORT_LOCAL) {
int i;
for (i = optind; i < argc; i++)
- if (!path_is_absolute(argv[i]) ) {
- log_error("Only absolute path is supported: %s", argv[i]);
- return -EINVAL;
- }
+ if (!path_is_absolute(argv[i]) )
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Only absolute path is supported: %s", argv[i]);
}
} else {
- if (optind >= argc) {
- log_error("At least one argument required.");
- return -EINVAL;
- }
+ if (optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "At least one argument required.");
- if (argc > optind+2) {
- log_error("At most two arguments required.");
- return -EINVAL;
- }
+ if (argc > optind+2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "At most two arguments required.");
if (arg_mount_type && (fstype_is_api_vfs(arg_mount_type) || fstype_is_network(arg_mount_type))) {
arg_mount_what = strdup(argv[optind]);
@@ -372,10 +365,9 @@ static int parse_argv(int argc, char *argv[]) {
path_simplify(arg_mount_what, false);
- if (!path_is_absolute(arg_mount_what)) {
- log_error("Only absolute path is supported: %s", arg_mount_what);
- return -EINVAL;
- }
+ if (!path_is_absolute(arg_mount_what))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Only absolute path is supported: %s", arg_mount_what);
}
if (argc > optind+1) {
@@ -390,18 +382,16 @@ static int parse_argv(int argc, char *argv[]) {
path_simplify(arg_mount_where, false);
- if (!path_is_absolute(arg_mount_where)) {
- log_error("Only absolute path is supported: %s", arg_mount_where);
- return -EINVAL;
- }
+ if (!path_is_absolute(arg_mount_where))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Only absolute path is supported: %s", arg_mount_where);
}
} else
arg_discover = true;
- if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Automatic mount location discovery is only supported locally.");
- return -EOPNOTSUPP;
- }
+ if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Automatic mount location discovery is only supported locally.");
}
return 1;
@@ -909,15 +899,13 @@ static int stop_mounts(
int r;
- if (path_equal(where, "/")) {
- log_error("Refusing to operate on root directory: %s", where);
- return -EINVAL;
- }
+ if (path_equal(where, "/"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Refusing to operate on root directory: %s", where);
- if (!path_is_normalized(where)) {
- log_error("Path contains non-normalized components: %s", where);
- return -EINVAL;
- }
+ if (!path_is_normalized(where))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path contains non-normalized components: %s", where);
r = stop_mount(bus, where, ".mount");
if (r < 0)
@@ -1164,13 +1152,14 @@ static int acquire_mount_where_for_loop_dev(const char *loop_dev) {
r = find_mount_points(loop_dev, &list);
if (r < 0)
return r;
- else if (r == 0) {
- log_error("Can't find mount point of %s. It is expected that %s is already mounted on a place.", loop_dev, loop_dev);
- return -EINVAL;
- } else if (r >= 2) {
- log_error("%s is mounted on %d places. It is expected that %s is mounted on a place.", loop_dev, r, loop_dev);
- return -EINVAL;
- }
+ else if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Can't find mount point of %s. It is expected that %s is already mounted on a place.",
+ loop_dev, loop_dev);
+ else if (r >= 2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s is mounted on %d places. It is expected that %s is mounted on a place.",
+ loop_dev, r, loop_dev);
arg_mount_where = strdup(list[0]);
if (!arg_mount_where)
diff --git a/src/notify/notify.c b/src/notify/notify.c
index 07ad97a490..fff5233b0c 100644
--- a/src/notify/notify.c
+++ b/src/notify/notify.c
@@ -96,10 +96,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PID:
if (optarg) {
- if (parse_pid(optarg, &arg_pid) < 0) {
- log_error("Failed to parse PID %s.", optarg);
- return -EINVAL;
- }
+ if (parse_pid(optarg, &arg_pid) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse PID %s.", optarg);
} else
arg_pid = getppid();
@@ -208,10 +207,9 @@ static int run(int argc, char* argv[]) {
r = sd_pid_notify(arg_pid ? arg_pid : getppid(), false, n);
if (r < 0)
return log_error_errno(r, "Failed to notify init system: %m");
- if (r == 0) {
- log_error("No status data could be sent: $NOTIFY_SOCKET was not set");
- return -EOPNOTSUPP;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "No status data could be sent: $NOTIFY_SOCKET was not set");
return 0;
}
diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c
index 0a54d27e6a..0197474dbc 100644
--- a/src/nspawn/nspawn-cgroup.c
+++ b/src/nspawn/nspawn-cgroup.c
@@ -525,8 +525,8 @@ static int mount_unified_cgroups(const char *dest) {
if (errno != ENOENT)
return log_error_errno(errno, "Failed to determine if mount point %s contains the unified cgroup hierarchy: %m", p);
- log_error("%s is already mounted but not a unified cgroup hierarchy. Refusing.", p);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s is already mounted but not a unified cgroup hierarchy. Refusing.", p);
}
return mount_verbose(LOG_ERR, "cgroup", p, "cgroup2", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL);
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c
index 322b9748f5..48187079b3 100644
--- a/src/nspawn/nspawn-mount.c
+++ b/src/nspawn/nspawn-mount.c
@@ -678,15 +678,15 @@ static int mount_bind(const char *dest, CustomMount *m) {
if (stat(where, &dest_st) < 0)
return log_error_errno(errno, "Failed to stat %s: %m", where);
- if (S_ISDIR(source_st.st_mode) && !S_ISDIR(dest_st.st_mode)) {
- log_error("Cannot bind mount directory %s on file %s.", m->source, where);
- return -EINVAL;
- }
-
- if (!S_ISDIR(source_st.st_mode) && S_ISDIR(dest_st.st_mode)) {
- log_error("Cannot bind mount file %s on directory %s.", m->source, where);
- return -EINVAL;
- }
+ if (S_ISDIR(source_st.st_mode) && !S_ISDIR(dest_st.st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot bind mount directory %s on file %s.",
+ m->source, where);
+
+ if (!S_ISDIR(source_st.st_mode) && S_ISDIR(dest_st.st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot bind mount file %s on directory %s.",
+ m->source, where);
} else { /* Path doesn't exist yet? */
r = mkdir_parents_label(where, 0755);
diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c
index 44f5b17675..e865d5b2a8 100644
--- a/src/nspawn/nspawn-setuid.c
+++ b/src/nspawn/nspawn-setuid.c
@@ -94,69 +94,60 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
- if (r == 0) {
- log_error("Failed to resolve user %s.", user);
- return -ESRCH;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "Failed to resolve user %s.", user);
if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m");
(void) wait_for_terminate_and_check("getent passwd", pid, WAIT_LOG);
x = strchr(line, ':');
- if (!x) {
- log_error("/etc/passwd entry has invalid user field.");
- return -EIO;
- }
+ if (!x)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid user field.");
u = strchr(x+1, ':');
- if (!u) {
- log_error("/etc/passwd entry has invalid password field.");
- return -EIO;
- }
+ if (!u)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid password field.");
u++;
g = strchr(u, ':');
- if (!g) {
- log_error("/etc/passwd entry has invalid UID field.");
- return -EIO;
- }
+ if (!g)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid UID field.");
*g = 0;
g++;
x = strchr(g, ':');
- if (!x) {
- log_error("/etc/passwd entry has invalid GID field.");
- return -EIO;
- }
+ if (!x)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid GID field.");
*x = 0;
h = strchr(x+1, ':');
- if (!h) {
- log_error("/etc/passwd entry has invalid GECOS field.");
- return -EIO;
- }
+ if (!h)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid GECOS field.");
h++;
x = strchr(h, ':');
- if (!x) {
- log_error("/etc/passwd entry has invalid home directory field.");
- return -EIO;
- }
+ if (!x)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "/etc/passwd entry has invalid home directory field.");
*x = 0;
r = parse_uid(u, &uid);
- if (r < 0) {
- log_error("Failed to parse UID of user.");
- return -EIO;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Failed to parse UID of user.");
r = parse_gid(g, &gid);
- if (r < 0) {
- log_error("Failed to parse GID of user.");
- return -EIO;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Failed to parse GID of user.");
home = strdup(h);
if (!home)
@@ -176,10 +167,9 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
- if (r == 0) {
- log_error("Failed to resolve user %s.", user);
- return -ESRCH;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "Failed to resolve user %s.", user);
if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m");
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 3369dd18c9..47fe7d4865 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -321,14 +321,12 @@ static int custom_mount_check_all(void) {
CustomMount *m = &arg_custom_mounts[i];
if (path_equal(m->destination, "/") && arg_userns_mode != USER_NAMESPACE_NO) {
-
- if (arg_userns_chown) {
- log_error("--private-users-chown may not be combined with custom root mounts.");
- return -EINVAL;
- } else if (arg_uid_shift == UID_INVALID) {
- log_error("--private-users with automatic UID shift may not be combined with custom root mounts.");
- return -EINVAL;
- }
+ if (arg_userns_chown)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--private-users-chown may not be combined with custom root mounts.");
+ else if (arg_uid_shift == UID_INVALID)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--private-users with automatic UID shift may not be combined with custom root mounts.");
}
}
@@ -609,10 +607,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_BRIDGE:
- if (!ifname_valid(optarg)) {
- log_error("Bridge interface name not valid: %s", optarg);
- return -EINVAL;
- }
+ if (!ifname_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Bridge interface name not valid: %s", optarg);
r = free_and_strdup(&arg_network_bridge, optarg);
if (r < 0)
@@ -635,10 +632,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_NETWORK_INTERFACE:
- if (!ifname_valid(optarg)) {
- log_error("Network interface name not valid: %s", optarg);
- return -EINVAL;
- }
+ if (!ifname_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_interfaces, optarg) < 0)
return log_oom();
@@ -649,10 +645,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_MACVLAN:
- if (!ifname_valid(optarg)) {
- log_error("MACVLAN network interface name not valid: %s", optarg);
- return -EINVAL;
- }
+ if (!ifname_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "MACVLAN network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_macvlan, optarg) < 0)
return log_oom();
@@ -663,10 +658,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_IPVLAN:
- if (!ifname_valid(optarg)) {
- log_error("IPVLAN network interface name not valid: %s", optarg);
- return -EINVAL;
- }
+ if (!ifname_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "IPVLAN network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_ipvlan, optarg) < 0)
return log_oom();
@@ -685,20 +679,18 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'b':
- if (arg_start_mode == START_PID2) {
- log_error("--boot and --as-pid2 may not be combined.");
- return -EINVAL;
- }
+ if (arg_start_mode == START_PID2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--boot and --as-pid2 may not be combined.");
arg_start_mode = START_BOOT;
arg_settings_mask |= SETTING_START_MODE;
break;
case 'a':
- if (arg_start_mode == START_BOOT) {
- log_error("--boot and --as-pid2 may not be combined.");
- return -EINVAL;
- }
+ if (arg_start_mode == START_BOOT)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--boot and --as-pid2 may not be combined.");
arg_start_mode = START_PID2;
arg_settings_mask |= SETTING_START_MODE;
@@ -709,10 +701,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Invalid UUID: %s", optarg);
- if (sd_id128_is_null(arg_uuid)) {
- log_error("Machine UUID may not be all zeroes.");
- return -EINVAL;
- }
+ if (sd_id128_is_null(arg_uuid))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Machine UUID may not be all zeroes.");
arg_settings_mask |= SETTING_MACHINE_ID;
break;
@@ -725,10 +716,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg))
arg_machine = mfree(arg_machine);
else {
- if (!machine_name_is_valid(optarg)) {
- log_error("Invalid machine name: %s", optarg);
- return -EINVAL;
- }
+ if (!machine_name_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid machine name: %s", optarg);
r = free_and_strdup(&arg_machine, optarg);
if (r < 0)
@@ -740,10 +730,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg))
arg_hostname = mfree(arg_hostname);
else {
- if (!hostname_is_valid(optarg, false)) {
- log_error("Invalid hostname: %s", optarg);
- return -EINVAL;
- }
+ if (!hostname_is_valid(optarg, false))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid hostname: %s", optarg);
r = free_and_strdup(&arg_hostname, optarg);
if (r < 0)
@@ -788,10 +777,9 @@ static int parse_argv(int argc, char *argv[]) {
int cap;
cap = capability_from_name(t);
- if (cap < 0) {
- log_error("Failed to parse capability %s.", t);
- return -EINVAL;
- }
+ if (cap < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse capability %s.", t);
if (c == ARG_CAPABILITY)
plus |= 1ULL << (uint64_t) cap;
@@ -860,10 +848,9 @@ static int parse_argv(int argc, char *argv[]) {
case 'E': {
char **n;
- if (!env_assignment_is_valid(optarg)) {
- log_error("Environment variable assignment '%s' is not valid.", optarg);
- return -EINVAL;
- }
+ if (!env_assignment_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Environment variable assignment '%s' is not valid.", optarg);
n = strv_env_set(arg_setenv, optarg);
if (!n)
@@ -902,10 +889,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PERSONALITY:
arg_personality = personality_from_string(optarg);
- if (arg_personality == PERSONALITY_INVALID) {
- log_error("Unknown or unsupported personality '%s'.", optarg);
- return -EINVAL;
- }
+ if (arg_personality == PERSONALITY_INVALID)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown or unsupported personality '%s'.", optarg);
arg_settings_mask |= SETTING_PERSONALITY;
break;
@@ -921,10 +907,10 @@ static int parse_argv(int argc, char *argv[]) {
VolatileMode m;
m = volatile_mode_from_string(optarg);
- if (m < 0) {
- log_error("Failed to parse --volatile= argument: %s", optarg);
- return -EINVAL;
- } else
+ if (m < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --volatile= argument: %s", optarg);
+ else
arg_volatile_mode = m;
}
@@ -998,10 +984,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_userns_mode = USER_NAMESPACE_FIXED;
}
- if (arg_uid_range <= 0) {
- log_error("UID range cannot be 0.");
- return -EINVAL;
- }
+ if (arg_uid_range <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "UID range cannot be 0.");
arg_settings_mask |= SETTING_USERNS;
break;
@@ -1031,10 +1016,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_kill_signal = signal_from_string(optarg);
- if (arg_kill_signal < 0) {
- log_error("Cannot parse signal: %s", optarg);
- return -EINVAL;
- }
+ if (arg_kill_signal < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot parse signal: %s", optarg);
arg_settings_mask |= SETTING_KILL_SIGNAL;
break;
@@ -1075,10 +1059,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CHDIR:
- if (!path_is_absolute(optarg)) {
- log_error("Working directory %s is not an absolute path.", optarg);
- return -EINVAL;
- }
+ if (!path_is_absolute(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Working directory %s is not an absolute path.", optarg);
r = free_and_strdup(&arg_chdir, optarg);
if (r < 0)
@@ -1097,10 +1080,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NOTIFY_READY:
r = parse_boolean(optarg);
- if (r < 0) {
- log_error("%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg);
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg);
arg_notify_ready = r;
arg_settings_mask |= SETTING_NOTIFY_READY;
break;
@@ -1165,20 +1147,18 @@ static int parse_argv(int argc, char *argv[]) {
}
eq = strchr(optarg, '=');
- if (!eq) {
- log_error("--rlimit= expects an '=' assignment.");
- return -EINVAL;
- }
+ if (!eq)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--rlimit= expects an '=' assignment.");
name = strndup(optarg, eq - optarg);
if (!name)
return log_oom();
rl = rlimit_from_string_harder(name);
- if (rl < 0) {
- log_error("Unknown resource limit: %s", name);
- return -EINVAL;
- }
+ if (rl < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown resource limit: %s", name);
if (!arg_rlimit[rl]) {
arg_rlimit[rl] = new0(struct rlimit, 1);
@@ -1226,10 +1206,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_resolv_conf = resolv_conf_mode_from_string(optarg);
- if (arg_resolv_conf < 0) {
- log_error("Failed to parse /etc/resolv.conf mode: %s", optarg);
- return -EINVAL;
- }
+ if (arg_resolv_conf < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse /etc/resolv.conf mode: %s", optarg);
arg_settings_mask |= SETTING_RESOLV_CONF;
break;
@@ -1241,10 +1220,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_timezone = timezone_mode_from_string(optarg);
- if (arg_timezone < 0) {
- log_error("Failed to parse /etc/localtime mode: %s", optarg);
- return -EINVAL;
- }
+ if (arg_timezone < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse /etc/localtime mode: %s", optarg);
arg_settings_mask |= SETTING_TIMEZONE;
break;
@@ -1262,10 +1240,9 @@ static int parse_argv(int argc, char *argv[]) {
(arg_network_interfaces || arg_network_macvlan ||
arg_network_ipvlan || arg_network_veth_extra ||
arg_network_bridge || arg_network_zone ||
- arg_network_veth || arg_private_network)) {
- log_error("--network-namespace-path cannot be combined with other network options.");
- return -EINVAL;
- }
+ arg_network_veth || arg_private_network))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--network-namespace-path cannot be combined with other network options.");
parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_IPC", CLONE_NEWIPC);
parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_PID", CLONE_NEWPID);
@@ -1283,31 +1260,27 @@ static int parse_argv(int argc, char *argv[]) {
if (!(arg_clone_ns_flags & CLONE_NEWPID) ||
!(arg_clone_ns_flags & CLONE_NEWUTS)) {
arg_register = false;
- if (arg_start_mode != START_PID1) {
- log_error("--boot cannot be used without namespacing.");
- return -EINVAL;
- }
+ if (arg_start_mode != START_PID1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--boot cannot be used without namespacing.");
}
if (arg_userns_mode == USER_NAMESPACE_PICK)
arg_userns_chown = true;
- if (arg_keep_unit && arg_register && cg_pid_get_owner_uid(0, NULL) >= 0) {
+ if (arg_keep_unit && arg_register && cg_pid_get_owner_uid(0, NULL) >= 0)
/* Save the user from accidentally registering either user-$SESSION.scope or user@.service.
* The latter is not technically a user session, but we don't need to labour the point. */
- log_error("--keep-unit --register=yes may not be used when invoked from a user session.");
- return -EINVAL;
- }
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--keep-unit --register=yes may not be used when invoked from a user session.");
- if (arg_directory && arg_image) {
- log_error("--directory= and --image= may not be combined.");
- return -EINVAL;
- }
+ if (arg_directory && arg_image)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--directory= and --image= may not be combined.");
- if (arg_template && arg_image) {
- log_error("--template= and --image= may not be combined.");
- return -EINVAL;
- }
+ if (arg_template && arg_image)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--template= and --image= may not be combined.");
if (arg_ephemeral && arg_template && !arg_directory) {
/* User asked for ephemeral execution but specified --template= instead of --directory=. Semantically
@@ -1318,35 +1291,29 @@ static int parse_argv(int argc, char *argv[]) {
arg_directory = TAKE_PTR(arg_template);
}
- if (arg_template && !(arg_directory || arg_machine)) {
- log_error("--template= needs --directory= or --machine=.");
- return -EINVAL;
- }
+ if (arg_template && !(arg_directory || arg_machine))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--template= needs --directory= or --machine=.");
- if (arg_ephemeral && arg_template) {
- log_error("--ephemeral and --template= may not be combined.");
- return -EINVAL;
- }
+ if (arg_ephemeral && arg_template)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--ephemeral and --template= may not be combined.");
- if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO)) {
- log_error("--ephemeral and --link-journal= may not be combined.");
- return -EINVAL;
- }
+ if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--ephemeral and --link-journal= may not be combined.");
- if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported()) {
- log_error("--private-users= is not supported, kernel compiled without user namespace support.");
- return -EOPNOTSUPP;
- }
+ if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported())
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "--private-users= is not supported, kernel compiled without user namespace support.");
- if (arg_userns_chown && arg_read_only) {
- log_error("--read-only and --private-users-chown may not be combined.");
- return -EINVAL;
- }
+ if (arg_userns_chown && arg_read_only)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--read-only and --private-users-chown may not be combined.");
- if (arg_network_bridge && arg_network_zone) {
- log_error("--network-bridge= and --network-zone= may not be combined.");
- return -EINVAL;
- }
+ if (arg_network_bridge && arg_network_zone)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--network-bridge= and --network-zone= may not be combined.");
if (argc > optind) {
arg_parameters = strv_copy(argv + optind);
@@ -1388,31 +1355,26 @@ static int parse_argv(int argc, char *argv[]) {
}
static int verify_arguments(void) {
- if (arg_userns_mode != USER_NAMESPACE_NO && (arg_mount_settings & MOUNT_APPLY_APIVFS_NETNS) && !arg_private_network) {
- log_error("Invalid namespacing settings. Mounting sysfs with --private-users requires --private-network.");
- return -EINVAL;
- }
+ if (arg_userns_mode != USER_NAMESPACE_NO && (arg_mount_settings & MOUNT_APPLY_APIVFS_NETNS) && !arg_private_network)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid namespacing settings. Mounting sysfs with --private-users requires --private-network.");
- if (arg_userns_mode != USER_NAMESPACE_NO && !(arg_mount_settings & MOUNT_APPLY_APIVFS_RO)) {
- log_error("Cannot combine --private-users with read-write mounts.");
- return -EINVAL;
- }
+ if (arg_userns_mode != USER_NAMESPACE_NO && !(arg_mount_settings & MOUNT_APPLY_APIVFS_RO))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot combine --private-users with read-write mounts.");
- if (arg_volatile_mode != VOLATILE_NO && arg_read_only) {
- log_error("Cannot combine --read-only with --volatile. Note that --volatile already implies a read-only base hierarchy.");
- return -EINVAL;
- }
+ if (arg_volatile_mode != VOLATILE_NO && arg_read_only)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot combine --read-only with --volatile. Note that --volatile already implies a read-only base hierarchy.");
- if (arg_expose_ports && !arg_private_network) {
- log_error("Cannot use --port= without private networking.");
- return -EINVAL;
- }
+ if (arg_expose_ports && !arg_private_network)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot use --port= without private networking.");
#if ! HAVE_LIBIPTC
- if (arg_expose_ports) {
- log_error("--port= is not supported, compiled without libiptc support.");
- return -EOPNOTSUPP;
- }
+ if (arg_expose_ports)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "--port= is not supported, compiled without libiptc support.");
#endif
if (arg_start_mode == START_BOOT && arg_kill_signal <= 0)
@@ -1804,12 +1766,10 @@ static int copy_devnodes(const char *dest) {
if (errno != ENOENT)
return log_error_errno(errno, "Failed to stat %s: %m", from);
- } else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) {
-
- log_error("%s is not a char or block device, cannot copy.", from);
- return -EIO;
-
- } else {
+ } else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "%s is not a char or block device, cannot copy.", from);
+ else {
_cleanup_free_ char *sl = NULL, *prefixed = NULL, *dn = NULL, *t = NULL;
if (mknod(to, st.st_mode, st.st_rdev) < 0) {
@@ -2071,16 +2031,16 @@ static int setup_journal(const char *directory) {
if (try)
return 0;
- log_error("%s: already a mount point, refusing to use for journal", p);
- return -EEXIST;
+ return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+ "%s: already a mount point, refusing to use for journal", p);
}
if (path_is_mount_point(q, NULL, 0) > 0) {
if (try)
return 0;
- log_error("%s: already a mount point, refusing to use for journal", q);
- return -EEXIST;
+ return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+ "%s: already a mount point, refusing to use for journal", q);
}
r = readlink_and_make_absolute(p, &d);
@@ -2252,10 +2212,9 @@ static int setup_machine_id(const char *directory) {
return log_error_errno(r, "Failed to acquire randomized machine UUID: %m");
}
} else {
- if (sd_id128_is_null(id)) {
- log_error("Machine ID in container image is zero, refusing.");
- return -EINVAL;
- }
+ if (sd_id128_is_null(id))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Machine ID in container image is zero, refusing.");
arg_uuid = id;
}
@@ -2336,12 +2295,12 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
_fallthrough_;
case CLD_DUMPED:
- log_error("Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status));
- return -EIO;
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status));
default:
- log_error("Container %s failed due to unknown reason.", arg_machine);
- return -EIO;
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Container %s failed due to unknown reason.", arg_machine);
}
}
@@ -2531,18 +2490,16 @@ static int determine_uid_shift(const char *directory) {
arg_uid_shift = st.st_uid & UINT32_C(0xffff0000);
- if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000))) {
- log_error("UID and GID base of %s don't match.", directory);
- return -EINVAL;
- }
+ if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000)))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "UID and GID base of %s don't match.", directory);
arg_uid_range = UINT32_C(0x10000);
}
- if (arg_uid_shift > (uid_t) -1 - arg_uid_range) {
- log_error("UID base too high for UID range.");
- return -EINVAL;
- }
+ if (arg_uid_shift > (uid_t) -1 - arg_uid_range)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "UID base too high for UID range.");
return 0;
}
@@ -2595,10 +2552,9 @@ static int inner_child(
(void) barrier_place(barrier); /* #1 */
/* Wait until the parent wrote the UID map */
- if (!barrier_place_and_sync(barrier)) { /* #2 */
- log_error("Parent died too early");
- return -ESRCH;
- }
+ if (!barrier_place_and_sync(barrier)) /* #2 */
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "Parent died too early");
}
r = reset_uid_gid();
@@ -2627,10 +2583,9 @@ static int inner_child(
/* Wait until we are cgroup-ified, so that we
* can mount the right cgroup path writable */
- if (!barrier_place_and_sync(barrier)) { /* #4 */
- log_error("Parent died too early");
- return -ESRCH;
- }
+ if (!barrier_place_and_sync(barrier)) /* #4 */
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "Parent died too early");
if (arg_use_cgns && cg_ns_supported()) {
r = unshare(CLONE_NEWCGROUP);
@@ -2750,10 +2705,9 @@ static int inner_child(
/* Let the parent know that we are ready and
* wait until the parent is ready with the
* setup, too... */
- if (!barrier_place_and_sync(barrier)) { /* #5 */
- log_error("Parent died too early");
- return -ESRCH;
- }
+ if (!barrier_place_and_sync(barrier)) /* #5 */
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "Parent died too early");
if (arg_chdir)
if (chdir(arg_chdir) < 0)
@@ -2941,10 +2895,9 @@ static int outer_child(
l = send(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send UID shift: %m");
- if (l != sizeof(arg_uid_shift)) {
- log_error("Short write while sending UID shift.");
- return -EIO;
- }
+ if (l != sizeof(arg_uid_shift))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Short write while sending UID shift.");
if (arg_userns_mode == USER_NAMESPACE_PICK) {
/* When we are supposed to pick the UID shift, the parent will check now whether the UID shift
@@ -2954,10 +2907,9 @@ static int outer_child(
l = recv(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), 0);
if (l < 0)
return log_error_errno(errno, "Failed to recv UID shift: %m");
- if (l != sizeof(arg_uid_shift)) {
- log_error("Short read while receiving UID shift.");
- return -EIO;
- }
+ if (l != sizeof(arg_uid_shift))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Short read while receiving UID shift.");
}
log_full(arg_quiet ? LOG_DEBUG : LOG_INFO,
@@ -2982,10 +2934,9 @@ static int outer_child(
l = send(unified_cgroup_hierarchy_socket, &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send cgroup mode: %m");
- if (l != sizeof(arg_unified_cgroup_hierarchy)) {
- log_error("Short write while sending cgroup mode.");
- return -EIO;
- }
+ if (l != sizeof(arg_unified_cgroup_hierarchy))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Short write while sending cgroup mode.");
unified_cgroup_hierarchy_socket = safe_close(unified_cgroup_hierarchy_socket);
}
@@ -3162,18 +3113,16 @@ static int outer_child(
l = send(pid_socket, &pid, sizeof(pid), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send PID: %m");
- if (l != sizeof(pid)) {
- log_error("Short write while sending PID.");
- return -EIO;
- }
+ if (l != sizeof(pid))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Short write while sending PID.");
l = send(uuid_socket, &arg_uuid, sizeof(arg_uuid), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send machine ID: %m");
- if (l != sizeof(arg_uuid)) {
- log_error("Short write while sending machine ID.");
- return -EIO;
- }
+ if (l != sizeof(arg_uuid))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Short write while sending machine ID.");
l = send_one_fd(notify_socket, fd, 0);
if (l < 0)
diff --git a/src/partition/growfs.c b/src/partition/growfs.c
index c089830b0d..8e04eb3c23 100644
--- a/src/partition/growfs.c
+++ b/src/partition/growfs.c
@@ -211,11 +211,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind + 1 != argc) {
- log_error("%s excepts exactly one argument (the mount point).",
- program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind + 1 != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s excepts exactly one argument (the mount point).",
+ program_invocation_short_name);
arg_target = argv[optind];
diff --git a/src/partition/makefs.c b/src/partition/makefs.c
index 22ff83dc77..88834092bd 100644
--- a/src/partition/makefs.c
+++ b/src/partition/makefs.c
@@ -51,10 +51,9 @@ static int run(int argc, char *argv[]) {
log_setup_service();
- if (argc != 3) {
- log_error("This program expects two arguments.");
- return -EINVAL;
- }
+ if (argc != 3)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program expects two arguments.");
type = argv[1];
device = argv[2];
diff --git a/src/path/path.c b/src/path/path.c
index 2ac5f002a3..7b630a5714 100644
--- a/src/path/path.c
+++ b/src/path/path.c
@@ -100,8 +100,8 @@ static int print_home(const char *n) {
}
}
- log_error("Path %s not known.", n);
- return -EOPNOTSUPP;
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Path %s not known.", n);
}
static int help(void) {
diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c
index 9d1f3f7815..9af9744fd0 100644
--- a/src/portable/portablectl.c
+++ b/src/portable/portablectl.c
@@ -62,10 +62,9 @@ static int determine_image(const char *image, bool permit_non_existing, char **r
return 0;
}
- if (arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Operations on images by path not supported when connecting to remote systems.");
- return -EOPNOTSUPP;
- }
+ if (arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Operations on images by path not supported when connecting to remote systems.");
r = chase_symlinks(image, NULL, CHASE_TRAIL_SLASH | (permit_non_existing ? CHASE_NONEXISTENT : 0), ret);
if (r < 0)
@@ -135,10 +134,9 @@ static int determine_matches(const char *image, char **l, bool allow_any, char *
} else if (strv_equal(l, STRV_MAKE("-"))) {
- if (!allow_any) {
- log_error("Refusing all unit file match.");
- return -EINVAL;
- }
+ if (!allow_any)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Refusing all unit file match.");
if (!arg_quiet)
log_info("(Matching all unit files.)");
@@ -896,10 +894,9 @@ static int parse_argv(int argc, char *argv[]) {
if (streq(optarg, "help"))
return dump_profiles();
- if (!filename_is_valid(optarg)) {
- log_error("Unit profile name not valid: %s", optarg);
- return -EINVAL;
- }
+ if (!filename_is_valid(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unit profile name not valid: %s", optarg);
arg_profile = optarg;
break;
@@ -914,10 +911,9 @@ static int parse_argv(int argc, char *argv[]) {
"copy\n"
"symlink");
return 0;
- } else {
- log_error("Failed to parse --copy= argument: %s", optarg);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse --copy= argument: %s", optarg);
break;
diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c
index 0fc0052f72..a51a76411e 100644
--- a/src/quotacheck/quotacheck.c
+++ b/src/quotacheck/quotacheck.c
@@ -58,10 +58,9 @@ static int run(int argc, char *argv[]) {
log_setup_service();
- if (argc > 1) {
- log_error("This program takes no arguments.");
- return -EINVAL;
- }
+ if (argc > 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes no arguments.");
umask(0022);
diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c
index 1d2b017cf7..0c5f329756 100644
--- a/src/random-seed/random-seed.c
+++ b/src/random-seed/random-seed.c
@@ -32,10 +32,9 @@ static int run(int argc, char *argv[]) {
log_setup_service();
- if (argc != 2) {
- log_error("This program requires one argument.");
- return -EINVAL;
- }
+ if (argc != 2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program requires one argument.");
umask(0022);
@@ -104,10 +103,9 @@ static int run(int argc, char *argv[]) {
read_seed_file = false;
write_seed_file = true;
- } else {
- log_error("Unknown verb '%s'.", argv[1]);
- return -EINVAL;
- }
+ } else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown verb '%s'.", argv[1]);
if (fstat(seed_fd, &st) < 0)
return log_error_errno(errno, "Failed to stat() seed file " RANDOM_SEED ": %m");
@@ -164,10 +162,9 @@ static int run(int argc, char *argv[]) {
k = loop_read(random_fd, buf, buf_size, false);
if (k < 0)
return log_error_errno(k, "Failed to read new seed from /dev/urandom: %m");
- if (k == 0) {
- log_error("Got EOF while reading from /dev/urandom.");
- return -EIO;
- }
+ if (k == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Got EOF while reading from /dev/urandom.");
r = loop_write(seed_fd, buf, (size_t) k, false);
if (r < 0)
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index 5eb1404670..28edbbd856 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -31,10 +31,9 @@ static int run(int argc, char *argv[]) {
log_setup_service();
- if (argc > 1) {
- log_error("This program takes no arguments.");
- return -EINVAL;
- }
+ if (argc > 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program takes no arguments.");
umask(0022);
diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c
index 340767634f..242c26e5ca 100644
--- a/src/resolve/resolvconf-compat.c
+++ b/src/resolve/resolvconf-compat.c
@@ -183,19 +183,19 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
case 'r':
case 'v':
case 'V':
- log_error("Switch -%c not supported.", c);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch -%c not supported.", c);
/* The Debian resolvconf commands we don't support. */
case ARG_ENABLE_UPDATES:
- log_error("Switch --enable-updates not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --enable-updates not supported.");
case ARG_DISABLE_UPDATES:
- log_error("Switch --disable-updates not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --disable-updates not supported.");
case ARG_UPDATES_ARE_ENABLED:
- log_error("Switch --updates-are-enabled not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --updates-are-enabled not supported.");
case '?':
return -EINVAL;
@@ -204,15 +204,13 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_mode == _MODE_INVALID) {
- log_error("Expected either -a or -d on the command line.");
- return -EINVAL;
- }
+ if (arg_mode == _MODE_INVALID)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected either -a or -d on the command line.");
- if (optind+1 != argc) {
- log_error("Expected interface name as argument.");
- return -EINVAL;
- }
+ if (optind+1 != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected interface name as argument.");
r = ifname_mangle(argv[optind], false);
if (r <= 0)
@@ -268,10 +266,9 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
} else if (type == TYPE_PRIVATE)
log_debug("Private DNS server data not supported, ignoring.");
- if (!arg_set_dns) {
- log_error("No DNS servers specified, refusing operation.");
- return -EINVAL;
- }
+ if (!arg_set_dns)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "No DNS servers specified, refusing operation.");
}
return 1; /* work to do */
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
index d4a4b3f40e..bd24a11a93 100644
--- a/src/resolve/resolvectl.c
+++ b/src/resolve/resolvectl.c
@@ -91,10 +91,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
if (arg_ifname) {
assert(arg_ifindex >= 0);
- if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX) {
- log_error("Interface can't be the loopback interface (lo). Sorry.");
- return -EINVAL;
- }
+ if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Interface can't be the loopback interface (lo). Sorry.");
return 1;
}
@@ -124,10 +123,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
}
}
- if (!allow_loopback && r == LOOPBACK_IFINDEX) {
- log_error("Interface can't be the loopback interface (lo). Sorry.");
- return -EINVAL;
- }
+ if (!allow_loopback && r == LOOPBACK_IFINDEX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Interface can't be the loopback interface (lo). Sorry.");
arg_ifindex = r;
arg_ifname = TAKE_PTR(iface);
@@ -579,10 +577,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL;
const char *e;
- if (class != 0) {
- log_error("DNS class specified twice.");
- return -EINVAL;
- }
+ if (class != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "DNS class specified twice.");
e = strchrnul(f, ';');
t = strndup(f, e - f);
@@ -590,10 +587,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom();
r = dns_class_from_string(t);
- if (r < 0) {
- log_error("Unknown DNS class %s.", t);
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown DNS class %s.", t);
class = r;
@@ -610,10 +606,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL;
const char *e;
- if (type != 0) {
- log_error("DNS type specified twice.");
- return -EINVAL;
- }
+ if (type != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "DNS type specified twice.");
e = strchrnul(f, ';');
t = strndup(f, e - f);
@@ -621,10 +616,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom();
r = dns_type_from_string(t);
- if (r < 0) {
- log_error("Unknown DNS type %s.", t);
- return -EINVAL;
- }
+ if (r < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown DNS type %s.", t);
type = r;
@@ -649,8 +643,8 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return resolve_record(bus, n, class, type, true);
invalid:
- log_error("Invalid DNS URI: %s", name);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid DNS URI: %s", name);
}
static int verb_query(int argc, char **argv, void *userdata) {
@@ -897,13 +891,12 @@ static int resolve_openpgp(sd_bus *bus, const char *address) {
assert(address);
domain = strrchr(address, '@');
- if (!domain) {
- log_error("Address does not contain '@': \"%s\"", address);
- return -EINVAL;
- } else if (domain == address || domain[1] == '\0') {
- log_error("Address starts or ends with '@': \"%s\"", address);
- return -EINVAL;
- }
+ if (!domain)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Address does not contain '@': \"%s\"", address);
+ if (domain == address || domain[1] == '\0')
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Address starts or ends with '@': \"%s\"", address);
domain++;
r = string_hashsum_sha256(address, domain - 1 - address, &hashed);
@@ -2566,10 +2559,9 @@ static int compat_parse_argv(int argc, char *argv[]) {
arg_flags |= SD_RESOLVED_MDNS_IPV4;
else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6;
- else {
- log_error("Unknown protocol specifier: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown protocol specifier: %s", optarg);
break;
@@ -2585,26 +2577,24 @@ static int compat_parse_argv(int argc, char *argv[]) {
arg_mode = MODE_RESOLVE_TLSA;
if (!optarg || service_family_is_valid(optarg))
arg_service_family = optarg;
- else {
- log_error("Unknown service family \"%s\".", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown service family \"%s\".", optarg);
break;
case ARG_RAW:
- if (on_tty()) {
- log_error("Refusing to write binary data to tty.");
- return -ENOTTY;
- }
+ if (on_tty())
+ return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
+ "Refusing to write binary data to tty.");
if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET;
- else {
- log_error("Unknown --raw specifier \"%s\".", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown --raw specifier \"%s\".",
+ optarg);
arg_legend = false;
break;
@@ -2716,15 +2706,13 @@ static int compat_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_type == 0 && arg_class != 0) {
- log_error("--class= may only be used in conjunction with --type=.");
- return -EINVAL;
- }
+ if (arg_type == 0 && arg_class != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--class= may only be used in conjunction with --type=.");
- if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE) {
- log_error("--service and --type= may not be combined.");
- return -EINVAL;
- }
+ if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--service and --type= may not be combined.");
if (arg_type != 0 && arg_class == 0)
arg_class = DNS_CLASS_IN;
@@ -2734,15 +2722,13 @@ static int compat_parse_argv(int argc, char *argv[]) {
if (IN_SET(arg_mode, MODE_SET_LINK, MODE_REVERT_LINK)) {
- if (arg_ifindex <= 0) {
- log_error("--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=.");
- return -EINVAL;
- }
+ if (arg_ifindex <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=.");
- if (arg_ifindex == LOOPBACK_IFINDEX) {
- log_error("Interface can't be the loopback interface (lo). Sorry.");
- return -EINVAL;
- }
+ if (arg_ifindex == LOOPBACK_IFINDEX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Interface can't be the loopback interface (lo). Sorry.");
}
return 1 /* work to do */;
@@ -2864,27 +2850,26 @@ static int native_parse_argv(int argc, char *argv[]) {
arg_flags |= SD_RESOLVED_MDNS_IPV4;
else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6;
- else {
- log_error("Unknown protocol specifier: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown protocol specifier: %s",
+ optarg);
break;
case ARG_RAW:
- if (on_tty()) {
- log_error("Refusing to write binary data to tty.");
- return -ENOTTY;
- }
+ if (on_tty())
+ return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
+ "Refusing to write binary data to tty.");
if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET;
- else {
- log_error("Unknown --raw specifier \"%s\".", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown --raw specifier \"%s\".",
+ optarg);
arg_legend = false;
break;
@@ -2928,10 +2913,9 @@ static int native_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_type == 0 && arg_class != 0) {
- log_error("--class= may only be used in conjunction with --type=.");
- return -EINVAL;
- }
+ if (arg_type == 0 && arg_class != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--class= may only be used in conjunction with --type=.");
if (arg_type != 0 && arg_class == 0)
arg_class = DNS_CLASS_IN;
diff --git a/src/resolve/resolved-dns-dnssec.c b/src/resolve/resolved-dns-dnssec.c
index a837414ca1..13da4e5991 100644
--- a/src/resolve/resolved-dns-dnssec.c
+++ b/src/resolve/resolved-dns-dnssec.c
@@ -1272,10 +1272,10 @@ int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
if (nsec3->key->type != DNS_TYPE_NSEC3)
return -EINVAL;
- if (nsec3->nsec3.iterations > NSEC3_ITERATIONS_MAX) {
- log_debug("Ignoring NSEC3 RR %s with excessive number of iterations.", dns_resource_record_to_string(nsec3));
- return -EOPNOTSUPP;
- }
+ if (nsec3->nsec3.iterations > NSEC3_ITERATIONS_MAX)
+ return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Ignoring NSEC3 RR %s with excessive number of iterations.",
+ dns_resource_record_to_string(nsec3));
algorithm = nsec3_hash_to_gcrypt_md(nsec3->nsec3.algorithm);
if (algorithm < 0)
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index f54468a0ac..6eb12f8ae5 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -48,10 +48,10 @@ int dns_packet_new(
/* The caller may not check what is going to be truly allocated, so do not allow to
* allocate a DNS packet bigger than DNS_PACKET_SIZE_MAX.
*/
- if (min_alloc_dsize > DNS_PACKET_SIZE_MAX) {
- log_error("Requested packet data size too big: %zu", min_alloc_dsize);
- return -EFBIG;
- }
+ if (min_alloc_dsize > DNS_PACKET_SIZE_MAX)
+ return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
+ "Requested packet data size too big: %zu",
+ min_alloc_dsize);
/* When dns_packet_new() is called with min_alloc_dsize == 0, allocate more than the
* absolute minimum (which is the dns packet header size), to avoid
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index fbc4735855..ddab2850df 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -1816,13 +1816,12 @@ static int dns_transaction_add_dnssec_transaction(DnsTransaction *t, DnsResource
if (r > 0) {
char s[DNS_RESOURCE_KEY_STRING_MAX], saux[DNS_RESOURCE_KEY_STRING_MAX];
- log_debug("Potential cyclic dependency, refusing to add transaction %" PRIu16 " (%s) as dependency for %" PRIu16 " (%s).",
- aux->id,
- dns_resource_key_to_string(t->key, s, sizeof s),
- t->id,
- dns_resource_key_to_string(aux->key, saux, sizeof saux));
-
- return -ELOOP;
+ return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
+ "Potential cyclic dependency, refusing to add transaction %" PRIu16 " (%s) as dependency for %" PRIu16 " (%s).",
+ aux->id,
+ dns_resource_key_to_string(t->key, s, sizeof s),
+ t->id,
+ dns_resource_key_to_string(aux->key, saux, sizeof saux));
}
}
@@ -2445,8 +2444,8 @@ static int dns_transaction_requires_rrsig(DnsTransaction *t, DnsResourceRecord *
return true;
/* A CNAME/DNAME without a parent? That's sooo weird. */
- log_debug("Transaction %" PRIu16 " claims CNAME/DNAME at root. Refusing.", t->id);
- return -EBADMSG;
+ return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Transaction %" PRIu16 " claims CNAME/DNAME at root. Refusing.", t->id);
}
}
diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c
index 293a0fade4..ea96255dc1 100644
--- a/src/resolve/resolved-dnssd.c
+++ b/src/resolve/resolved-dnssd.c
@@ -175,10 +175,10 @@ int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
if (r < 0)
return log_debug_errno(r, "Failed to replace specifiers: %m");
- if (!dns_service_name_is_valid(name)) {
- log_debug("Service instance name '%s' is invalid.", name);
- return -EINVAL;
- }
+ if (!dns_service_name_is_valid(name))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Service instance name '%s' is invalid.",
+ name);
*ret_name = TAKE_PTR(name);
diff --git a/src/resolve/resolved-dnstls-gnutls.c b/src/resolve/resolved-dnstls-gnutls.c
index 15055284d5..ddf9758bb3 100644
--- a/src/resolve/resolved-dnstls-gnutls.c
+++ b/src/resolve/resolved-dnstls-gnutls.c
@@ -155,8 +155,9 @@ ssize_t dnstls_stream_write(DnsStream *stream, const char *buf, size_t count) {
case GNUTLS_E_AGAIN:
return -EAGAIN;
default:
- log_debug("Failed to invoke gnutls_record_send: %s", gnutls_strerror(ss));
- return -EPIPE;
+ return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
+ "Failed to invoke gnutls_record_send: %s",
+ gnutls_strerror(ss));
}
return ss;
@@ -178,8 +179,9 @@ ssize_t dnstls_stream_read(DnsStream *stream, void *buf, size_t count) {
case GNUTLS_E_AGAIN:
return -EAGAIN;
default:
- log_debug("Failed to invoke gnutls_record_recv: %s", gnutls_strerror(ss));
- return -EPIPE;
+ return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
+ "Failed to invoke gnutls_record_recv: %s",
+ gnutls_strerror(ss));
}
return ss;
diff --git a/src/resolve/resolved-dnstls-openssl.c b/src/resolve/resolved-dnstls-openssl.c
index 9242f6ab08..0ebaa660c5 100644
--- a/src/resolve/resolved-dnstls-openssl.c
+++ b/src/resolve/resolved-dnstls-openssl.c
@@ -174,8 +174,9 @@ int dnstls_stream_on_io(DnsStream *stream, uint32_t revents) {
char errbuf[256];
ERR_error_string_n(error, errbuf, sizeof(errbuf));
- log_debug("Failed to invoke SSL_do_handshake: %s", errbuf);
- return -ECONNREFUSED;
+ return log_debug_errno(SYNTHETIC_ERRNO(ECONNREFUSED),
+ "Failed to invoke SSL_do_handshake: %s",
+ errbuf);
}
}
diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c
index 00ff20d2dc..c5c180943d 100644
--- a/src/resolve/resolved-etc-hosts.c
+++ b/src/resolve/resolved-etc-hosts.c
@@ -47,10 +47,10 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
r = extract_first_word(&line, &address_str, NULL, EXTRACT_RELAX);
if (r < 0)
return log_error_errno(r, "Couldn't extract address, in line /etc/hosts:%u.", nr);
- if (r == 0) {
- log_error("Premature end of line, in line /etc/hosts:%u.", nr);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Premature end of line, in line /etc/hosts:%u.",
+ nr);
r = in_addr_ifindex_from_string_auto(address_str, &address.family, &address.address, NULL);
if (r < 0)
@@ -151,10 +151,10 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
bn->addresses[bn->n_addresses++] = &item->address;
}
- if (!found) {
- log_error("Line is missing any host names, in line /etc/hosts:%u.", nr);
- return -EINVAL;
- }
+ if (!found)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Line is missing any host names, in line /etc/hosts:%u.",
+ nr);
return 0;
}
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 8e564216ed..cbdeebb211 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -336,10 +336,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
r = dns_label_unescape(&p, label, sizeof label);
if (r < 0)
return log_error_errno(r, "Failed to unescape host name: %m");
- if (r == 0) {
- log_error("Couldn't find a single label in hostname.");
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Couldn't find a single label in hostname.");
#if HAVE_LIBIDN2
r = idn2_to_unicode_8z8z(label, &utf8, 0);
@@ -356,10 +355,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
if (k > 0)
r = k;
- if (!utf8_is_valid(label)) {
- log_error("System hostname is not UTF-8 clean.");
- return -EINVAL;
- }
+ if (!utf8_is_valid(label))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "System hostname is not UTF-8 clean.");
decoded = label;
#else
decoded = label; /* no decoding */
@@ -369,10 +367,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
if (r < 0)
return log_error_errno(r, "Failed to escape host name: %m");
- if (is_localhost(n)) {
- log_debug("System hostname is 'localhost', ignoring.");
- return -EINVAL;
- }
+ if (is_localhost(n))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "System hostname is 'localhost', ignoring.");
r = dns_name_concat(n, "local", mdns_hostname);
if (r < 0)
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index ec8d91af79..977d2adb36 100644
--- a/src/rfkill/rfkill.c
+++ b/src/rfkill/rfkill.c
@@ -251,10 +251,9 @@ static int load_state(
l = write(rfkill_fd, &we, sizeof(we));
if (l < 0)
return log_error_errno(errno, "Failed to restore rfkill state for %i: %m", event->idx);
- if (l != sizeof(we)) {
- log_error("Couldn't write rfkill event structure, too short.");
- return -EIO;
- }
+ if (l != sizeof(we))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Couldn't write rfkill event structure, too short.");
log_debug("Loaded state '%s' from %s.", one_zero(b), state_file);
return 0;
diff --git a/src/run/run.c b/src/run/run.c
index dbd437593e..63f135db2f 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -408,10 +408,9 @@ static int parse_argv(int argc, char *argv[]) {
with_trigger = !!arg_path_property || !!arg_socket_property || with_timer;
/* currently, only single trigger (path, socket, timer) unit can be created simultaneously */
- if ((int) !!arg_path_property + (int) !!arg_socket_property + (int) with_timer > 1) {
- log_error("Only single trigger (path, socket, timer) unit can be created.");
- return -EINVAL;
- }
+ if ((int) !!arg_path_property + (int) !!arg_socket_property + (int) with_timer > 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Only single trigger (path, socket, timer) unit can be created.");
if (arg_stdio == ARG_STDIO_AUTO) {
/* If we both --pty and --pipe are specified we'll automatically pick --pty if we are connected fully
@@ -422,66 +421,54 @@ static int parse_argv(int argc, char *argv[]) {
ARG_STDIO_DIRECT;
}
- if ((optind >= argc) && (!arg_unit || !with_trigger)) {
- log_error("Command line to execute required.");
- return -EINVAL;
- }
+ if ((optind >= argc) && (!arg_unit || !with_trigger))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Command line to execute required.");
- if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Execution in user context is not supported on non-local systems.");
- return -EINVAL;
- }
+ if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Execution in user context is not supported on non-local systems.");
- if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL) {
- log_error("Scope execution is not supported on non-local systems.");
- return -EINVAL;
- }
+ if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Scope execution is not supported on non-local systems.");
- if (arg_scope && (arg_remain_after_exit || arg_service_type)) {
- log_error("--remain-after-exit and --service-type= are not supported in --scope mode.");
- return -EINVAL;
- }
+ if (arg_scope && (arg_remain_after_exit || arg_service_type))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--remain-after-exit and --service-type= are not supported in --scope mode.");
- if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope)) {
- log_error("--pty/--pipe is not compatible in timer or --scope mode.");
- return -EINVAL;
- }
+ if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--pty/--pipe is not compatible in timer or --scope mode.");
- if (arg_stdio != ARG_STDIO_NONE && arg_transport == BUS_TRANSPORT_REMOTE) {
- log_error("--pty/--pipe is only supported when connecting to the local system or containers.");
- return -EINVAL;
- }
+ if (arg_stdio != ARG_STDIO_NONE && arg_transport == BUS_TRANSPORT_REMOTE)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--pty/--pipe is only supported when connecting to the local system or containers.");
- if (arg_stdio != ARG_STDIO_NONE && arg_no_block) {
- log_error("--pty/--pipe is not compatible with --no-block.");
- return -EINVAL;
- }
+ if (arg_stdio != ARG_STDIO_NONE && arg_no_block)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--pty/--pipe is not compatible with --no-block.");
- if (arg_scope && with_trigger) {
- log_error("Path, socket or timer options are not supported in --scope mode.");
- return -EINVAL;
- }
+ if (arg_scope && with_trigger)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Path, socket or timer options are not supported in --scope mode.");
- if (arg_timer_property && !with_timer) {
- log_error("--timer-property= has no effect without any other timer options.");
- return -EINVAL;
- }
+ if (arg_timer_property && !with_timer)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--timer-property= has no effect without any other timer options.");
if (arg_wait) {
- if (arg_no_block) {
- log_error("--wait may not be combined with --no-block.");
- return -EINVAL;
- }
+ if (arg_no_block)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--wait may not be combined with --no-block.");
- if (with_trigger) {
- log_error("--wait may not be combined with path, socket or timer operations.");
- return -EINVAL;
- }
+ if (with_trigger)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--wait may not be combined with path, socket or timer operations.");
- if (arg_scope) {
- log_error("--wait may not be combined with --scope.");
- return -EINVAL;
- }
+ if (arg_scope)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--wait may not be combined with --scope.");
}
return 1;
@@ -787,10 +774,10 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
* name our transient units. */
id = startswith(unique, ":1.");
- if (!id) {
- log_error("Unique name %s has unexpected format.", unique);
- return -EINVAL;
- }
+ if (!id)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unique name %s has unexpected format.",
+ unique);
p = strjoin("run-u", id, ".", unit_type_to_string(t));
if (!p)
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c
index 9ba6978962..db4fd411e2 100644
--- a/src/shared/bootspec.c
+++ b/src/shared/bootspec.c
@@ -593,10 +593,10 @@ int find_esp_and_warn(
path = getenv("SYSTEMD_ESP_PATH");
if (path) {
- if (!path_is_valid(path) || !path_is_absolute(path)) {
- log_error("$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s", path);
- return -EINVAL;
- }
+ if (!path_is_valid(path) || !path_is_absolute(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s",
+ path);
/* Note: when the user explicitly configured things with an env var we won't validate the mount
* point. After all we want this to be useful for testing. */
@@ -649,10 +649,9 @@ int find_default_boot_entry(
if (r < 0)
return log_error_errno(r, "Failed to load bootspec config from \"%s/loader\": %m", where);
- if (config->default_entry < 0) {
- log_error("No entry suitable as default, refusing to guess.");
- return -ENOENT;
- }
+ if (config->default_entry < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "No entry suitable as default, refusing to guess.");
*e = &config->entries[config->default_entry];
log_debug("Found default boot entry in file \"%s\"", (*e)->path);
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 2cd30e3467..0141c131f6 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -83,10 +83,8 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {
int r; \
\
r = parse_func(eq); \
- if (r < 0) { \
- log_error("Failed to parse %s: %s", field, eq); \
- return -EINVAL; \
- } \
+ if (r < 0) \
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s: %s", field, eq); \
\
r = sd_bus_message_append(m, "(sv)", field, \
bus_type, (int32_t) r); \
@@ -277,8 +275,8 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c
case '+':
case '!':
/* The bus API doesn't support +, ! and !! currently, unfortunately. :-( */
- log_error("Sorry, but +, ! and !! are currently not supported for transient services.");
- return -EOPNOTSUPP;
+ return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Sorry, but +, ! and !! are currently not supported for transient services.");
default:
done = true;
@@ -450,10 +448,9 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
else {
r = parse_permille_unbounded(eq);
- if (r == 0) {
- log_error("CPU quota too small.");
- return -ERANGE;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
+ "CPU quota too small.");
if (r < 0)
return log_error_errno(r, "CPU quota '%s' invalid.", eq);
@@ -497,10 +494,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
uint64_t bytes;
e = strchr(eq, ' ');
- if (!e) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse %s value %s.",
+ field, eq);
path = strndupa(eq, e - eq);
bandwidth = e+1;
@@ -531,10 +528,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
uint64_t u;
e = strchr(eq, ' ');
- if (!e) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse %s value %s.",
+ field, eq);
path = strndupa(eq, e - eq);
weight = e+1;
@@ -562,10 +559,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
usec_t usec;
e = strchr(eq, ' ');
- if (!e) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse %s value %s.",
+ field, eq);
path = strndupa(eq, e - eq);
target = e+1;
@@ -1125,10 +1122,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_QUOTES|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m");
- if (r == 0) {
- log_error("Missing argument after ':': %s", eq);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Missing argument after ':': %s",
+ eq);
d = destination;
@@ -1143,10 +1140,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
flags = MS_REC;
else if (streq(options, "norbind"))
flags = 0;
- else {
- log_error("Unknown options: %s", eq);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown options: %s",
+ eq);
}
} else
d = s;
@@ -1204,10 +1201,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m");
- if (r == 0) {
- log_error("Failed to parse argument: %s", p);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse argument: %s",
+ p);
r = sd_bus_message_append(m, "(ss)", path, w);
if (r < 0)
@@ -1603,10 +1600,9 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
assert(assignment);
eq = strchr(assignment, '=');
- if (!eq) {
- log_error("Not an assignment: %s", assignment);
- return -EINVAL;
- }
+ if (!eq)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not an assignment: %s", assignment);
field = strndupa(assignment, eq - assignment);
eq++;
@@ -1709,20 +1705,20 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
case UNIT_TARGET:
case UNIT_DEVICE:
case UNIT_SWAP:
- log_error("Not supported unit type");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not supported unit type");
default:
- log_error("Invalid unit type");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid unit type");
}
r = bus_append_unit_property(m, field, eq);
if (r != 0)
return r;
- log_error("Unknown assignment: %s", assignment);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown assignment: %s", assignment);
}
int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char **l) {
@@ -2006,8 +2002,8 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char* const*
else if (STR_IN_SET(d->result, "done", "skipped"))
return 0;
- log_debug("Unexpected job result, assuming server side newer than us: %s", d->result);
- return -EIO;
+ return log_debug_errno(SYNTHETIC_ERRNO(EIO),
+ "Unexpected job result, assuming server side newer than us: %s", d->result);
}
int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_args) {
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 4667d3bc52..760be38c85 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -1382,12 +1382,10 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
if (user)
r = bus_connect_user_systemd(bus);
else {
- if (sd_booted() <= 0) {
+ if (sd_booted() <= 0)
/* Print a friendly message when the local system is actually not running systemd as PID 1. */
- log_error("System has not been booted with systemd as init system (PID 1). Can't operate.");
-
- return -EHOSTDOWN;
- }
+ return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
+ "System has not been booted with systemd as init system (PID 1). Can't operate.");
r = bus_connect_system_systemd(bus);
}
break;
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index ec3e1a10bb..18620a3b19 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -1086,10 +1086,9 @@ int dissected_image_decrypt_interactively(
else if (r != -ENOKEY)
return log_error_errno(r, "Failed to decrypt image: %m");
- if (--n < 0) {
- log_error("Too many retries.");
- return -EKEYREJECTED;
- }
+ if (--n < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EKEYREJECTED),
+ "Too many retries.");
z = strv_free(z);
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 357c66d800..409eef21ff 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -204,10 +204,10 @@ static int unit_file_find_dirs(
return 0;
type = unit_name_to_type(name);
- if (type < 0) {
- log_error("Failed to to derive unit type from unit name: %s", name);
- return -EINVAL;
- }
+ if (type < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to to derive unit type from unit name: %s",
+ name);
if (is_instance) {
r = unit_name_to_instance(name, &instance);
diff --git a/src/shared/efivars.c b/src/shared/efivars.c
index 6815fc69b8..cb9e13c15f 100644
--- a/src/shared/efivars.c
+++ b/src/shared/efivars.c
@@ -875,10 +875,9 @@ int efi_loader_get_features(uint64_t *ret) {
if (r < 0)
return r;
- if (s != sizeof(uint64_t)) {
- log_debug("LoaderFeatures EFI variable doesn't have the right size.");
- return -EINVAL;
- }
+ if (s != sizeof(uint64_t))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "LoaderFeatures EFI variable doesn't have the right size.");
memcpy(ret, v, sizeof(uint64_t));
return 0;
diff --git a/src/shared/generator.c b/src/shared/generator.c
index eba0ae8ae0..e4a15f8b11 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -310,10 +310,10 @@ int generator_hook_up_mkswap(
return log_oom();
/* Nothing to work on. */
- if (!is_device_path(node)) {
- log_error("Cannot format something that is not a device node: %s", node);
- return -EINVAL;
- }
+ if (!is_device_path(node))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot format something that is not a device node: %s",
+ node);
r = unit_name_from_path_instance("systemd-mkswap", node, ".service", &unit);
if (r < 0)
@@ -380,15 +380,15 @@ int generator_hook_up_mkfs(
return log_oom();
/* Nothing to work on. */
- if (!is_device_path(node)) {
- log_error("Cannot format something that is not a device node: %s", node);
- return -EINVAL;
- }
+ if (!is_device_path(node))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot format something that is not a device node: %s",
+ node);
- if (!type || streq(type, "auto")) {
- log_error("Cannot format partition %s, filesystem type is not specified", node);
- return -EINVAL;
- }
+ if (!type || streq(type, "auto"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot format partition %s, filesystem type is not specified",
+ node);
r = unit_name_from_path_instance("systemd-mkfs", node, ".service", &unit);
if (r < 0)
diff --git a/src/shared/install.c b/src/shared/install.c
index 1fd24cb4eb..97c48afe5d 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1232,10 +1232,9 @@ static int unit_file_load(
type = unit_name_to_type(info->name);
if (type < 0)
return -EINVAL;
- if (unit_name_is_valid(info->name, UNIT_NAME_TEMPLATE|UNIT_NAME_INSTANCE) && !unit_type_may_template(type)) {
- log_error("Unit type %s cannot be templated.", unit_type_to_string(type));
- return -EINVAL;
- }
+ if (unit_name_is_valid(info->name, UNIT_NAME_TEMPLATE|UNIT_NAME_INSTANCE) && !unit_type_may_template(type))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unit type %s cannot be templated.", unit_type_to_string(type));
if (!(flags & SEARCH_LOAD)) {
r = lstat(path, &st);
@@ -1448,10 +1447,10 @@ static int unit_file_search(
}
}
- if (!found_unit) {
- log_debug("Cannot find unit %s%s%s.", info->name, template ? " or " : "", strempty(template));
- return -ENOENT;
- }
+ if (!found_unit)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
+ "Cannot find unit %s%s%s.",
+ info->name, template ? " or " : "", strempty(template));
if (info->type == UNIT_FILE_TYPE_MASKED)
return result;
diff --git a/src/shared/journal-importer.c b/src/shared/journal-importer.c
index ca203bbbfc..b0e619205d 100644
--- a/src/shared/journal-importer.c
+++ b/src/shared/journal-importer.c
@@ -96,10 +96,10 @@ static int get_line(JournalImporter *imp, char **line, size_t *size) {
}
imp->scanned = imp->filled;
- if (imp->scanned >= DATA_SIZE_MAX) {
- log_error("Entry is bigger than %u bytes.", DATA_SIZE_MAX);
- return -E2BIG;
- }
+ if (imp->scanned >= DATA_SIZE_MAX)
+ return log_error_errno(SYNTHETIC_ERRNO(E2BIG),
+ "Entry is bigger than %u bytes.",
+ DATA_SIZE_MAX);
if (imp->passive_fd)
/* we have to wait for some data to come to us */
@@ -192,11 +192,10 @@ static int get_data_size(JournalImporter *imp) {
return r;
imp->data_size = unaligned_read_le64(data);
- if (imp->data_size > DATA_SIZE_MAX) {
- log_error("Stream declares field with size %zu > DATA_SIZE_MAX = %u",
- imp->data_size, DATA_SIZE_MAX);
- return -EINVAL;
- }
+ if (imp->data_size > DATA_SIZE_MAX)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Stream declares field with size %zu > DATA_SIZE_MAX = %u",
+ imp->data_size, DATA_SIZE_MAX);
if (imp->data_size == 0)
log_warning("Binary field with zero length");
@@ -234,8 +233,8 @@ static int get_data_newline(JournalImporter *imp) {
int l;
l = cescape_char(*data, buf);
- log_error("Expected newline, got '%.*s'", l, buf);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected newline, got '%.*s'", l, buf);
}
return 1;
@@ -446,12 +445,12 @@ int journal_importer_push_data(JournalImporter *imp, const char *data, size_t si
assert(imp);
assert(imp->state != IMPORTER_STATE_EOF);
- if (!realloc_buffer(imp, imp->filled + size)) {
- log_error("Failed to store received data of size %zu "
- "(in addition to existing %zu bytes with %zu filled): %s",
- size, imp->size, imp->filled, strerror(ENOMEM));
- return -ENOMEM;
- }
+ if (!realloc_buffer(imp, imp->filled + size))
+ return log_error_errno(SYNTHETIC_ERRNO(ENOMEM),
+ "Failed to store received data of size %zu "
+ "(in addition to existing %zu bytes with %zu filled): %s",
+ size, imp->size, imp->filled,
+ strerror(ENOMEM));
memcpy(imp->buf + imp->filled, data, size);
imp->filled += size;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 2d53307203..41d484fa16 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -303,10 +303,9 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
k = format_timestamp_utc(buf, sizeof(buf), x);
else
k = format_timestamp(buf, sizeof(buf), x);
- if (!k) {
- log_error("Failed to format timestamp: %"PRIu64, x);
- return -EINVAL;
- }
+ if (!k)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to format timestamp: %" PRIu64, x);
} else {
char usec[7];
@@ -321,18 +320,16 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
break;
case OUTPUT_SHORT_ISO:
- if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", gettime_r(&t, &tm)) <= 0) {
- log_error("Failed to format ISO time");
- return -EINVAL;
- }
+ if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", gettime_r(&t, &tm)) <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to format ISO time");
break;
case OUTPUT_SHORT_ISO_PRECISE:
/* No usec in strftime, so we leave space and copy over */
- if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.xxxxxx%z", gettime_r(&t, &tm)) <= 0) {
- log_error("Failed to format ISO-precise time");
- return -EINVAL;
- }
+ if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.xxxxxx%z", gettime_r(&t, &tm)) <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to format ISO-precise time");
xsprintf(usec, "%06"PRI_USEC, x % USEC_PER_SEC);
memcpy(buf + 20, usec, 6);
break;
@@ -340,10 +337,9 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
case OUTPUT_SHORT:
case OUTPUT_SHORT_PRECISE:
- if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm)) <= 0) {
- log_error("Failed to format syslog time");
- return -EINVAL;
- }
+ if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm)) <= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to format syslog time");
if (mode == OUTPUT_SHORT_PRECISE) {
size_t k;
@@ -352,10 +348,9 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
k = sizeof(buf) - strlen(buf);
r = snprintf(buf + strlen(buf), k, ".%06"PRIu64, x % USEC_PER_SEC);
- if (r <= 0 || (size_t) r >= k) { /* too long? */
- log_error("Failed to format precise time");
- return -EINVAL;
- }
+ if (r <= 0 || (size_t) r >= k) /* too long? */
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to format precise time");
}
break;
@@ -563,10 +558,9 @@ static int output_verbose(
const char *on = "", *off = "";
c = memchr(data, '=', length);
- if (!c) {
- log_error("Invalid field.");
- return -EINVAL;
- }
+ if (!c)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid field.");
fieldlen = c - (const char*) data;
r = field_set_test(output_fields, data, fieldlen);
@@ -658,10 +652,9 @@ static int output_export(
continue;
c = memchr(data, '=', length);
- if (!c) {
- log_error("Invalid field.");
- return -EINVAL;
- }
+ if (!c)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid field.");
r = field_set_test(output_fields, data, c - (const char *) data);
if (r < 0)
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
index e00001288d..67ccd43c3f 100644
--- a/src/shared/seccomp-util.c
+++ b/src/shared/seccomp-util.c
@@ -874,10 +874,10 @@ int seccomp_add_syscall_filter_item(scmp_filter_ctx *seccomp, const char *name,
const SyscallFilterSet *other;
other = syscall_filter_set_find(name);
- if (!other) {
- log_debug("Filter set %s is not known!", name);
- return -EINVAL;
- }
+ if (!other)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Filter set %s is not known!",
+ name);
return seccomp_add_syscall_filter_set(seccomp, other, action, exclude, log_missing);
diff --git a/src/shared/serialize.c b/src/shared/serialize.c
index d0f86a83f4..eb1191b3bf 100644
--- a/src/shared/serialize.c
+++ b/src/shared/serialize.c
@@ -153,10 +153,10 @@ int deserialize_dual_timestamp(const char *value, dual_timestamp *t) {
return -EINVAL;
r = sscanf(value, "%" PRIu64 "%" PRIu64 "%n", &a, &b, &pos);
- if (r != 2) {
- log_debug("Failed to parse dual timestamp value \"%s\".", value);
- return -EINVAL;
- }
+ if (r != 2)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse dual timestamp value \"%s\".",
+ value);
if (value[pos] != '\0')
/* trailing garbage */
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 62fd3655e9..9ea88a37b4 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -256,8 +256,8 @@ int find_hibernate_location(char **device, char **type, size_t *size, size_t *us
return 0;
}
- log_debug("No swap partitions were found.");
- return -ENOSYS;
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOSYS),
+ "No swap partitions were found.");
}
static bool enough_swap_for_hibernation(void) {
diff --git a/src/shared/verbs.c b/src/shared/verbs.c
index f68c2bae08..7c5dcb02a2 100644
--- a/src/shared/verbs.c
+++ b/src/shared/verbs.c
@@ -92,16 +92,14 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
left = 1;
if (verb->min_args != VERB_ANY &&
- (unsigned) left < verb->min_args) {
- log_error("Too few arguments.");
- return -EINVAL;
- }
+ (unsigned) left < verb->min_args)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too few arguments.");
if (verb->max_args != VERB_ANY &&
- (unsigned) left > verb->max_args) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ (unsigned) left > verb->max_args)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
if ((verb->flags & VERB_ONLINE_ONLY) && running_in_chroot_or_offline()) {
if (name)
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 9e4831e35f..5b7984a6f2 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -49,10 +49,9 @@ static int write_hibernate_location_info(void) {
return r;
}
- if (!streq(type, "file")) {
- log_debug("Invalid hibernate type: %s", type);
- return -EINVAL;
- }
+ if (!streq(type, "file"))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid hibernate type: %s", type);
/* Only available in 4.17+ */
if (access("/sys/power/resume_offset", W_OK) < 0) {
@@ -74,10 +73,9 @@ static int write_hibernate_location_info(void) {
r = read_fiemap(fd, &fiemap);
if (r < 0)
return log_debug_errno(r, "Unable to read extent map for '%s': %m", device);
- if (fiemap->fm_mapped_extents == 0) {
- log_debug("No extents found in '%s'", device);
- return -EINVAL;
- }
+ if (fiemap->fm_mapped_extents == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "No extents found in '%s'", device);
offset = fiemap->fm_extents[0].fe_physical / page_size();
xsprintf(offset_str, "%" PRIu64, offset);
@@ -336,18 +334,16 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (argc - optind != 1) {
- log_error("Usage: %s COMMAND",
- program_invocation_short_name);
- return -EINVAL;
- }
+ if (argc - optind != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Usage: %s COMMAND",
+ program_invocation_short_name);
arg_verb = argv[optind];
- if (!STR_IN_SET(arg_verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate")) {
- log_error("Unknown command '%s'.", arg_verb);
- return -EINVAL;
- }
+ if (!STR_IN_SET(arg_verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown command '%s'.", arg_verb);
return 1 /* work to do */;
}
@@ -368,10 +364,10 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return r;
- if (!allow) {
- log_error("Sleep mode \"%s\" is disabled by configuration, refusing.", arg_verb);
- return -EACCES;
- }
+ if (!allow)
+ return log_error_errno(SYNTHETIC_ERRNO(EACCES),
+ "Sleep mode \"%s\" is disabled by configuration, refusing.",
+ arg_verb);
if (streq(arg_verb, "suspend-then-hibernate"))
return execute_s2h(delay);
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index 36ba5422ed..62b7051073 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -505,10 +505,9 @@ static int add_listen_socket(Context *context, int fd) {
r = sd_is_socket(fd, 0, SOCK_STREAM, 1);
if (r < 0)
return log_error_errno(r, "Failed to determine socket type: %m");
- if (r == 0) {
- log_error("Passed in socket is not a stream socket.");
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Passed in socket is not a stream socket.");
r = fd_nonblock(fd, true);
if (r < 0)
@@ -592,10 +591,9 @@ static int parse_argv(int argc, char *argv[]) {
return r;
}
- if (arg_connections_max < 1) {
- log_error("Connection limit is too low.");
- return -EINVAL;
- }
+ if (arg_connections_max < 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Connection limit is too low.");
break;
@@ -606,15 +604,13 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind >= argc) {
- log_error("Not enough parameters.");
- return -EINVAL;
- }
+ if (optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not enough parameters.");
- if (argc != optind+1) {
- log_error("Too many parameters.");
- return -EINVAL;
- }
+ if (argc != optind+1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many parameters.");
arg_remote_host = argv[optind];
return 1;
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index 9ceb3f8d13..3a21aa4aed 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -82,8 +82,8 @@ static int parse_argv(int argc, char *argv[]) {
break;
default:
- log_error("Unknown option code %c", c);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown option code %c", c);
}
}
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index adfb546756..1cfe510180 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -256,10 +256,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_cat_config && argc > optind) {
- log_error("Positional arguments are not allowed with --cat-config");
- return -EINVAL;
- }
+ if (arg_cat_config && argc > optind)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Positional arguments are not allowed with --cat-config");
return 1;
}
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5292c648df..d573f8f17a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3640,11 +3640,10 @@ static int start_special(int argc, char *argv[], void *userdata) {
static int start_system_special(int argc, char *argv[], void *userdata) {
/* Like start_special above, but raises an error when running in user mode */
- if (arg_scope != UNIT_FILE_SYSTEM) {
- log_error("Bad action for %s mode.",
- arg_scope == UNIT_FILE_GLOBAL ? "--global" : "--user");
- return -EINVAL;
- }
+ if (arg_scope != UNIT_FILE_SYSTEM)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Bad action for %s mode.",
+ arg_scope == UNIT_FILE_GLOBAL ? "--global" : "--user");
return start_special(argc, argv, userdata);
}
@@ -5252,15 +5251,13 @@ static int show(int argc, char *argv[], void *userdata) {
assert(argv);
show_mode = systemctl_show_mode_from_string(argv[0]);
- if (show_mode < 0) {
- log_error("Invalid argument.");
- return -EINVAL;
- }
+ if (show_mode < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid argument.");
- if (show_mode == SYSTEMCTL_SHOW_HELP && argc <= 1) {
- log_error("This command expects one or more unit names. Did you mean --help?");
- return -EINVAL;
- }
+ if (show_mode == SYSTEMCTL_SHOW_HELP && argc <= 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This command expects one or more unit names. Did you mean --help?");
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
@@ -5624,10 +5621,9 @@ static int print_variable(const char *s) {
_cleanup_free_ char *esc = NULL;
sep = strchr(s, '=');
- if (!sep) {
- log_error("Invalid environment block");
- return -EUCLEAN;
- }
+ if (!sep)
+ return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
+ "Invalid environment block");
esc = shell_maybe_quote(sep + 1, ESCAPE_POSIX);
if (!esc)
@@ -6042,15 +6038,15 @@ static int normalize_filenames(char **names) {
if (!path_is_absolute(*u)) {
char* normalized_path;
- if (!isempty(arg_root)) {
- log_error("Non-absolute paths are not allowed when --root is used: %s", *u);
- return -EINVAL;
- }
+ if (!isempty(arg_root))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Non-absolute paths are not allowed when --root is used: %s",
+ *u);
- if (!strchr(*u,'/')) {
- log_error("Link argument does contain at least one directory separator: %s", *u);
- return -EINVAL;
- }
+ if (!strchr(*u,'/'))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Link argument does contain at least one directory separator: %s",
+ *u);
r = path_make_absolute_cwd(*u, &normalized_path);
if (r < 0)
@@ -6765,10 +6761,10 @@ static int get_file_to_edit(
}
if (arg_runtime) {
- if (access(path, F_OK) >= 0) {
- log_error("Refusing to create \"%s\" because it would be overridden by \"%s\" anyway.", run, path);
- return -EEXIST;
- }
+ if (access(path, F_OK) >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+ "Refusing to create \"%s\" because it would be overridden by \"%s\" anyway.",
+ run, path);
*ret_path = TAKE_PTR(run);
} else
@@ -7515,10 +7511,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return version();
case 't': {
- if (isempty(optarg)) {
- log_error("--type= requires arguments.");
- return -EINVAL;
- }
+ if (isempty(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--type= requires arguments.");
for (p = optarg;;) {
_cleanup_free_ char *type = NULL;
@@ -7553,8 +7548,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
log_error("Unknown unit type or load state '%s'.", type);
- log_info("Use -t help to see a list of allowed values.");
- return -EINVAL;
+ return log_info_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Use -t help to see a list of allowed values.");
}
break;
@@ -7708,10 +7703,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
arg_signal = signal_from_string(optarg);
- if (arg_signal < 0) {
- log_error("Failed to parse signal string %s.", optarg);
- return -EINVAL;
- }
+ if (arg_signal < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse signal string %s.",
+ optarg);
break;
case ARG_NO_ASK_PASSWORD:
@@ -7733,10 +7728,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case 'n':
- if (safe_atou(optarg, &arg_lines) < 0) {
- log_error("Failed to parse lines '%s'", optarg);
- return -EINVAL;
- }
+ if (safe_atou(optarg, &arg_lines) < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse lines '%s'",
+ optarg);
break;
case 'o':
@@ -7746,10 +7741,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
arg_output = output_mode_from_string(optarg);
- if (arg_output < 0) {
- log_error("Unknown output '%s'.", optarg);
- return -EINVAL;
- }
+ if (arg_output < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown output '%s'.",
+ optarg);
break;
case 'i':
@@ -7765,10 +7760,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case ARG_STATE: {
- if (isempty(optarg)) {
- log_error("--state= requires arguments.");
- return -EINVAL;
- }
+ if (isempty(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--state= requires arguments.");
for (p = optarg;;) {
_cleanup_free_ char *s = NULL;
@@ -7793,10 +7787,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
case 'r':
- if (geteuid() != 0) {
- log_error("--recursive requires root privileges.");
- return -EPERM;
- }
+ if (geteuid() != 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "--recursive requires root privileges.");
arg_recursive = true;
break;
@@ -7808,10 +7801,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
arg_preset_mode = unit_file_preset_mode_from_string(optarg);
- if (arg_preset_mode < 0) {
- log_error("Failed to parse preset mode: %s.", optarg);
- return -EINVAL;
- }
+ if (arg_preset_mode < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to parse preset mode: %s.", optarg);
break;
@@ -7831,20 +7823,18 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM) {
- log_error("Cannot access user instance remotely.");
- return -EINVAL;
- }
+ if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot access user instance remotely.");
- if (arg_wait && arg_no_block) {
- log_error("--wait may not be combined with --no-block.");
- return -EINVAL;
- }
+ if (arg_wait && arg_no_block)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--wait may not be combined with --no-block.");
- if (arg_runtime && STRPTR_IN_SET(argv[optind], "disable", "unmask", "preset", "preset-all")) {
- log_error("--runtime cannot be used with %s", argv[optind]);
- return -EINVAL;
- }
+ if (arg_runtime && STRPTR_IN_SET(argv[optind], "disable", "unmask", "preset", "preset-all"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--runtime cannot be used with %s",
+ argv[optind]);
return 1;
}
@@ -7934,10 +7924,9 @@ static int halt_parse_argv(int argc, char *argv[]) {
r = update_reboot_parameter_and_warn(argc == optind + 1 ? argv[optind] : NULL);
if (r < 0)
return r;
- } else if (optind < argc) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ } else if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
return 1;
}
@@ -8151,29 +8140,26 @@ static int telinit_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind >= argc) {
- log_error("%s: required argument missing.", program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s: required argument missing.",
+ program_invocation_short_name);
- if (optind + 1 < argc) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ if (optind + 1 < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
- if (strlen(argv[optind]) != 1) {
- log_error("Expected single character argument.");
- return -EINVAL;
- }
+ if (strlen(argv[optind]) != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected single character argument.");
for (i = 0; i < ELEMENTSOF(table); i++)
if (table[i].from == argv[optind][0])
break;
- if (i >= ELEMENTSOF(table)) {
- log_error("Unknown command '%s'.", argv[optind]);
- return -EINVAL;
- }
+ if (i >= ELEMENTSOF(table))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown command '%s'.", argv[optind]);
arg_action = table[i].to;
@@ -8210,10 +8196,9 @@ static int runlevel_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
- log_error("Too many arguments.");
- return -EINVAL;
- }
+ if (optind < argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments.");
return 1;
}
@@ -8267,8 +8252,8 @@ static int parse_argv(int argc, char *argv[]) {
execv(TELINIT, argv);
- log_error("Couldn't find an alternative telinit implementation to spawn.");
- return -EIO;
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Couldn't find an alternative telinit implementation to spawn.");
}
} else if (strstr(program_invocation_short_name, "runlevel")) {
@@ -8439,8 +8424,8 @@ static int start_with_fallback(void) {
if (talk_initctl() > 0)
return 0;
- log_error("Failed to talk to init daemon.");
- return -EIO;
+ return log_error_errno(SYNTHETIC_ERRNO(EIO),
+ "Failed to talk to init daemon.");
}
static int halt_now(enum action a) {
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index a348ec497a..6f15647cc3 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -1112,10 +1112,10 @@ static int add_group(Item *i) {
* r > 0: means the gid does not exist -> fail
* r == 0: means the gid exists -> nothing more to do.
*/
- if (r > 0) {
- log_error("Failed to create %s: please create GID %d", i->name, i->gid);
- return -EINVAL;
- }
+ if (r > 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to create %s: please create GID %d",
+ i->name, i->gid);
if (r == 0)
return 0;
}
@@ -1839,10 +1839,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_REPLACE:
if (!path_is_absolute(optarg) ||
- !endswith(optarg, ".conf")) {
- log_error("The argument to --replace= must an absolute path to a config file");
- return -EINVAL;
- }
+ !endswith(optarg, ".conf"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "The argument to --replace= must an absolute path to a config file");
arg_replace = optarg;
break;
@@ -1862,15 +1861,13 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_replace && arg_cat_config) {
- log_error("Option --replace= is not supported with --cat-config");
- return -EINVAL;
- }
+ if (arg_replace && arg_cat_config)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --replace= is not supported with --cat-config");
- if (arg_replace && optind >= argc) {
- log_error("When --replace= is given, some configuration items must be specified");
- return -EINVAL;
- }
+ if (arg_replace && optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "When --replace= is given, some configuration items must be specified");
return 1;
}
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 46712b71fc..24b103bbb7 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -438,15 +438,13 @@ static int map_server_address(sd_bus *bus, const char *member, sd_bus_message *m
return 0;
}
- if (!IN_SET(family, AF_INET, AF_INET6)) {
- log_error("Unknown address family %i", family);
- return -EINVAL;
- }
+ if (!IN_SET(family, AF_INET, AF_INET6))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown address family %i", family);
- if (sz != FAMILY_ADDRESS_SIZE(family)) {
- log_error("Invalid address size");
- return -EINVAL;
- }
+ if (sz != FAMILY_ADDRESS_SIZE(family))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid address size");
r = in_addr_to_string(family, d, p);
if (r < 0)
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 1fd1999974..2bee31c603 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -471,10 +471,9 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
break;
}
}
- if (!recv_time) {
- log_error("Invalid packet timestamp.");
- return -EINVAL;
- }
+ if (!recv_time)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid packet timestamp.");
if (!m->pending) {
log_debug("Unexpected reply. Ignoring.");
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 5f2844195c..6de06a8589 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -797,10 +797,10 @@ static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st
st = &stbuf;
}
- if (hardlink_vulnerable(st)) {
- log_error("Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path);
- return -EPERM;
- }
+ if (hardlink_vulnerable(st))
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.",
+ path);
if (i->mode_set) {
if (S_ISLNK(st->st_mode))
@@ -852,10 +852,10 @@ static int path_open_parent_safe(const char *path) {
_cleanup_free_ char *dn = NULL;
int fd;
- if (path_equal(path, "/") || !path_is_normalized(path)) {
- log_error("Failed to open parent of '%s': invalid path.", path);
- return -EINVAL;
- }
+ if (path_equal(path, "/") || !path_is_normalized(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to open parent of '%s': invalid path.",
+ path);
dn = dirname_malloc(path);
if (!dn)
@@ -879,10 +879,10 @@ static int path_open_safe(const char *path) {
assert(path);
- if (!path_is_normalized(path)) {
- log_error("Failed to open invalid path '%s'.", path);
- return -EINVAL;
- }
+ if (!path_is_normalized(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Failed to open invalid path '%s'.",
+ path);
fd = chase_symlinks(path, NULL, CHASE_OPEN|CHASE_SAFE|CHASE_NOFOLLOW, NULL);
if (fd == -EPERM)
@@ -1057,10 +1057,10 @@ static int fd_set_acls(Item *item, int fd, const char *path, const struct stat *
st = &stbuf;
}
- if (hardlink_vulnerable(st)) {
- log_error("Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path);
- return -EPERM;
- }
+ if (hardlink_vulnerable(st))
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+ "Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.",
+ path);
if (S_ISLNK(st->st_mode)) {
log_debug("Skipping ACL fix for symlink %s.", path);
@@ -1168,10 +1168,10 @@ static int parse_attribute_from_arg(Item *item) {
}
}
- if (isempty(p) && mode != MODE_SET) {
- log_error("Setting file attribute on '%s' needs an attribute specification.", item->path);
- return -EINVAL;
- }
+ if (isempty(p) && mode != MODE_SET)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Setting file attribute on '%s' needs an attribute specification.",
+ item->path);
for (; p && *p ; p++) {
unsigned i, v;
@@ -1180,10 +1180,10 @@ static int parse_attribute_from_arg(Item *item) {
if (*p == attributes[i].character)
break;
- if (i >= ELEMENTSOF(attributes)) {
- log_error("Unknown file attribute '%c' on '%s'.", *p, item->path);
- return -EINVAL;
- }
+ if (i >= ELEMENTSOF(attributes))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown file attribute '%c' on '%s'.",
+ *p, item->path);
v = attributes[i].value;
@@ -1226,10 +1226,10 @@ static int fd_set_attribute(Item *item, int fd, const char *path, const struct s
/* Issuing the file attribute ioctls on device nodes is not
* safe, as that will be delivered to the drivers, not the
* file system containing the device node. */
- if (!S_ISREG(st->st_mode) && !S_ISDIR(st->st_mode)) {
- log_error("Setting file flags is only supported on regular files and directories, cannot set on '%s'.", path);
- return -EINVAL;
- }
+ if (!S_ISREG(st->st_mode) && !S_ISDIR(st->st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Setting file flags is only supported on regular files and directories, cannot set on '%s'.",
+ path);
f = item->attribute_value & item->attribute_mask;
@@ -1657,10 +1657,10 @@ static int empty_directory(Item *i, const char *path) {
}
if (r < 0)
return log_error_errno(r, "is_dir() failed on path %s: %m", path);
- if (r == 0) {
- log_error("'%s' already exists and is not a directory.", path);
- return -EEXIST;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+ "'%s' already exists and is not a directory.",
+ path);
return path_set_perms(i, path);
}
@@ -2212,10 +2212,9 @@ static int clean_item_instance(Item *i, const char* instance) {
if (fstat(dirfd(d), &s) < 0)
return log_error_errno(errno, "stat(%s) failed: %m", i->path);
- if (!S_ISDIR(s.st_mode)) {
- log_error("%s is not a directory.", i->path);
- return -ENOTDIR;
- }
+ if (!S_ISDIR(s.st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(ENOTDIR),
+ "%s is not a directory.", i->path);
if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW) != 0)
return log_error_errno(errno, "stat(%s/..) failed: %m", i->path);
@@ -2963,10 +2962,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_REPLACE:
if (!path_is_absolute(optarg) ||
- !endswith(optarg, ".conf")) {
- log_error("The argument to --replace= must an absolute path to a config file");
- return -EINVAL;
- }
+ !endswith(optarg, ".conf"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "The argument to --replace= must an absolute path to a config file");
arg_replace = optarg;
break;
@@ -2982,20 +2980,17 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_operation == 0 && !arg_cat_config) {
- log_error("You need to specify at least one of --clean, --create or --remove.");
- return -EINVAL;
- }
+ if (arg_operation == 0 && !arg_cat_config)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "You need to specify at least one of --clean, --create or --remove.");
- if (arg_replace && arg_cat_config) {
- log_error("Option --replace= is not supported with --cat-config");
- return -EINVAL;
- }
+ if (arg_replace && arg_cat_config)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option --replace= is not supported with --cat-config");
- if (arg_replace && optind >= argc) {
- log_error("When --replace= is given, some configuration items must be specified");
- return -EINVAL;
- }
+ if (arg_replace && optind >= argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "When --replace= is given, some configuration items must be specified");
return 1;
}
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index c147493bf8..fc165ffc01 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -308,10 +308,9 @@ static int parse_password(const char *filename, char **wall) {
if (r < 0)
return r;
- if (!socket_name) {
- log_error("Invalid password file %s", filename);
- return -EBADMSG;
- }
+ if (!socket_name)
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+ "Invalid password file %s", filename);
if (not_after > 0 && now(CLOCK_MONOTONIC) > not_after)
return 0;
@@ -652,10 +651,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_console = true;
if (optarg) {
- if (isempty(optarg)) {
- log_error("Empty console device path is not allowed.");
- return -EINVAL;
- }
+ if (isempty(optarg))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Empty console device path is not allowed.");
arg_device = optarg;
}
@@ -668,22 +666,19 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind != argc) {
- log_error("%s takes no arguments.", program_invocation_short_name);
- return -EINVAL;
- }
+ if (optind != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s takes no arguments.", program_invocation_short_name);
if (arg_plymouth || arg_console) {
- if (!IN_SET(arg_action, ACTION_QUERY, ACTION_WATCH)) {
- log_error("Options --query and --watch conflict.");
- return -EINVAL;
- }
+ if (!IN_SET(arg_action, ACTION_QUERY, ACTION_WATCH))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Options --query and --watch conflict.");
- if (arg_plymouth && arg_console) {
- log_error("Options --plymouth and --console conflict.");
- return -EINVAL;
- }
+ if (arg_plymouth && arg_console)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Options --plymouth and --console conflict.");
}
return 1;
diff --git a/src/udev/mtd_probe/probe_smartmedia.c b/src/udev/mtd_probe/probe_smartmedia.c
index 099809da1b..f8e1b140f5 100644
--- a/src/udev/mtd_probe/probe_smartmedia.c
+++ b/src/udev/mtd_probe/probe_smartmedia.c
@@ -49,19 +49,17 @@ int probe_smart_media(int mtd_fd, mtd_info_t* info) {
if (!cis_buffer)
return log_oom();
- if (info->type != MTD_NANDFLASH) {
- log_debug("Not marked MTD_NANDFLASH.");
- return -EINVAL;
- }
+ if (info->type != MTD_NANDFLASH)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Not marked MTD_NANDFLASH.");
sector_size = info->writesize;
block_size = info->erasesize;
size_in_megs = info->size / (1024 * 1024);
- if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE)) {
- log_debug("Unexpected sector size: %i", sector_size);
- return -EINVAL;
- }
+ if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unexpected sector size: %i", sector_size);
switch(size_in_megs) {
case 1:
@@ -85,16 +83,14 @@ int probe_smart_media(int mtd_fd, mtd_info_t* info) {
}
}
- if (!cis_found) {
- log_debug("CIS not found");
- return -EINVAL;
- }
+ if (!cis_found)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "CIS not found");
if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 &&
- memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0) {
- log_debug("CIS signature didn't match");
- return -EINVAL;
- }
+ memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "CIS signature didn't match");
printf("MTD_FTL=smartmedia\n");
return 0;
diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c
index d8575b72bd..ce52149b1d 100644
--- a/src/udev/udev-builtin-kmod.c
+++ b/src/udev/udev-builtin-kmod.c
@@ -27,10 +27,9 @@ static int builtin_kmod(sd_device *dev, int argc, char *argv[], bool test) {
if (!ctx)
return 0;
- if (argc < 3 || !streq(argv[1], "load")) {
- log_error("%s: expected: load <module>", argv[0]);
- return -EINVAL;
- }
+ if (argc < 3 || !streq(argv[1], "load"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s: expected: load <module>", argv[0]);
for (i = 2; argv[i]; i++)
(void) module_load_and_warn(ctx, argv[i], false);
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index f69458ef9b..c60c02e7fe 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -625,10 +625,9 @@ int udev_event_spawn(struct udev_event *event,
if (!argv)
return log_oom();
- if (isempty(argv[0])) {
- log_error("Invalid command '%s'", cmd);
- return -EINVAL;
- }
+ if (isempty(argv[0]))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid command '%s'", cmd);
/* allow programs in /usr/lib/udev/ to be called without the path */
if (!path_is_absolute(argv[0])) {
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 4f3dffad49..da1dee6e13 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -605,10 +605,10 @@ static int import_property_from_string(sd_device *dev, char *line) {
/* unquote */
if (IN_SET(val[0], '"', '\'')) {
- if (len == 1 || val[len-1] != val[0]) {
- log_debug("inconsistent quoting: '%s', skip", line);
- return -EINVAL;
- }
+ if (len == 1 || val[len-1] != val[0])
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "inconsistent quoting: '%s', skip",
+ line);
val[len-1] = '\0';
val++;
}
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index e9a1af65fc..7f8960f549 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -84,10 +84,9 @@ int hwdb_main(int argc, char *argv[], void *userdata) {
if (r <= 0)
return r;
- if (!arg_update && !arg_test) {
- log_error("Either --update or --test must be used.");
- return -EINVAL;
- }
+ if (!arg_update && !arg_test)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Either --update or --test must be used.");
if (arg_update) {
r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true);
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
index a2a8893870..4ae237d430 100644
--- a/src/udev/udevadm-settle.c
+++ b/src/udev/udevadm-settle.c
@@ -65,8 +65,9 @@ static int parse_argv(int argc, char *argv[]) {
case 's':
case 'e':
case 'q':
- log_info("Option -%c no longer supported.", c);
- return -EINVAL;
+ return log_info_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option -%c no longer supported.",
+ c);
case '?':
return -EINVAL;
default:
diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c
index 7bf7b08a44..22c3184a01 100644
--- a/src/udev/udevadm-test-builtin.c
+++ b/src/udev/udevadm-test-builtin.c
@@ -49,16 +49,14 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_command = argv[optind++];
- if (!arg_command) {
- log_error("Command missing.");
- return -EINVAL;
- }
+ if (!arg_command)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Command missing.");
arg_syspath = argv[optind++];
- if (!arg_syspath) {
- log_error("syspath missing.");
- return -EINVAL;
- }
+ if (!arg_syspath)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "syspath missing.");
return 1;
}
diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c
index 2ee78da51b..a5f05ea836 100644
--- a/src/udev/udevadm-test.c
+++ b/src/udev/udevadm-test.c
@@ -58,10 +58,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'N':
arg_resolve_name_timing = resolve_name_timing_from_string(optarg);
- if (arg_resolve_name_timing < 0) {
- log_error("--resolve-names= must be early, late or never");
- return -EINVAL;
- }
+ if (arg_resolve_name_timing < 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--resolve-names= must be early, late or never");
break;
case 'V':
return print_version();
@@ -73,10 +72,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unknown option");
}
- if (!argv[optind]) {
- log_error("syspath parameter missing.");
- return -EINVAL;
- }
+ if (!argv[optind])
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "syspath parameter missing.");
/* add /sys if needed */
if (!startswith(argv[optind], "/sys"))
diff --git a/src/user-sessions/user-sessions.c b/src/user-sessions/user-sessions.c
index 4f711c2ed6..5ca8037cb9 100644
--- a/src/user-sessions/user-sessions.c
+++ b/src/user-sessions/user-sessions.c
@@ -15,10 +15,9 @@
static int run(int argc, char*argv[]) {
int r, k;
- if (argc != 2) {
- log_error("This program requires one argument.");
- return -EINVAL;
- }
+ if (argc != 2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program requires one argument.");
log_setup_service();
@@ -36,8 +35,7 @@ static int run(int argc, char*argv[]) {
} else if (streq(argv[1], "stop"))
return create_shutdown_run_nologin_or_warn();
- log_error("Unknown verb '%s'.", argv[1]);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb '%s'.", argv[1]);
}
DEFINE_MAIN_FUNCTION(run);
diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c
index 70f5d957b2..ffe63d5717 100644
--- a/src/volatile-root/volatile-root.c
+++ b/src/volatile-root/volatile-root.c
@@ -19,10 +19,9 @@ static int make_volatile(const char *path) {
r = path_is_mount_point(path, NULL, AT_SYMLINK_FOLLOW);
if (r < 0)
return log_error_errno(r, "Couldn't determine whether %s is a mount point: %m", path);
- if (r == 0) {
- log_error("%s is not a mount point.", path);
- return -EINVAL;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "%s is not a mount point.", path);
r = path_is_temporary_fs(path);
if (r < 0)
@@ -84,10 +83,9 @@ static int run(int argc, char *argv[]) {
log_setup_service();
- if (argc > 3) {
- log_error("Too many arguments. Expected directory and mode.");
- return -EINVAL;
- }
+ if (argc > 3)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Too many arguments. Expected directory and mode.");
r = query_volatile_mode(&m);
if (r < 0)
@@ -106,18 +104,15 @@ static int run(int argc, char *argv[]) {
else {
path = argv[2];
- if (isempty(path)) {
- log_error("Directory name cannot be empty.");
- return -EINVAL;
- }
- if (!path_is_absolute(path)) {
- log_error("Directory must be specified as absolute path.");
- return -EINVAL;
- }
- if (path_equal(path, "/")) {
- log_error("Directory cannot be the root directory.");
- return -EINVAL;
- }
+ if (isempty(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Directory name cannot be empty.");
+ if (!path_is_absolute(path))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Directory must be specified as absolute path.");
+ if (path_equal(path, "/"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Directory cannot be the root directory.");
}
if (m != VOLATILE_YES)