Correct exit status checks (status 0 returned by wait() doesn't have to mean
authorDavin McCall <davmac@davmac.org>
Tue, 21 Jun 2016 18:24:10 +0000 (19:24 +0100)
committerDavin McCall <davmac@davmac.org>
Tue, 21 Jun 2016 18:24:10 +0000 (19:24 +0100)
"exited cleanly with 0 exit status", though it probably does on most real
systems).

src/service.cc

index fef4c1374a66d270441406529cbc521cf27b35b4..2c11965863d3a3832376848cfb7d7eb5bf468cb3 100644 (file)
@@ -154,7 +154,7 @@ void ServiceRecord::handle_exit_status() noexcept
         // (BGPROCESS only)
         doing_recovery = false;
         bool need_stop = false;
-        if (exit_status != 0) {
+        if ((did_exit && WEXITSTATUS(exit_status) != 0) || was_signalled) {
             need_stop = true;
         }
         else {
@@ -179,7 +179,7 @@ void ServiceRecord::handle_exit_status() noexcept
     if (service_type == ServiceType::PROCESS || service_type == ServiceType::BGPROCESS) {
         if (service_state == ServiceState::STARTING) {
             // (only applies to BGPROCESS)
-            if (exit_status == 0) {
+            if (did_exit && WEXITSTATUS(exit_status) == 0) {
                 started();
             }
             else {
@@ -207,7 +207,7 @@ void ServiceRecord::handle_exit_status() noexcept
     }
     else {  // SCRIPTED
         if (service_state == ServiceState::STOPPING) {
-            if (exit_status == 0) {
+            if (did_exit && WEXITSTATUS(exit_status) == 0) {
                 stopped();
             }
             else {