core: use SYNTHETIC_ERRNO() macro

This commit is contained in:
Yu Watanabe 2020-11-26 09:27:21 +09:00
parent 2762ce2d89
commit d85ff94477
14 changed files with 95 additions and 177 deletions

View File

@ -174,19 +174,15 @@ static int automount_verify(Automount *a) {
assert(a); assert(a);
assert(UNIT(a)->load_state == UNIT_LOADED); assert(UNIT(a)->load_state == UNIT_LOADED);
if (path_equal(a->where, "/")) { if (path_equal(a->where, "/"))
log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing."); return log_unit_error_errno(UNIT(a), SYNTHETIC_ERRNO(ENOEXEC), "Cannot have an automount unit for the root directory. Refusing.");
return -ENOEXEC;
}
r = unit_name_from_path(a->where, ".automount", &e); r = unit_name_from_path(a->where, ".automount", &e);
if (r < 0) if (r < 0)
return log_unit_error_errno(UNIT(a), r, "Failed to generate unit name from path: %m"); return log_unit_error_errno(UNIT(a), r, "Failed to generate unit name from path: %m");
if (!unit_has_name(UNIT(a), e)) { if (!unit_has_name(UNIT(a), e))
log_unit_error(UNIT(a), "Where= setting doesn't match unit name. Refusing."); return log_unit_error_errno(UNIT(a), SYNTHETIC_ERRNO(ENOEXEC), "Where= setting doesn't match unit name. Refusing.");
return -ENOEXEC;
}
return 0; return 0;
} }
@ -811,10 +807,8 @@ static int automount_start(Unit *u) {
assert(a); assert(a);
assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED)); assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED));
if (path_is_mount_point(a->where, NULL, 0) > 0) { 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 log_unit_error_errno(u, SYNTHETIC_ERRNO(EEXIST), "Path %s is already a mount point, refusing start.", a->where);
return -EEXIST;
}
r = unit_test_trigger_loaded(u); r = unit_test_trigger_loaded(u);
if (r < 0) if (r < 0)

View File

