From: Mike Yuan Date: Sat, 3 Aug 2024 19:46:51 +0000 (+0200) Subject: core/service: drop redundant flush_n_restarts indicator X-Git-Tag: v257-rc1~748 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce31dbf4455c94d6639d5be1f90239d3a7ad78c0;p=thirdparty%2Fsystemd.git core/service: drop redundant flush_n_restarts indicator Now that we track auto-restarts with a dedicated state, there's no need for a separate variable for this. I also took the chance to reorder some struct members. --- diff --git a/src/core/service.c b/src/core/service.c index 49ed3b088a7..ca6040a0557 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2074,14 +2074,12 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) log_unit_debug(UNIT(s), "Next restart interval calculated as: %s", FORMAT_TIMESPAN(restart_usec_next, 0)); service_set_state(s, SERVICE_AUTO_RESTART); - } else { + } else + /* If we shan't restart, the restart counter would be flushed out. But rather than doing that + * immediately here, this is delegated to service_start(), i.e. next start, so that the user + * can still introspect the counter. */ service_set_state(s, end_state); - /* If we shan't restart, then flush out the restart counter. But don't do that immediately, so that the - * user can still introspect the counter. Do so on the next start. */ - s->flush_n_restarts = true; - } - /* The new state is in effect, let's decrease the fd store ref counter again. Let's also re-add us to the GC * queue, so that the fd store is possibly gc'ed again */ unit_add_to_gc_queue(UNIT(s)); @@ -2595,7 +2593,6 @@ static void service_enter_restart(Service *s, bool shortcut) { * fully stopped, i.e. as long as it remains up or remains in auto-start states. The user can reset * the counter explicitly however via the usual "systemctl reset-failure" logic. */ s->n_restarts++; - s->flush_n_restarts = false; log_unit_struct(UNIT(s), LOG_INFO, "MESSAGE_ID=" SD_MESSAGE_UNIT_RESTART_SCHEDULED_STR, @@ -2799,6 +2796,10 @@ static int service_start(Unit *u) { s->main_pid_alien = false; s->forbid_restart = false; + /* This is not an automatic restart? Flush the restart counter then. */ + if (s->state != SERVICE_AUTO_RESTART_QUEUED) + s->n_restarts = 0; + s->status_text = mfree(s->status_text); s->status_errno = 0; s->status_bus_error = mfree(s->status_bus_error); @@ -2814,12 +2815,6 @@ static int service_start(Unit *u) { exec_command_reset_status_list_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX); exec_status_reset(&s->main_exec_status); - /* This is not an automatic restart? Flush the restart counter then */ - if (s->flush_n_restarts) { - s->n_restarts = 0; - s->flush_n_restarts = false; - } - CGroupRuntime *crt = unit_get_cgroup_runtime(u); if (crt) crt->reset_accounting = true; @@ -3005,7 +3000,6 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) { (void) serialize_bool(f, "bus-name-good", s->bus_name_good); (void) serialize_item_format(f, "n-restarts", "%u", s->n_restarts); - (void) serialize_bool(f, "flush-n-restarts", s->flush_n_restarts); (void) serialize_bool(f, "forbid-restart", s->forbid_restart); service_serialize_exec_command(u, f, s->control_command); @@ -3348,12 +3342,6 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value, if (r < 0) log_unit_debug_errno(u, r, "Failed to parse serialized restart counter '%s': %m", value); - } else if (streq(key, "flush-n-restarts")) { - r = parse_boolean(value); - if (r < 0) - log_unit_debug_errno(u, r, "Failed to parse serialized flush restart counter setting '%s': %m", value); - else - s->flush_n_restarts = r; } else if (streq(key, "forbid-restart")) { r = parse_boolean(value); if (r < 0) @@ -4875,7 +4863,6 @@ static void service_reset_failed(Unit *u) { s->reload_result = SERVICE_SUCCESS; s->clean_result = SERVICE_SUCCESS; s->n_restarts = 0; - s->flush_n_restarts = false; } static PidRef* service_main_pid(Unit *u, bool *ret_is_alien) { diff --git a/src/core/service.h b/src/core/service.h index 1d67d13fda4..8984be37b43 100644 --- a/src/core/service.h +++ b/src/core/service.h @@ -124,8 +124,9 @@ struct Service { /* If set we'll read the main daemon PID from this file */ char *pid_file; - usec_t restart_usec; + unsigned n_restarts; unsigned restart_steps; + usec_t restart_usec; usec_t restart_max_delay_usec; usec_t timeout_start_usec; usec_t timeout_stop_usec; @@ -143,8 +144,6 @@ struct Service { bool watchdog_override_enable; sd_event_source *watchdog_event_source; - ExecCommand* exec_command[_SERVICE_EXEC_COMMAND_MAX]; - ExecContext exec_context; KillContext kill_context; CGroupContext cgroup_context; @@ -154,14 +153,15 @@ struct Service { /* The exit status of the real main process */ ExecStatus main_exec_status; - /* The currently executed control process */ - ExecCommand *control_command; + ExecCommand *exec_command[_SERVICE_EXEC_COMMAND_MAX]; - /* The currently executed main process, which may be NULL if - * the main process got started via forking mode and not by - * us */ + /* The currently executed main process, which may be NULL if the main process got started via + * forking mode and not by us */ ExecCommand *main_command; + /* The currently executed control process */ + ExecCommand *control_command; + /* The ID of the control command currently being executed */ ServiceExecCommand control_command_id; @@ -225,9 +225,6 @@ struct Service { int stdout_fd; int stderr_fd; - unsigned n_restarts; - bool flush_n_restarts; - OOMPolicy oom_policy; LIST_HEAD(OpenFile, open_files);