Browse Source

shutdown: don't close stdout before opening /dev/console

Don't close stdout before opening /dev/console, just in case we can't
open /dev/console. (This shouldn't really happen in practice, but is
possible eg if user unmounts /dev).
Davin McCall 1 year ago
parent
commit
60a3d9980d
1 changed files with 1 additions and 2 deletions
  1. 1 2
      src/shutdown.cc

+ 1 - 2
src/shutdown.cc

@@ -423,9 +423,8 @@ void do_system_shutdown(shutdown_type_t shutdown_type)
 #endif
     
     // Write to console rather than any terminal, since we lose the terminal it seems:
-    close(STDOUT_FILENO);
     int consfd = open("/dev/console", O_WRONLY);
-    if (consfd != STDOUT_FILENO) {
+    if (consfd != STDOUT_FILENO && consfd != -1) {
         dup2(consfd, STDOUT_FILENO);
     }