@ -686,14 +686,10 @@ int bpf_firewall_install(Unit *u) {
supported = bpf_firewall_supported(); supported = bpf_firewall_supported();
if (supported < 0) if (supported < 0)
return supported; return supported;
if (supported == BPF_FIREWALL_UNSUPPORTED) { if (supported == BPF_FIREWALL_UNSUPPORTED)
log_unit_debug(u, "BPF firewalling not supported on this manager, proceeding without."); return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "BPF firewalling not supported on this manager, proceeding without.");
return -EOPNOTSUPP; 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 && 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_SUPPORTED_WITH_MULTI && if (supported != BPF_FIREWALL_SUPPORTED_WITH_MULTI &&
(!set_isempty(u->ip_bpf_custom_ingress) || !set_isempty(u->ip_bpf_custom_egress))) (!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."); return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "BPF_F_ALLOW_MULTI not supported on this manager, cannot attach custom BPF programs.");

View File

@ -515,11 +515,10 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
if (DEVICE(u)->state == DEVICE_PLUGGED && if (DEVICE(u)->state == DEVICE_PLUGGED &&
DEVICE(u)->sysfs && DEVICE(u)->sysfs &&
sysfs && sysfs &&
!path_equal(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.", return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EEXIST),
e, DEVICE(u)->sysfs, sysfs); "Device %s appeared twice with different sysfs paths %s and %s, ignoring the latter.",
return -EEXIST; e, DEVICE(u)->sysfs, sysfs);
}
delete = false; delete = false;

View File

@ -3769,23 +3769,20 @@ static int exec_child(
r = dynamic_creds_realize(dcreds, suggested_paths, &uid, &gid); r = dynamic_creds_realize(dcreds, suggested_paths, &uid, &gid);
if (r < 0) { if (r < 0) {
*exit_status = EXIT_USER; *exit_status = EXIT_USER;
if (r == -EILSEQ) { if (r == -EILSEQ)
log_unit_error(unit, "Failed to update dynamic user credentials: User or group with specified name already exists."); return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EOPNOTSUPP),
return -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"); return log_unit_error_errno(unit, r, "Failed to update dynamic user credentials: %m");
} }
if (!uid_is_valid(uid)) { if (!uid_is_valid(uid)) {
*exit_status = EXIT_USER; *exit_status = EXIT_USER;
log_unit_error(unit, "UID validation failed for \""UID_FMT"\"", uid); return log_unit_error_errno(unit, SYNTHETIC_ERRNO(ESRCH), "UID validation failed for \""UID_FMT"\"", uid);
return -ESRCH;
} }
if (!gid_is_valid(gid)) { if (!gid_is_valid(gid)) {
*exit_status = EXIT_USER; *exit_status = EXIT_USER;
log_unit_error(unit, "GID validation failed for \""GID_FMT"\"", gid); return log_unit_error_errno(unit, SYNTHETIC_ERRNO(ESRCH), "GID validation failed for \""GID_FMT"\"", gid);
return -ESRCH;
} }
if (dcreds->user) if (dcreds->user)
@ -4628,15 +4625,11 @@ int exec_spawn(Unit *unit,
context->std_output == EXEC_OUTPUT_SOCKET || context->std_output == EXEC_OUTPUT_SOCKET ||
context->std_error == EXEC_OUTPUT_SOCKET) { context->std_error == EXEC_OUTPUT_SOCKET) {
if (params->n_socket_fds > 1) { if (params->n_socket_fds > 1)
log_unit_error(unit, "Got more than one socket."); return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EINVAL), "Got more than one socket.");
return -EINVAL;
}
if (params->n_socket_fds == 0) { if (params->n_socket_fds == 0)
log_unit_error(unit, "Got no socket."); return log_unit_error_errno(unit, SYNTHETIC_ERRNO(EINVAL), "Got no socket.");
return -EINVAL;
}
socket_fd = params->fds[0]; socket_fd = params->fds[0];
} else { } else {

View File

@ -549,25 +549,19 @@ static int mount_verify(Mount *m) {
if (r < 0) if (r < 0)
return log_unit_error_errno(UNIT(m), r, "Failed to generate unit name from mount path: %m"); return log_unit_error_errno(UNIT(m), r, "Failed to generate unit name from mount path: %m");
if (!unit_has_name(UNIT(m), e)) { if (!unit_has_name(UNIT(m), e))
log_unit_error(UNIT(m), "Where= setting doesn't match unit name. Refusing."); return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Where= setting doesn't match unit name. Refusing.");
return -ENOEXEC;
}
if (mount_point_is_api(m->where) || mount_point_ignore(m->where)) { 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 log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Cannot create mount unit for API file system %s. Refusing.", m->where);
return -ENOEXEC;
}
p = get_mount_parameters_fragment(m); p = get_mount_parameters_fragment(m);
if (p && !p->what && !UNIT(m)->perpetual) if (p && !p->what && !UNIT(m)->perpetual)
return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC),
"What= setting is missing. Refusing."); "What= setting is missing. Refusing.");
if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP) { 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 log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
return -ENOEXEC;
}
return 0; return 0;
} }

View File

@ -283,10 +283,8 @@ static int path_verify(Path *p) {
assert(p); assert(p);
assert(UNIT(p)->load_state == UNIT_LOADED); assert(UNIT(p)->load_state == UNIT_LOADED);
if (!p->specs) { if (!p->specs)
log_unit_error(UNIT(p), "Path unit lacks path setting. Refusing."); return log_unit_error_errno(UNIT(p), SYNTHETIC_ERRNO(ENOEXEC), "Path unit lacks path setting. Refusing.");
return -ENOEXEC;
}
return 0; return 0;
} }

View File

@ -131,10 +131,8 @@ static int scope_verify(Scope *s) {
if (set_isempty(UNIT(s)->pids) && if (set_isempty(UNIT(s)->pids) &&
!MANAGER_IS_RELOADING(UNIT(s)->manager) && !MANAGER_IS_RELOADING(UNIT(s)->manager) &&
!unit_has_name(UNIT(s), SPECIAL_INIT_SCOPE)) { !unit_has_name(UNIT(s), SPECIAL_INIT_SCOPE))
log_unit_error(UNIT(s), "Scope has no PIDs. Refusing."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOENT), "Scope has no PIDs. Refusing.");
return -ENOENT;
}
return 0; return 0;
} }

View File

