chiark / gitweb /
shutdown: rework messages during shutdown
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 26 Jun 2014 05:41:04 +0000 (01:41 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 26 Jun 2014 05:41:04 +0000 (01:41 -0400)
When running in 'quiet' mode, the only message printed from shutdown
binary would be 'Cannot finalize remaining file systems and devices,
giving up.', the only log line at error level before switch back to
initramfs. This is misleading, because in initramfs everything will
be cleaned up properly.

Avoid printing anything at error level before the attempt to switch
back to initramfs. Rework the messages to contain a bit more
information what is still remaining, to help people diagnose shutdown
issues.

src/core/shutdown.c

index 7ef671ad0f56f854225d6420b2d5ca39decbe95f..fde3ce9c27b92239dd93fbcacff88a311dd79770 100644 (file)
@@ -220,7 +220,7 @@ static int pivot_to_new_root(void) {
 }
 
 int main(int argc, char *argv[]) {
-        bool need_umount = true, need_swapoff = true, need_loop_detach = true, need_dm_detach = true;
+        bool need_umount, need_swapoff, need_loop_detach, need_dm_detach;
         bool in_container, use_watchdog = false;
         _cleanup_free_ char *cgroup = NULL;
         char *arguments[3];
@@ -246,8 +246,6 @@ int main(int argc, char *argv[]) {
                 goto error;
         }
 
-        in_container = detect_container(NULL) > 0;
-
         if (streq(arg_verb, "reboot"))
                 cmd = RB_AUTOBOOT;
         else if (streq(arg_verb, "poweroff"))
@@ -275,11 +273,12 @@ int main(int argc, char *argv[]) {
         log_info("Sending SIGKILL to remaining processes...");
         broadcast_signal(SIGKILL, true, false);
 
-        if (in_container) {
-                need_swapoff = false;
-                need_dm_detach = false;
-                need_loop_detach = false;
-        }
+        in_container = detect_container(NULL) > 0;
+
+        need_umount = true;
+        need_swapoff = !in_container;
+        need_loop_detach = !in_container;
+        need_dm_detach = !in_container;
 
         /* Unmount all mountpoints, swaps, and loopback devices */
         for (retries = 0; retries < FINALIZE_ATTEMPTS; retries++) {
@@ -347,23 +346,31 @@ int main(int argc, char *argv[]) {
                         if (retries > 0)
                                 log_info("All filesystems, swaps, loop devices, DM devices detached.");
                         /* Yay, done */
-                        break;
+                        goto initrd_jump;
                 }
 
                 /* If in this iteration we didn't manage to
                  * unmount/deactivate anything, we simply give up */
                 if (!changed) {
-                        log_error("Cannot finalize remaining file systems and devices, giving up.");
-                        break;
+                        log_info("Cannot finalize remaining%s%s%s%s continuing.",
+                                 need_umount ? " file systems," : "",
+                                 need_swapoff ? " swap devices," : "",
+                                 need_loop_detach ? " loop devices," : "",
+                                 need_dm_detach ? " DM devices," : "");
+                        goto initrd_jump;
                 }
 
-                log_debug("Couldn't finalize remaining file systems and devices after %u retries, trying again.", retries+1);
+                log_debug("After %u retries, couldn't finalize remaining %s%s%s%s trying again.",
+                          retries + 1,
+                          need_umount ? " file systems," : "",
+                          need_swapoff ? " swap devices," : "",
+                          need_loop_detach ? " loop devices," : "",
+                          need_dm_detach ? " DM devices," : "");
         }
 
-        if (retries >= FINALIZE_ATTEMPTS)
-                log_error("Too many iterations, giving up.");
-        else
-                log_info("Storage is finalized.");
+        log_error("Too many iterations, giving up.");
+
+ initrd_jump:
 
         arguments[0] = NULL;
         arguments[1] = arg_verb;
@@ -384,6 +391,13 @@ int main(int argc, char *argv[]) {
                 }
         }
 
+        if (need_umount || need_swapoff || need_loop_detach || need_dm_detach)
+                log_error("Failed to finalize %s%s%s%s ignoring",
+                          need_umount ? " file systems," : "",
+                          need_swapoff ? " swap devices," : "",
+                          need_loop_detach ? " loop devices," : "",
+                          need_dm_detach ? " DM devices," : "");
+
         /* The kernel will automaticall flush ATA disks and suchlike
          * on reboot(), but the file systems need to be synce'd
          * explicitly in advance. So let's do this here, but not