From 6f40aa4547ac2c62ade78268108a4fa60b6e9fff Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 1 Jun 2018 18:06:54 +0200 Subject: [PATCH] core: add a couple of more error cases that should result in "bad-setting" This changes a number of EINVAL cases to ENOEXEC, so that we enter "bad-setting" state if they fail. --- src/core/automount.c | 4 ++-- src/core/load-fragment.c | 8 ++++---- src/core/mount.c | 8 ++++---- src/core/path.c | 2 +- src/core/scope.c | 2 +- src/core/service.c | 16 ++++++++-------- src/core/slice.c | 4 ++-- src/core/socket.c | 12 ++++++------ src/core/swap.c | 4 ++-- src/core/timer.c | 2 +- src/core/unit.c | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/core/automount.c b/src/core/automount.c index 0aba87b..3251e8a 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -172,7 +172,7 @@ static int automount_verify(Automount *a) { if (path_equal(a->where, "/")) { log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing."); - return -EINVAL; + return -ENOEXEC; } r = unit_name_from_path(a->where, ".automount", &e); @@ -181,7 +181,7 @@ static int automount_verify(Automount *a) { if (!unit_has_name(UNIT(a), e)) { log_unit_error(UNIT(a), "Where= setting doesn't match unit name. Refusing."); - return -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0953355..fb5b742 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -820,7 +820,7 @@ int config_parse_exec_input( resolved = mfree(resolved); else if (!fdname_is_valid(resolved)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); - return -EINVAL; + return -ENOEXEC; } free_and_replace(c->stdio_fdname[STDIN_FILENO], resolved); @@ -836,7 +836,7 @@ int config_parse_exec_input( r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); if (r < 0) - return -EINVAL; + return -ENOEXEC; free_and_replace(c->stdio_file[STDIN_FILENO], resolved); @@ -1001,7 +1001,7 @@ int config_parse_exec_output( resolved = mfree(resolved); else if (!fdname_is_valid(resolved)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); - return -EINVAL; + return -ENOEXEC; } eo = EXEC_OUTPUT_NAMED_FD; @@ -1014,7 +1014,7 @@ int config_parse_exec_output( r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); if (r < 0) - return -EINVAL; + return -ENOEXEC; eo = EXEC_OUTPUT_FILE; diff --git a/src/core/mount.c b/src/core/mount.c index dcc4465..c588ef9 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -517,23 +517,23 @@ static int mount_verify(Mount *m) { if (!unit_has_name(UNIT(m), e)) { log_unit_error(UNIT(m), "Where= setting doesn't match unit name. Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } p = get_mount_parameters_fragment(m); if (p && !p->what) { log_unit_error(UNIT(m), "What= setting is missing. Refusing."); - return -EBADMSG; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/path.c b/src/core/path.c index 6eacd95..e97da44 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -289,7 +289,7 @@ static int path_verify(Path *p) { if (!p->specs) { log_unit_error(UNIT(p), "Path unit lacks path setting. Refusing."); - return -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/scope.c b/src/core/scope.c index 27ff545..f30d135 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -133,7 +133,7 @@ static int scope_verify(Scope *s) { !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 -EINVAL; + return -ENOENT; } return 0; diff --git a/src/core/service.c b/src/core/service.c index 2d43779..33fd36f 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -543,37 +543,37 @@ static int service_verify(Service *s) { if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP]) { log_unit_error(UNIT(s), "Service lacks both ExecStart= and ExecStop= setting. Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } if (!s->remain_after_exit && !s->exec_command[SERVICE_EXEC_START]) { log_unit_error(UNIT(s), "Service has no ExecStart= setting, which is only allowed for RemainAfterExit=yes services. Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } if (s->type == SERVICE_ONESHOT && s->restart != SERVICE_RESTART_NO) { log_unit_error(UNIT(s), "Service has Restart= setting other than no, which isn't allowed for Type=oneshot services. Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } if (s->bus_name && s->type != SERVICE_DBUS) @@ -581,7 +581,7 @@ static int service_verify(Service *s) { 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 -EINVAL; + return -ENOEXEC; } if (s->usb_function_descriptors && !s->usb_function_strings) diff --git a/src/core/slice.c b/src/core/slice.c index e8a7c9a..f903d51 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -97,7 +97,7 @@ static int slice_verify(Slice *s) { if (!slice_name_is_valid(UNIT(s)->id)) { log_unit_error(UNIT(s), "Slice name %s is not valid. Refusing.", UNIT(s)->id); - return -EINVAL; + return -ENOEXEC; } r = slice_build_parent_slice(UNIT(s)->id, &parent); @@ -106,7 +106,7 @@ static int slice_verify(Slice *s) { 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 -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/socket.c b/src/core/socket.c index f97ff64..25e99e9 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -441,32 +441,32 @@ static int socket_verify(Socket *s) { if (!s->ports) { log_unit_error(UNIT(s), "Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } if (s->accept && s->max_connections <= 0) { log_unit_error(UNIT(s), "MaxConnection= setting too small. Refusing."); - return -EINVAL; + return -ENOEXEC; } if (s->accept && UNIT_DEREF(s->service)) { log_unit_error(UNIT(s), "Explicit service configuration for accepting socket units not supported. Refusing."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/swap.c b/src/core/swap.c index 398eb02..b61eab3 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -240,12 +240,12 @@ static int swap_verify(Swap *s) { if (!unit_has_name(UNIT(s), e)) { log_unit_error(UNIT(s), "Value of What= and unit name do not match, not loading."); - return -EINVAL; + return -ENOEXEC; } 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 -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/timer.c b/src/core/timer.c index 5babb6d..5b65e6e 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -78,7 +78,7 @@ static int timer_verify(Timer *t) { if (!t->values) { log_unit_error(UNIT(t), "Timer unit lacks value setting. Refusing."); - return -EINVAL; + return -ENOEXEC; } return 0; diff --git a/src/core/unit.c b/src/core/unit.c index d21c09c..0d9a6b3 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1510,7 +1510,7 @@ int unit_load(Unit *u) { 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 = -EINVAL; + r = -ENOEXEC; goto fail; } -- 2.7.4