@ -548,51 +548,35 @@ static int service_verify(Service *s) {
assert(s); assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED); assert(UNIT(s)->load_state == UNIT_LOADED);
if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP] if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP] &&
&& UNIT(s)->success_action == EMERGENCY_ACTION_NONE) { UNIT(s)->success_action == EMERGENCY_ACTION_NONE)
/* FailureAction= only makes sense if one of the start or stop commands is specified. /* 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, * SuccessAction= will be executed unconditionally if no commands are specified. Hence,
* either a command or SuccessAction= are required. */ * either a command or SuccessAction= are required. */
log_unit_error(UNIT(s), "Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.");
return -ENOEXEC;
}
if (s->type != SERVICE_ONESHOT && !s->exec_command[SERVICE_EXEC_START]) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has no ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
return -ENOEXEC;
}
if (!s->remain_after_exit && !s->exec_command[SERVICE_EXEC_START] && UNIT(s)->success_action == EMERGENCY_ACTION_NONE) { 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 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.");
return -ENOEXEC;
}
if (s->type != SERVICE_ONESHOT && s->exec_command[SERVICE_EXEC_START]->command_next) { 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 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.");
return -ENOEXEC;
}
if (s->type == SERVICE_ONESHOT 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)) { !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 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.");
return -ENOEXEC;
}
if (s->type == SERVICE_ONESHOT && !exit_status_set_is_empty(&s->restart_force_status)) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has RestartForceStatus= set, which isn't allowed for Type=oneshot services. Refusing.");
return -ENOEXEC;
}
if (s->type == SERVICE_DBUS && !s->bus_name) { 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 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.");
return -ENOEXEC;
}
if (s->exec_context.pam_name && !IN_SET(s->kill_context.kill_mode, KILL_CONTROL_GROUP, KILL_MIXED)) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has PAM enabled. Kill mode must be set to 'control-group' or 'mixed'. Refusing.");
return -ENOEXEC;
}
if (s->usb_function_descriptors && !s->usb_function_strings) if (s->usb_function_descriptors && !s->usb_function_strings)
log_unit_warning(UNIT(s), "Service has USBFunctionDescriptors= setting, but no USBFunctionStrings=. Ignoring."); 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 * PID is questionnable but should be accepted if the source of configuration is trusted. > 0 if the PID is
* good */ * good */
if (pid == getpid_cached() || pid == 1) { if (pid == getpid_cached() || pid == 1)
log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the manager, refusing.", pid); return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the manager, refusing.", pid);
return -EPERM;
}
if (pid == s->control_pid) { if (pid == s->control_pid)
log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the control process, refusing.", pid); return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the control process, refusing.", pid);
return -EPERM;
}
if (!pid_is_alive(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 log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(ESRCH), "New main PID "PID_FMT" does not exist or is a zombie.", pid);
return -ESRCH;
}
owner = manager_get_unit_by_pid(UNIT(s)->manager, pid); owner = manager_get_unit_by_pid(UNIT(s)->manager, pid);
if (owner == UNIT(s)) { if (owner == UNIT(s)) {
@ -988,20 +966,18 @@ static int service_load_pid_file(Service *s, bool may_warn) {
if (r == 0) { if (r == 0) {
struct stat st; struct stat st;
if (questionable_pid_file) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EPERM),
return -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 */ /* 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) if (fstat(fd, &st) < 0)
return log_unit_error_errno(UNIT(s), errno, "Failed to fstat() PID file O_PATH fd: %m"); return log_unit_error_errno(UNIT(s), errno, "Failed to fstat() PID file O_PATH fd: %m");
if (st.st_uid != 0) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EPERM),
return -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); 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. /* 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, * This can only happen if the configuration changes at runtime. In this case,
* let's enter a failure state. */ * let's enter a failure state. */
log_unit_error(UNIT(s), "There's no 'start' task anymore we could start."); r = log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENXIO), "There's no 'start' task anymore we could start.");
r = -ENXIO;
goto fail; goto fail;
} }

View File

@ -94,19 +94,15 @@ static int slice_verify(Slice *s) {
assert(s); assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED); assert(UNIT(s)->load_state == UNIT_LOADED);
if (!slice_name_is_valid(UNIT(s)->id)) { if (!slice_name_is_valid(UNIT(s)->id))
log_unit_error(UNIT(s), "Slice name %s is not valid. Refusing.", UNIT(s)->id); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Slice name %s is not valid. Refusing.", UNIT(s)->id);
return -ENOEXEC;
}
r = slice_build_parent_slice(UNIT(s)->id, &parent); r = slice_build_parent_slice(UNIT(s)->id, &parent);
if (r < 0) if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to determine parent slice: %m"); 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)) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Located outside of parent slice. Refusing.");
return -ENOEXEC;
}
return 0; return 0;
} }

View File

@ -384,8 +384,7 @@ int mac_smack_setup(bool *loaded_policy) {
log_info("Successfully wrote Smack onlycap list."); log_info("Successfully wrote Smack onlycap list.");
break; break;
default: default:
log_emergency_errno(r, "Failed to write Smack onlycap list: %m"); return log_emergency_errno(r, "Failed to write Smack onlycap list: %m");
return r;
} }
*loaded_policy = true; *loaded_policy = true;

View File

