Fix bug causing scripted service shutdown scripts to be run twice.
authorDavin McCall <davmac@davmac.org>
Fri, 8 Jun 2018 20:04:58 +0000 (21:04 +0100)
committerDavin McCall <davmac@davmac.org>
Fri, 8 Jun 2018 20:04:58 +0000 (21:04 +0100)
All tests now passing.

src/includes/proc-service.h
src/proc-service.cc

index 76fef21df6ec46f3de7f3098b702a54cc41c3db9..bccce7a27264b39020a142c9d0f0cf5d0d6013c4 100644 (file)
@@ -267,6 +267,7 @@ class bgproc_service : public base_process_service
 class scripted_service : public base_process_service
 {
     virtual void handle_exit_status(bp_sys::exit_status exit_status) noexcept override;
+    virtual void exec_succeeded() noexcept override;
     virtual void exec_failed(int errcode) noexcept override;
     virtual void bring_down() noexcept override;
 
index d482fde7e3abaa182efb67fb40d5881cc4f4ae11..7651ec71366b98c94a7b050f529e433387203b21 100644 (file)
@@ -55,6 +55,12 @@ void process_service::exec_succeeded() noexcept
     }
 }
 
+void scripted_service::exec_succeeded() noexcept
+{
+       // For a scripted service, this means nothing other than that the start/stop
+       // script will now begin.
+}
+
 rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) noexcept
 {
     base_process_service *sr = service;
@@ -506,6 +512,11 @@ void bgproc_service::bring_down() noexcept
 
 void scripted_service::bring_down() noexcept
 {
+       if (pid != -1) {
+               // We're already running the stop script; nothing to do.
+               return;
+       }
+
     if (stop_command.length() == 0) {
         stopped();
     }