summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-11-26 09:27:21 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-11-27 14:35:20 +0900
commitd85ff94477b9b1e1b8f45f92eaa4eb8f834f6499 (patch)
tree4d597d84bfc0ee7b38850af574328ba9629170c2
parent2762ce2d89336d5e62ad4fb1984e7d9777e1c3c5 (diff)
downloadsystemd-d85ff94477b9b1e1b8f45f92eaa4eb8f834f6499.tar.gz
core: use SYNTHETIC_ERRNO() macro
-rw-r--r--src/core/automount.c18
-rw-r--r--src/core/bpf-firewall.c12
-rw-r--r--src/core/device.c9
-rw-r--r--src/core/execute.c25
-rw-r--r--src/core/mount.c18
-rw-r--r--src/core/path.c6
-rw-r--r--src/core/scope.c6
-rw-r--r--src/core/service.c87
-rw-r--r--src/core/slice.c12
-rw-r--r--src/core/smack-setup.c3
-rw-r--r--src/core/socket.c48
-rw-r--r--src/core/swap.c12
-rw-r--r--src/core/timer.c6
-rw-r--r--src/core/unit.c10
14 files changed, 95 insertions, 177 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index a84cddbdbd..5076b351f5 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -174,19 +174,15 @@ static int automount_verify(Automount *a) {
assert(a);
assert(UNIT(a)->load_state == UNIT_LOADED);
- if (path_equal(a->where, "/")) {
- log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing.");
- return -ENOEXEC;
- }
+ if (path_equal(a->where, "/"))
+ return log_unit_error_errno(UNIT(a), SYNTHETIC_ERRNO(ENOEXEC), "Cannot have an automount unit for the root directory. Refusing.");
r = unit_name_from_path(a->where, ".automount", &e);
if (r < 0)
return log_unit_error_errno(UNIT(a), r, "Failed to generate unit name from path: %m");
- if (!unit_has_name(UNIT(a), e)) {
- log_unit_error(UNIT(a), "Where= setting doesn't match unit name. Refusing.");
- return -ENOEXEC;
- }
+ if (!unit_has_name(UNIT(a), e))
+ return log_unit_error_errno(UNIT(a), SYNTHETIC_ERRNO(ENOEXEC), "Where= setting doesn't match unit name. Refusing.");
return 0;
}
@@ -811,10 +807,8 @@ static int automount_start(Unit *u) {
assert(a);
assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED));
- if (path_is_mount_point(a->where, NULL, 0) > 0) {
- log_unit_error(u, "Path %s is already a mount point, refusing start.", a->where);
- return -EEXIST;
- }
+ if (path_is_mount_point(a->where, NULL, 0) > 0)
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(EEXIST), "Path %s is already a mount point, refusing start.", a->where);
r = unit_test_trigger_loaded(u);
if (r < 0)
diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c
index 31c2dcf37d..44aa1bfb1e 100644
--- a/src/core/bpf-firewall.c
+++ b/src/core/bpf-firewall.c
@@ -686,14 +686,10 @@ int bpf_firewall_install(Unit *u) {
supported = bpf_firewall_supported();
if (supported < 0)
return supported;
- if (supported == BPF_FIREWALL_UNSUPPORTED) {
- log_unit_debug(u, "BPF firewalling not supported on this manager, proceeding without.");
- return -EOPNOTSUPP;
- }
- if (supported != BPF_FIREWALL_SUPPORTED_WITH_MULTI && u->type == UNIT_SLICE) {
- log_unit_debug(u, "BPF_F_ALLOW_MULTI is not supported on this manager, not doing BPF firewall on slice units.");
- return -EOPNOTSUPP;
- }
+ if (supported == BPF_FIREWALL_UNSUPPORTED)
+ return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "BPF firewalling not supported on this manager, proceeding without.");
+ if (supported != BPF_FIREWALL_SUPPORTED_WITH_MULTI && u->type == UNIT_SLICE)
+ return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "BPF_F_ALLOW_MULTI is not supported on this manager, not doing BPF firewall on slice units.");
if (supported != BPF_FIREWALL_SUPPORTED_WITH_MULTI &&
(!set_isempty(u->ip_bpf_custom_ingress) || !set_isempty(u->ip_bpf_custom_egress)))
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "BPF_F_ALLOW_MULTI not supported on this manager, cannot attach custom BPF programs.");
diff --git a/src/core/device.c b/src/core/device.c
index 9a1d88270d..6440c59e26 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -515,11 +515,10 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
if (DEVICE(u)->state == DEVICE_PLUGGED &&
DEVICE(u)->sysfs &&
sysfs &&
- !path_equal(DEVICE(u)->sysfs, sysfs)) {
- log_unit_debug(u, "Device %s appeared twice with different sysfs paths %s and %s, ignoring the latter.",
- e, DEVICE(u)->sysfs, sysfs);
- return -EEXIST;
- }
+ !path_equal(DEVICE(u)->sysfs, sysfs))
+ return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EEXIST),
+ "Device %s appeared twice with different sysfs paths %s and %s, ignoring the latter.",
+ e, DEVICE(u)->sysfs, sysfs);
delete = false;
diff --git a/src/core/execute.c b/src/core/execute.c
index c992b8d5d3..f1f3744191 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -3769,23 +3769,20 @@ static int exec_child(
r = dynamic_creds_realize(dcreds, suggested_paths, &uid, &gid);
if (r < 0) {
*exit_status = EXIT_USER;
- if (r == -EILSEQ) {
- log_unit_error(unit, "Failed to update dynamic user credentials: User or group with specified name already exists.");
- return -EOPNOTSUPP;
- }
+ if (r == -EILSEQ)
+ return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "Failed to update dynamic user credentials: User or group with specified name already exists.");
return log_unit_error_errno(unit, r, "Failed to update dynamic user credentials: %m");
}
if (!uid_is_valid(uid)) {
*exit_status = EXIT_USER;
- log_unit_error(unit, "UID validation failed for \""UID_FMT"\"", uid);
- return -ESRCH;
+ return log_unit_error_errno(unit, SYNTHETIC_ERRNO(ESRCH), "UID validation failed for \""UID_FMT"\"", uid);
}
if (!gid_is_valid(gid)) {
*exit_status = EXIT_USER;
- log_unit_error(unit, "GID validation failed for \""GID_FMT"\"", gid);
- return -ESRCH;
+ return log_unit_error_errno(unit, SYNTHETIC_ERRNO(ESRCH), "GID validation failed for \""GID_FMT"\"", gid);
}
if (dcreds->user)
@@ -4628,15 +4625,11 @@ int exec_spawn(Unit *unit,
context->std_output == EXEC_OUTPUT_SOCKET ||
context->std_error == EXEC_OUTPUT_SOCKET) {
- if (params->n_socket_fds > 1) {
- log_unit_error(unit, "Got more than one socket.");
- return -EINVAL;
- }
+ if (params->n_socket_fds > 1)
+ return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EINVAL), "Got more than one socket.");
- if (params->n_socket_fds == 0) {
- log_unit_error(unit, "Got no socket.");
- return -EINVAL;
- }
+ if (params->n_socket_fds == 0)
+ return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EINVAL), "Got no socket.");
socket_fd = params->fds[0];
} else {
diff --git a/src/core/mount.c b/src/core/mount.c
index 8e83de0ba8..e672796694 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -549,25 +549,19 @@ static int mount_verify(Mount *m) {
if (r < 0)
return log_unit_error_errno(UNIT(m), r, "Failed to generate unit name from mount path: %m");
- if (!unit_has_name(UNIT(m), e)) {
- log_unit_error(UNIT(m), "Where= setting doesn't match unit name. Refusing.");
- return -ENOEXEC;
- }
+ if (!unit_has_name(UNIT(m), e))
+ return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Where= setting doesn't match unit name. Refusing.");
- if (mount_point_is_api(m->where) || mount_point_ignore(m->where)) {
- log_unit_error(UNIT(m), "Cannot create mount unit for API file system %s. Refusing.", m->where);
- return -ENOEXEC;
- }
+ if (mount_point_is_api(m->where) || mount_point_ignore(m->where))
+ return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Cannot create mount unit for API file system %s. Refusing.", m->where);
p = get_mount_parameters_fragment(m);
if (p && !p->what && !UNIT(m)->perpetual)
return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC),
"What= setting is missing. Refusing.");
- if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP) {
- log_unit_error(UNIT(m), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
- return -ENOEXEC;
- }
+ if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP)
+ return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
return 0;
}
diff --git a/src/core/path.c b/src/core/path.c
index ca3a91df27..b954ee1f47 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -283,10 +283,8 @@ static int path_verify(Path *p) {
assert(p);
assert(UNIT(p)->load_state == UNIT_LOADED);
- if (!p->specs) {
- log_unit_error(UNIT(p), "Path unit lacks path setting. Refusing.");
- return -ENOEXEC;
- }
+ if (!p->specs)
+ return log_unit_error_errno(UNIT(p), SYNTHETIC_ERRNO(ENOEXEC), "Path unit lacks path setting. Refusing.");
return 0;
}
diff --git a/src/core/scope.c b/src/core/scope.c
index a372f8d726..9434d03cdc 100644
--- a/src/core/scope.c
+++ b/src/core/scope.c
@@ -131,10 +131,8 @@ static int scope_verify(Scope *s) {
if (set_isempty(UNIT(s)->pids) &&
!MANAGER_IS_RELOADING(UNIT(s)->manager) &&
- !unit_has_name(UNIT(s), SPECIAL_INIT_SCOPE)) {
- log_unit_error(UNIT(s), "Scope has no PIDs. Refusing.");
- return -ENOENT;
- }
+ !unit_has_name(UNIT(s), SPECIAL_INIT_SCOPE))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOENT), "Scope has no PIDs. Refusing.");
return 0;
}
diff --git a/src/core/service.c b/src/core/service.c
index d7bdeb7cca..b1a4d0bf18 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -548,51 +548,35 @@ static int service_verify(Service *s) {
assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED);
- if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP]
- && UNIT(s)->success_action == EMERGENCY_ACTION_NONE) {
+ if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP] &&
+ UNIT(s)->success_action == EMERGENCY_ACTION_NONE)
/* FailureAction= only makes sense if one of the start or stop commands is specified.
* SuccessAction= will be executed unconditionally if no commands are specified. Hence,
* either a command or SuccessAction= are required. */
- log_unit_error(UNIT(s), "Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.");
- return -ENOEXEC;
- }
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.");
- if (s->type != SERVICE_ONESHOT && !s->exec_command[SERVICE_EXEC_START]) {
- log_unit_error(UNIT(s), "Service has no ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
- return -ENOEXEC;
- }
+ if (s->type != SERVICE_ONESHOT && !s->exec_command[SERVICE_EXEC_START])
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has no ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
- if (!s->remain_after_exit && !s->exec_command[SERVICE_EXEC_START] && UNIT(s)->success_action == EMERGENCY_ACTION_NONE) {
- log_unit_error(UNIT(s), "Service has no ExecStart= and no SuccessAction= settings and does not have RemainAfterExit=yes set. Refusing.");
- return -ENOEXEC;
- }
+ if (!s->remain_after_exit && !s->exec_command[SERVICE_EXEC_START] && UNIT(s)->success_action == EMERGENCY_ACTION_NONE)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has no ExecStart= and no SuccessAction= settings and does not have RemainAfterExit=yes set. Refusing.");
- if (s->type != SERVICE_ONESHOT && s->exec_command[SERVICE_EXEC_START]->command_next) {
- log_unit_error(UNIT(s), "Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
- return -ENOEXEC;
- }
+ if (s->type != SERVICE_ONESHOT && s->exec_command[SERVICE_EXEC_START]->command_next)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
- if (s->type == SERVICE_ONESHOT
- && !IN_SET(s->restart, SERVICE_RESTART_NO, SERVICE_RESTART_ON_FAILURE, SERVICE_RESTART_ON_ABNORMAL, SERVICE_RESTART_ON_WATCHDOG, SERVICE_RESTART_ON_ABORT)) {
- log_unit_error(UNIT(s), "Service has Restart= set to either always or on-success, which isn't allowed for Type=oneshot services. Refusing.");
- return -ENOEXEC;
- }
+ if (s->type == SERVICE_ONESHOT &&
+ !IN_SET(s->restart, SERVICE_RESTART_NO, SERVICE_RESTART_ON_FAILURE, SERVICE_RESTART_ON_ABNORMAL, SERVICE_RESTART_ON_WATCHDOG, SERVICE_RESTART_ON_ABORT))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has Restart= set to either always or on-success, which isn't allowed for Type=oneshot services. Refusing.");
- if (s->type == SERVICE_ONESHOT && !exit_status_set_is_empty(&s->restart_force_status)) {
- log_unit_error(UNIT(s), "Service has RestartForceStatus= set, which isn't allowed for Type=oneshot services. Refusing.");
- return -ENOEXEC;
- }
+ if (s->type == SERVICE_ONESHOT && !exit_status_set_is_empty(&s->restart_force_status))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has RestartForceStatus= set, which isn't allowed for Type=oneshot services. Refusing.");
- if (s->type == SERVICE_DBUS && !s->bus_name) {
- log_unit_error(UNIT(s), "Service is of type D-Bus but no D-Bus service name has been specified. Refusing.");
- return -ENOEXEC;
- }
+ if (s->type == SERVICE_DBUS && !s->bus_name)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service is of type D-Bus but no D-Bus service name has been specified. Refusing.");
- if (s->exec_context.pam_name && !IN_SET(s->kill_context.kill_mode, KILL_CONTROL_GROUP, KILL_MIXED)) {
- log_unit_error(UNIT(s), "Service has PAM enabled. Kill mode must be set to 'control-group' or 'mixed'. Refusing.");
- return -ENOEXEC;
- }
+ if (s->exec_context.pam_name && !IN_SET(s->kill_context.kill_mode, KILL_CONTROL_GROUP, KILL_MIXED))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has PAM enabled. Kill mode must be set to 'control-group' or 'mixed'. Refusing.");
if (s->usb_function_descriptors && !s->usb_function_strings)
log_unit_warning(UNIT(s), "Service has USBFunctionDescriptors= setting, but no USBFunctionStrings=. Ignoring.");
@@ -914,20 +898,14 @@ static int service_is_suitable_main_pid(Service *s, pid_t pid, int prio) {
* PID is questionnable but should be accepted if the source of configuration is trusted. > 0 if the PID is
* good */
- if (pid == getpid_cached() || pid == 1) {
- log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the manager, refusing.", pid);
- return -EPERM;
- }
+ if (pid == getpid_cached() || pid == 1)
+ return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the manager, refusing.", pid);
- if (pid == s->control_pid) {
- log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the control process, refusing.", pid);
- return -EPERM;
- }
+ if (pid == s->control_pid)
+ return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the control process, refusing.", pid);
- if (!pid_is_alive(pid)) {
- log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" does not exist or is a zombie.", pid);
- return -ESRCH;
- }
+ if (!pid_is_alive(pid))
+ return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(ESRCH), "New main PID "PID_FMT" does not exist or is a zombie.", pid);
owner = manager_get_unit_by_pid(UNIT(s)->manager, pid);
if (owner == UNIT(s)) {
@@ -988,20 +966,18 @@ static int service_load_pid_file(Service *s, bool may_warn) {
if (r == 0) {
struct stat st;
- if (questionable_pid_file) {
- log_unit_error(UNIT(s), "Refusing to accept PID outside of service control group, acquired through unsafe symlink chain: %s", s->pid_file);
- return -EPERM;
- }
+ if (questionable_pid_file)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EPERM),
+ "Refusing to accept PID outside of service control group, acquired through unsafe symlink chain: %s", s->pid_file);
/* Hmm, it's not clear if the new main PID is safe. Let's allow this if the PID file is owned by root */
if (fstat(fd, &st) < 0)
return log_unit_error_errno(UNIT(s), errno, "Failed to fstat() PID file O_PATH fd: %m");
- if (st.st_uid != 0) {
- log_unit_error(UNIT(s), "New main PID "PID_FMT" does not belong to service, and PID file is not owned by root. Refusing.", pid);
- return -EPERM;
- }
+ if (st.st_uid != 0)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EPERM),
+ "New main PID "PID_FMT" does not belong to service, and PID file is not owned by root. Refusing.", pid);
log_unit_debug(UNIT(s), "New main PID "PID_FMT" does not belong to service, but we'll accept it since PID file is owned by root.", pid);
}
@@ -2127,8 +2103,7 @@ static void service_enter_start(Service *s) {
/* There's no command line configured for the main command? Hmm, that is strange.
* This can only happen if the configuration changes at runtime. In this case,
* let's enter a failure state. */
- log_unit_error(UNIT(s), "There's no 'start' task anymore we could start.");
- r = -ENXIO;
+ r = log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENXIO), "There's no 'start' task anymore we could start.");
goto fail;
}
diff --git a/src/core/slice.c b/src/core/slice.c
index ee5c25932f..94eb56e1ca 100644
--- a/src/core/slice.c
+++ b/src/core/slice.c
@@ -94,19 +94,15 @@ static int slice_verify(Slice *s) {
assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED);
- if (!slice_name_is_valid(UNIT(s)->id)) {
- log_unit_error(UNIT(s), "Slice name %s is not valid. Refusing.", UNIT(s)->id);
- return -ENOEXEC;
- }
+ if (!slice_name_is_valid(UNIT(s)->id))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Slice name %s is not valid. Refusing.", UNIT(s)->id);
r = slice_build_parent_slice(UNIT(s)->id, &parent);
if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to determine parent slice: %m");
- if (parent ? !unit_has_name(UNIT_DEREF(UNIT(s)->slice), parent) : UNIT_ISSET(UNIT(s)->slice)) {
- log_unit_error(UNIT(s), "Located outside of parent slice. Refusing.");
- return -ENOEXEC;
- }
+ if (parent ? !unit_has_name(UNIT_DEREF(UNIT(s)->slice), parent) : UNIT_ISSET(UNIT(s)->slice))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Located outside of parent slice. Refusing.");
return 0;
}
diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c
index 1fe592af70..8cc1696a4f 100644
--- a/src/core/smack-setup.c
+++ b/src/core/smack-setup.c
@@ -384,8 +384,7 @@ int mac_smack_setup(bool *loaded_policy) {
log_info("Successfully wrote Smack onlycap list.");
break;
default:
- log_emergency_errno(r, "Failed to write Smack onlycap list: %m");
- return r;
+ return log_emergency_errno(r, "Failed to write Smack onlycap list: %m");
}
*loaded_policy = true;
diff --git a/src/core/socket.c b/src/core/socket.c
index 7f8ac4eae9..1f799830d1 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -402,35 +402,23 @@ static int socket_verify(Socket *s) {
assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED);
- if (!s->ports) {
- log_unit_error(UNIT(s), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.");
- return -ENOEXEC;
- }
+ if (!s->ports)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.");
- if (s->accept && have_non_accept_socket(s)) {
- log_unit_error(UNIT(s), "Unit configured for accepting sockets, but sockets are non-accepting. Refusing.");
- return -ENOEXEC;
- }
+ if (s->accept && have_non_accept_socket(s))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit configured for accepting sockets, but sockets are non-accepting. Refusing.");
- if (s->accept && s->max_connections <= 0) {
- log_unit_error(UNIT(s), "MaxConnection= setting too small. Refusing.");
- return -ENOEXEC;
- }
+ if (s->accept && s->max_connections <= 0)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "MaxConnection= setting too small. Refusing.");
- if (s->accept && UNIT_DEREF(s->service)) {
- log_unit_error(UNIT(s), "Explicit service configuration for accepting socket units not supported. Refusing.");
- return -ENOEXEC;
- }
+ if (s->accept && UNIT_DEREF(s->service))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Explicit service configuration for accepting socket units not supported. Refusing.");
- if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) {
- log_unit_error(UNIT(s), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing.");
- return -ENOEXEC;
- }
+ if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing.");
- if (!strv_isempty(s->symlinks) && !socket_find_symlink_target(s)) {
- log_unit_error(UNIT(s), "Unit has symlinks set but none or more than one node in the file system. Refusing.");
- return -ENOEXEC;
- }
+ if (!strv_isempty(s->symlinks) && !socket_find_symlink_target(s))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has symlinks set but none or more than one node in the file system. Refusing.");
return 0;
}
@@ -2507,17 +2495,13 @@ static int socket_start(Unit *u) {
service = SERVICE(UNIT_DEREF(s->service));
- if (UNIT(service)->load_state != UNIT_LOADED) {
- log_unit_error(u, "Socket service %s not loaded, refusing.", UNIT(service)->id);
- return -ENOENT;
- }
+ if (UNIT(service)->load_state != UNIT_LOADED)
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT), "Socket service %s not loaded, refusing.", UNIT(service)->id);
/* If the service is already active we cannot start the
* socket */
- if (!IN_SET(service->state, SERVICE_DEAD, SERVICE_FAILED, SERVICE_AUTO_RESTART)) {
- log_unit_error(u, "Socket service %s already active, refusing.", UNIT(service)->id);
- return -EBUSY;
- }
+ if (!IN_SET(service->state, SERVICE_DEAD, SERVICE_FAILED, SERVICE_AUTO_RESTART))
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(EBUSY), "Socket service %s already active, refusing.", UNIT(service)->id);
}
assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED));
diff --git a/src/core/swap.c b/src/core/swap.c
index 76e491ad94..ed06cf4b4b 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -287,15 +287,11 @@ static int swap_verify(Swap *s) {
if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to generate unit name from path: %m");
- if (!unit_has_name(UNIT(s), e)) {
- log_unit_error(UNIT(s), "Value of What= and unit name do not match, not loading.");
- return -ENOEXEC;
- }
+ if (!unit_has_name(UNIT(s), e))
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Value of What= and unit name do not match, not loading.");
- if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) {
- log_unit_error(UNIT(s), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing to load.");
- return -ENOEXEC;
- }
+ if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP)
+ return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing to load.");
return 0;
}
diff --git a/src/core/timer.c b/src/core/timer.c
index 8ab9b0e519..f42c86da76 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -75,10 +75,8 @@ static int timer_verify(Timer *t) {
assert(t);
assert(UNIT(t)->load_state == UNIT_LOADED);
- if (!t->values && !t->on_clock_change && !t->on_timezone_change) {
- log_unit_error(UNIT(t), "Timer unit lacks value setting. Refusing.");
- return -ENOEXEC;
- }
+ if (!t->values && !t->on_clock_change && !t->on_timezone_change)
+ return log_unit_error_errno(UNIT(t), SYNTHETIC_ERRNO(ENOEXEC), "Timer unit lacks value setting. Refusing.");
return 0;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 45a417a090..e209efd4a6 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1668,8 +1668,8 @@ int unit_load(Unit *u) {
goto fail;
if (u->on_failure_job_mode == JOB_ISOLATE && hashmap_size(u->dependencies[UNIT_ON_FAILURE]) > 1) {
- log_unit_error(u, "More than one OnFailure= dependencies specified but OnFailureJobMode=isolate set. Refusing.");
- r = -ENOEXEC;
+ r = log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOEXEC),
+ "More than one OnFailure= dependencies specified but OnFailureJobMode=isolate set. Refusing.");
goto fail;
}
@@ -2022,10 +2022,8 @@ int unit_reload(Unit *u) {
if (state == UNIT_RELOADING)
return -EAGAIN;
- if (state != UNIT_ACTIVE) {
- log_unit_warning(u, "Unit cannot be reloaded because it is inactive.");
- return -ENOEXEC;
- }
+ if (state != UNIT_ACTIVE)
+ return log_unit_warning_errno(u, SYNTHETIC_ERRNO(ENOEXEC), "Unit cannot be reloaded because it is inactive.");
following = unit_following(u);
if (following) {