@ -402,35 +402,23 @@ static int socket_verify(Socket *s) {
assert(s); assert(s);
assert(UNIT(s)->load_state == UNIT_LOADED); assert(UNIT(s)->load_state == UNIT_LOADED);
if (!s->ports) { if (!s->ports)
log_unit_error(UNIT(s), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.");
return -ENOEXEC;
}
if (s->accept && have_non_accept_socket(s)) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit configured for accepting sockets, but sockets are non-accepting. Refusing.");
return -ENOEXEC;
}
if (s->accept && s->max_connections <= 0) { if (s->accept && s->max_connections <= 0)
log_unit_error(UNIT(s), "MaxConnection= setting too small. Refusing."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "MaxConnection= setting too small. Refusing.");
return -ENOEXEC;
}
if (s->accept && UNIT_DEREF(s->service)) { if (s->accept && UNIT_DEREF(s->service))
log_unit_error(UNIT(s), "Explicit service configuration for accepting socket units not supported. Refusing."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Explicit service configuration for accepting socket units not supported. Refusing.");
return -ENOEXEC;
}
if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) { 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 log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing.");
return -ENOEXEC;
}
if (!strv_isempty(s->symlinks) && !socket_find_symlink_target(s)) { 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 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 -ENOEXEC;
}
return 0; return 0;
} }
@ -2507,17 +2495,13 @@ static int socket_start(Unit *u) {
service = SERVICE(UNIT_DEREF(s->service)); service = SERVICE(UNIT_DEREF(s->service));
if (UNIT(service)->load_state != UNIT_LOADED) { if (UNIT(service)->load_state != UNIT_LOADED)
log_unit_error(u, "Socket service %s not loaded, refusing.", UNIT(service)->id); return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT), "Socket service %s not loaded, refusing.", UNIT(service)->id);
return -ENOENT;
}
/* If the service is already active we cannot start the /* If the service is already active we cannot start the
* socket */ * socket */
if (!IN_SET(service->state, SERVICE_DEAD, SERVICE_FAILED, SERVICE_AUTO_RESTART)) { 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 log_unit_error_errno(u, SYNTHETIC_ERRNO(EBUSY), "Socket service %s already active, refusing.", UNIT(service)->id);
return -EBUSY;
}
} }
assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED)); assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED));

View File

@ -287,15 +287,11 @@ static int swap_verify(Swap *s) {
if (r < 0) if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to generate unit name from path: %m"); return log_unit_error_errno(UNIT(s), r, "Failed to generate unit name from path: %m");
if (!unit_has_name(UNIT(s), e)) { if (!unit_has_name(UNIT(s), e))
log_unit_error(UNIT(s), "Value of What= and unit name do not match, not loading."); return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Value of What= and unit name do not match, not loading.");
return -ENOEXEC;
}
if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) { 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 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 -ENOEXEC;
}
return 0; return 0;
} }

View File

@ -75,10 +75,8 @@ static int timer_verify(Timer *t) {
assert(t); assert(t);
assert(UNIT(t)->load_state == UNIT_LOADED); assert(UNIT(t)->load_state == UNIT_LOADED);
if (!t->values && !t->on_clock_change && !t->on_timezone_change) { if (!t->values && !t->on_clock_change && !t->on_timezone_change)
log_unit_error(UNIT(t), "Timer unit lacks value setting. Refusing."); return log_unit_error_errno(UNIT(t), SYNTHETIC_ERRNO(ENOEXEC), "Timer unit lacks value setting. Refusing.");
return -ENOEXEC;
}
return 0; return 0;
} }

View File

@ -1668,8 +1668,8 @@ int unit_load(Unit *u) {
goto fail; goto fail;
if (u->on_failure_job_mode == JOB_ISOLATE && hashmap_size(u->dependencies[UNIT_ON_FAILURE]) > 1) { 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 = log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOEXEC),
r = -ENOEXEC; "More than one OnFailure= dependencies specified but OnFailureJobMode=isolate set. Refusing.");
goto fail; goto fail;
} }
@ -2022,10 +2022,8 @@ int unit_reload(Unit *u) {
if (state == UNIT_RELOADING) if (state == UNIT_RELOADING)
return -EAGAIN; return -EAGAIN;
if (state != UNIT_ACTIVE) { if (state != UNIT_ACTIVE)
log_unit_warning(u, "Unit cannot be reloaded because it is inactive."); return log_unit_warning_errno(u, SYNTHETIC_ERRNO(ENOEXEC), "Unit cannot be reloaded because it is inactive.");
return -ENOEXEC;
}
following = unit_following(u); following = unit_following(u);
if (following) { if (following) {