From: Davin McCall Date: Sat, 13 Jan 2018 18:52:22 +0000 (+0000) Subject: Move base_process_service timer expiry handling out of friend class. X-Git-Tag: v0.08~41 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6b07a54af57cb53dc67e9bc20a052e93d1bbe8bf;p=oweals%2Fdinit.git Move base_process_service timer expiry handling out of friend class. One less friend class is a good thing. The timer now just calls a single public 'timer_expiry' function. The latter function can also be used in tests. --- diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index ac5664b..1645b05 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -314,3 +314,25 @@ void base_process_service::kill_pg(int signo) noexcept } kill(-pgid, signo); } + +void base_process_service::timer_expired() noexcept +{ + stop_timer_armed = false; + + // Timer expires if: + // We are stopping, including after having startup cancelled (stop timeout, state is STOPPING); We are + // starting (start timeout, state is STARTING); We are waiting for restart timer before restarting, + // including smooth recovery (restart timeout, state is STARTING or STARTED). + if (get_state() == service_state_t::STOPPING) { + kill_with_fire(); + } + else if (pid != -1) { + // Starting, start timed out. + stop_dependents(); + interrupt_start(); + } + else { + // STARTING / STARTED, and we have a pid: must be restarting (smooth recovery if STARTED) + do_restart(); + } +} diff --git a/src/includes/proc-service.h b/src/includes/proc-service.h index a1935c7..0952fff 100644 --- a/src/includes/proc-service.h +++ b/src/includes/proc-service.h @@ -26,7 +26,6 @@ class base_process_service : public service_record { friend class service_child_watcher; friend class exec_status_pipe_watcher; - friend class process_restart_timer; friend class base_process_service_test; private: @@ -151,6 +150,9 @@ class base_process_service : public service_record { start_is_interruptible = value; } + + // The restart/stop timer expired. + void timer_expired() noexcept; }; class process_service : public base_process_service diff --git a/src/proc-service.cc b/src/proc-service.cc index 03ab278..168ca52 100644 --- a/src/proc-service.cc +++ b/src/proc-service.cc @@ -498,24 +498,7 @@ void scripted_service::bring_down() noexcept dasynq::rearm process_restart_timer::timer_expiry(eventloop_t &, int expiry_count) { - service->stop_timer_armed = false; - - // Timer expires if: - // We are stopping, including after having startup cancelled (stop timeout, state is STOPPING); We are - // starting (start timeout, state is STARTING); We are waiting for restart timer before restarting, - // including smooth recovery (restart timeout, state is STARTING or STARTED). - if (service->get_state() == service_state_t::STOPPING) { - service->kill_with_fire(); - } - else if (service->pid != -1) { - // Starting, start timed out. - service->stop_dependents(); - service->interrupt_start(); - } - else { - // STARTING / STARTED, and we have a pid: must be restarting (smooth recovery if STARTED) - service->do_restart(); - } + service->timer_expired(); // Leave the timer disabled, or, if it has been reset by any processing above, leave it armed: return dasynq::rearm::NOOP; diff --git a/src/tests/test-baseproc.cc b/src/tests/test-baseproc.cc index 20a51f6..c1a4103 100644 --- a/src/tests/test-baseproc.cc +++ b/src/tests/test-baseproc.cc @@ -211,3 +211,25 @@ bool base_process_service::interrupt_start() noexcept return false; } } + +void base_process_service::timer_expired() noexcept +{ + stop_timer_armed = false; + + // Timer expires if: + // We are stopping, including after having startup cancelled (stop timeout, state is STOPPING); We are + // starting (start timeout, state is STARTING); We are waiting for restart timer before restarting, + // including smooth recovery (restart timeout, state is STARTING or STARTED). + if (get_state() == service_state_t::STOPPING) { + kill_with_fire(); + } + else if (pid != -1) { + // Starting, start timed out. + stop_dependents(); + interrupt_start(); + } + else { + // STARTING / STARTED, and we have a pid: must be restarting (smooth recovery if STARTED) + do_restart(); + } +}