Avoid releasing console twice on failure to read pid file.
authorDavin McCall <davmac@davmac.org>
Fri, 26 May 2017 17:58:54 +0000 (18:58 +0100)
committerDavin McCall <davmac@davmac.org>
Mon, 29 May 2017 13:33:41 +0000 (14:33 +0100)
src/service.cc

index 25b62948cf51b6cc4c70f54a5a61c64ec0a6d6e2..c5a60f375c1c9a2c5e349772b39ee671fda557ae 100644 (file)
@@ -695,18 +695,18 @@ bool ServiceRecord::read_pid_file() noexcept
 
 void ServiceRecord::started() noexcept
 {
-    if (onstart_flags.runs_on_console && (service_type == ServiceType::SCRIPTED || service_type == ServiceType::BGPROCESS)) {
-        tcsetpgrp(0, getpgrp());
-        releaseConsole();
-    }
-    
     if (service_type == ServiceType::BGPROCESS && pid_file.length() != 0) {
         if (! read_pid_file()) {
             failed_to_start();
             return;
         }
     }
-    
+
+    if (onstart_flags.runs_on_console && (service_type == ServiceType::SCRIPTED || service_type == ServiceType::BGPROCESS)) {
+        tcsetpgrp(0, getpgrp());
+        releaseConsole();
+    }
+
     logServiceStarted(service_name);
     service_state = ServiceState::STARTED;
     notifyListeners(ServiceEvent::STARTED);