core/service: allow RestartForceExitStatus= for oneshot services

I think this was just overlooked in #13754, which removed
the restriction of Restart= on Type=oneshot services.
There's no reason to prevent RestartForceExitStatus=
now that Restart= has been allowed.

Closes #31148
This commit is contained in:
Mike Yuan
2024-02-10 21:19:36 +08:00
parent a5d9df35ac
commit 189a08e83d
4 changed files with 81 additions and 13 deletions
+8 -3
View File
@@ -665,9 +665,6 @@ static int service_verify(Service *s) {
if (s->type == SERVICE_ONESHOT && IN_SET(s->restart, SERVICE_RESTART_ALWAYS, SERVICE_RESTART_ON_SUCCESS))
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))
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has RestartForceExitStatus= set, which isn't allowed for Type=oneshot services. Refusing.");
if (s->type == SERVICE_ONESHOT && s->exit_type == SERVICE_EXIT_CGROUP)
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has ExitType=cgroup set, which isn't allowed for Type=oneshot services. Refusing.");
@@ -1900,6 +1897,7 @@ static int cgroup_good(Service *s) {
static bool service_shall_restart(Service *s, const char **reason) {
assert(s);
assert(reason);
/* Don't restart after manual stops */
if (s->forbid_restart) {
@@ -1915,6 +1913,13 @@ static bool service_shall_restart(Service *s, const char **reason) {
/* Restart if the exit code/status are configured as restart triggers */
if (exit_status_set_test(&s->restart_force_status, s->main_exec_status.code, s->main_exec_status.status)) {
/* Don't allow Type=oneshot services to restart on success. Note that Restart=always/on-success
* is already rejected in service_verify. */
if (s->type == SERVICE_ONESHOT && s->result == SERVICE_SUCCESS) {
*reason = "service type and exit status";
return false;
}
*reason = "forced by exit status";
return true;
}