From: Davin McCall Date: Thu, 11 Jan 2018 19:09:25 +0000 (+0000) Subject: Refactoring: split out exec_succeeded function. X-Git-Tag: v0.08~55 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2b8bcc97ae64390502a0a5246a06a6b0fb0df13a;p=oweals%2Fdinit.git Refactoring: split out exec_succeeded function. The status pipe watcher (exec_status_pipe_watcher) had some service-record-type specific code. Split it out as a virtual function. --- diff --git a/src/proc-service.cc b/src/proc-service.cc index c0efb52..9e64eec 100644 --- a/src/proc-service.cc +++ b/src/proc-service.cc @@ -35,6 +35,24 @@ std::vector separate_args(std::string &s, std::listexec_failed(exec_status); } else { - // exec() succeeded. - if (sr->get_type() == service_type_t::PROCESS) { - // This could be a smooth recovery (state already STARTED). Even more, the process - // might be stopped (and killed via a signal) during smooth recovery. We don't to - // process startup again in either case, so we check for state STARTING: - if (sr->get_state() == service_state_t::STARTING) { - sr->started(); - } - else if (sr->get_state() == service_state_t::STOPPING) { - // stopping, but smooth recovery was in process. That's now over so we can - // commence normal stop. Note that if pid == -1 the process already stopped(!), - // that's handled below. - if (sr->pid != -1 && sr->stop_check_dependents()) { - sr->bring_down(); - } - } - } + sr->exec_succeeded(); if (sr->pid == -1) { - // Somehow the process managed to complete before we even saw the status. + // Somehow the process managed to complete before we even saw the exec() status. sr->handle_exit_status(sr->exit_status); } } diff --git a/src/proc-service.h b/src/proc-service.h index c23b997..d32938f 100644 --- a/src/proc-service.h +++ b/src/proc-service.h @@ -88,6 +88,9 @@ class base_process_service : public service_record // Called if an exec fails. virtual void exec_failed(int errcode) noexcept = 0; + // Called if exec succeeds. + virtual void exec_succeeded() noexcept { }; + virtual bool can_interrupt_start() noexcept override { return waiting_restart_timer || start_is_interruptible || service_record::can_interrupt_start(); @@ -153,6 +156,7 @@ class process_service : public base_process_service { virtual void handle_exit_status(int exit_status) noexcept override; virtual void exec_failed(int errcode) noexcept override; + virtual void exec_succeeded() noexcept override; virtual void bring_down() noexcept override; public: