From: Davin McCall Date: Fri, 19 Jan 2018 23:41:54 +0000 (+0000) Subject: Refactoring / clean up. X-Git-Tag: v0.08~15 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4fd37bfb68b3af7803ae6b4cdb0031ff674da41d;p=oweals%2Fdinit.git Refactoring / clean up. --- diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index e66e1a5..14933a5 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -157,36 +157,6 @@ bool base_process_service::start_ps_process(const std::vector &cmd return false; } -void base_process_service::bring_down() noexcept -{ - if (pid != -1) { - // The process is still kicking on - must actually kill it. We signal the process - // group (-pid) rather than just the process as there's less risk then of creating - // an orphaned process group: - if (! onstart_flags.no_sigterm) { - kill_pg(SIGTERM); - } - if (term_signal != -1) { - kill_pg(term_signal); - } - - // In most cases, the rest is done in handle_exit_status. - // If we are a BGPROCESS and the process is not our immediate child, however, that - // won't work - check for this now: - if (get_type() == service_type_t::BGPROCESS && ! tracking_child) { - stopped(); - } - else if (stop_timeout != time_val(0,0)) { - restart_timer.arm_timer_rel(event_loop, stop_timeout); - stop_timer_armed = true; - } - } - else { - // The process is already dead. - stopped(); - } -} - base_process_service::base_process_service(service_set *sset, string name, service_type_t service_type_p, string &&command, std::list> &command_offsets, diff --git a/src/includes/proc-service.h b/src/includes/proc-service.h index 2705811..8074e8a 100644 --- a/src/includes/proc-service.h +++ b/src/includes/proc-service.h @@ -86,8 +86,6 @@ class base_process_service : public service_record // Start the process, return true on success virtual bool bring_up() noexcept override; - virtual void bring_down() noexcept override; - // Called when the process exits. The exit_status is the status value yielded by // the "wait" system call. virtual void handle_exit_status(int exit_status) noexcept = 0; @@ -203,6 +201,7 @@ class bgproc_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 bring_down() noexcept override; enum class pid_result_t { OK, diff --git a/src/proc-service.cc b/src/proc-service.cc index 168ca52..58768ea 100644 --- a/src/proc-service.cc +++ b/src/proc-service.cc @@ -442,7 +442,6 @@ bgproc_service::read_pid_file(int *exit_status) noexcept void process_service::bring_down() noexcept { - waiting_for_deps = false; if (waiting_for_execstat) { // The process is still starting. This should be uncommon, but can occur during // smooth recovery. We can't do much now; we have to wait until we get the @@ -460,10 +459,37 @@ void process_service::bring_down() noexcept kill_pg(term_signal); } + // If there's a stop timeout, arm the timer now: + if (stop_timeout != time_val(0,0)) { + restart_timer.arm_timer_rel(event_loop, stop_timeout); + stop_timer_armed = true; + } + + // The rest is done in handle_exit_status. + } + else { + // The process is already dead. + stopped(); + } +} + +void bgproc_service::bring_down() noexcept +{ + if (pid != -1) { + // The process is still kicking on - must actually kill it. We signal the process + // group (-pid) rather than just the process as there's less risk then of creating + // an orphaned process group: + if (! onstart_flags.no_sigterm) { + kill_pg(SIGTERM); + } + if (term_signal != -1) { + kill_pg(term_signal); + } + // In most cases, the rest is done in handle_exit_status. // If we are a BGPROCESS and the process is not our immediate child, however, that // won't work - check for this now: - if (get_type() == service_type_t::BGPROCESS && ! tracking_child) { + if (! tracking_child) { stopped(); } else if (stop_timeout != time_val(0,0)) { @@ -479,7 +505,6 @@ void process_service::bring_down() noexcept void scripted_service::bring_down() noexcept { - waiting_for_deps = false; if (stop_command.length() == 0) { stopped(); }