chiark / gitweb /
nspawn: simplify exit condition check
[elogind.git] / src / nspawn / nspawn.c
index be0e6b5386a814772ac000f0ba35ee0c93fa2793..a00a220966ae477c6caaf9cae2ffd2bd680083e7 100644 (file)
@@ -2666,8 +2666,10 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
         siginfo_t status;
 
         r = wait_for_terminate(pid, &status);
-        if (r < 0)
+        if (r < 0) {
+                log_warning("Failed to wait for container: %s", strerror(-r));
                 return r;
+        }
 
         switch (status.si_code) {
         case CLD_EXITED:
@@ -3307,14 +3309,15 @@ check_container_status:
                 r = wait_for_container(pid, &container_status);
                 pid = 0;
 
-                if (r != 0) {
-                        /* If r < 0, explicitly set to EXIT_FAILURE,
-                         * otherwise return the exit code of the
-                         * containered process. */
-                        if (r < 0)
-                                r = EXIT_FAILURE;
+                if (r < 0) {
+                        /* We failed to wait for the container, or the
+                         * container exited abnormally */
+                        r = EXIT_FAILURE;
                         break;
-                } else if (container_status == CONTAINER_TERMINATED)
+                } else if (r > 0 || container_status == CONTAINER_TERMINATED)
+                        /* The container exited with a non-zero
+                         * status, or with zero status and no reboot
+                         * was requested. */
                         break;
 
                 /* CONTAINER_REBOOTED, loop again */