X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=5c54a34bcdc7f3b98a4f1a90e6f195516bc5b01d;hb=5e56b378b40dc4dc5557e653487b608fd91fcc26;hp=10dc79c8a2f1ec8276f5af7efb2b8902613d57c8;hpb=817e224bbce3ed157817961ef19c80a250845a05;p=elogind.git diff --git a/src/core/service.c b/src/core/service.c index 10dc79c8a..5c54a34bc 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -266,15 +266,9 @@ static void service_done(Unit *u) { s->control_command = NULL; s->main_command = NULL; - set_free(s->restart_ignore_status.code); - s->restart_ignore_status.code = NULL; - set_free(s->restart_ignore_status.signal); - s->restart_ignore_status.signal = NULL; - - set_free(s->success_status.code); - s->success_status.code = NULL; - set_free(s->success_status.signal); - s->success_status.signal = NULL; + exit_status_set_free(&s->restart_prevent_status); + exit_status_set_free(&s->restart_force_status); + exit_status_set_free(&s->success_status); /* This will leak a process, but at least no memory or any of * our resources */ @@ -337,7 +331,12 @@ static int service_verify(Service *s) { } if (s->type == SERVICE_ONESHOT && s->restart != SERVICE_RESTART_NO) { - log_error_unit(UNIT(s)->id, "%s has Restart setting other than no, which isn't allowed for Type=oneshot services. Refusing.", UNIT(s)->id); + log_error_unit(UNIT(s)->id, "%s has Restart= setting other than no, which isn't allowed for Type=oneshot services. Refusing.", UNIT(s)->id); + return -EINVAL; + } + + if (s->type == SERVICE_ONESHOT && !exit_status_set_is_empty(&s->restart_force_status)) { + log_error_unit(UNIT(s)->id, "%s has RestartForceStatus= set, which isn't allowed for Type=oneshot services. Refusing.", UNIT(s)->id); return -EINVAL; } @@ -1071,11 +1070,11 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) (s->restart == SERVICE_RESTART_ON_FAILURE && s->result != SERVICE_SUCCESS) || (s->restart == SERVICE_RESTART_ON_ABNORMAL && !IN_SET(s->result, SERVICE_SUCCESS, SERVICE_FAILURE_EXIT_CODE)) || (s->restart == SERVICE_RESTART_ON_WATCHDOG && s->result == SERVICE_FAILURE_WATCHDOG) || - (s->restart == SERVICE_RESTART_ON_ABORT && IN_SET(s->result, SERVICE_FAILURE_SIGNAL, SERVICE_FAILURE_CORE_DUMP))) && - (s->result != SERVICE_FAILURE_EXIT_CODE || - !set_contains(s->restart_ignore_status.code, INT_TO_PTR(s->main_exec_status.status))) && - (s->result != SERVICE_FAILURE_SIGNAL || - !set_contains(s->restart_ignore_status.signal, INT_TO_PTR(s->main_exec_status.status)))) { + (s->restart == SERVICE_RESTART_ON_ABORT && IN_SET(s->result, SERVICE_FAILURE_SIGNAL, SERVICE_FAILURE_CORE_DUMP)) || + (s->main_exec_status.code == CLD_EXITED && set_contains(s->restart_force_status.status, INT_TO_PTR(s->main_exec_status.status))) || + (IN_SET(s->main_exec_status.code, CLD_KILLED, CLD_DUMPED) && set_contains(s->restart_force_status.signal, INT_TO_PTR(s->main_exec_status.status)))) && + (s->main_exec_status.code != CLD_EXITED || !set_contains(s->restart_prevent_status.status, INT_TO_PTR(s->main_exec_status.status))) && + (!IN_SET(s->main_exec_status.code, CLD_KILLED, CLD_DUMPED) || !set_contains(s->restart_prevent_status.signal, INT_TO_PTR(s->main_exec_status.status)))) { r = service_arm_timer(s, s->restart_usec); if (r < 0) @@ -1421,8 +1420,7 @@ static void service_enter_start_pre(Service *s) { return; fail: - log_warning_unit(UNIT(s)->id, - "%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r)); + log_warning_unit(UNIT(s)->id, "%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r)); service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true); } @@ -1434,8 +1432,7 @@ static void service_enter_restart(Service *s) { if (UNIT(s)->job && UNIT(s)->job->type == JOB_STOP) { /* Don't restart things if we are going down anyway */ - log_info_unit(UNIT(s)->id, - "Stop job pending for unit, delaying automatic restart."); + log_info_unit(UNIT(s)->id, "Stop job pending for unit, delaying automatic restart."); r = service_arm_timer(s, s->restart_usec); if (r < 0) @@ -1456,8 +1453,7 @@ static void service_enter_restart(Service *s) { * it will be canceled as part of the service_stop() call that * is executed as part of JOB_RESTART. */ - log_debug_unit(UNIT(s)->id, - "%s scheduled restart job.", UNIT(s)->id); + log_debug_unit(UNIT(s)->id, "%s scheduled restart job.", UNIT(s)->id); return; fail: @@ -2579,7 +2575,6 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) { } if (s->notify_access == NOTIFY_MAIN && pid != s->main_pid) { - if (s->main_pid != 0) log_warning_unit(u->id, "%s: Got notification message from PID "PID_FMT", but reception only permitted for main PID "PID_FMT, u->id, pid, s->main_pid); else @@ -2588,14 +2583,10 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) { } /* Interpret MAINPID= */ - if ((e = strv_find_prefix(tags, "MAINPID=")) && - (s->state == SERVICE_START || - s->state == SERVICE_START_POST || - s->state == SERVICE_RUNNING || - s->state == SERVICE_RELOAD)) { - + e = strv_find_prefix(tags, "MAINPID="); + if (e && IN_SET(s->state, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD)) { if (parse_pid(e + 8, &pid) < 0) - log_warning_unit(u->id, "Failed to parse notification message %s", e); + log_warning_unit(u->id, "Failed to parse MAINPID= field in notification message: %s", e); else { log_debug_unit(u->id, "%s: got %s", u->id, e); service_set_main_pid(s, pid); @@ -2641,6 +2632,23 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) { free(t); } + /* Interpret ERRNO= */ + e = strv_find_prefix(tags, "ERRNO="); + if (e) { + int status_errno; + + if (safe_atoi(e + 6, &status_errno) < 0) + log_warning_unit(u->id, "Failed to parse ERRNO= field in notification message: %s", e); + else { + log_debug_unit(u->id, "%s: got %s", u->id, e); + + if (s->status_errno != status_errno) { + s->status_errno = status_errno; + notify_dbus = true; + } + } + } + /* Interpret WATCHDOG= */ if (strv_find(tags, "WATCHDOG=1")) { log_debug_unit(u->id, "%s: got WATCHDOG=1", u->id);