[PATCH 1/2] Improve reboot modes in init.c and shutdown.c. (#564297).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ales Kozumplik <akozumpl@xxxxxxxxxx>

Stop the kernel correctly on HALT (so that we dont see 'kernel panic, they
killed init' on i386 and on s390 one gets easy access to manual IPL).

Introduce a new reboot method that does allow us to see the backtrace and
doesn't scroll the screen up with useless unmount info.
---
 loader/init.c     |    8 +++---
 loader/init.h     |    5 +++-
 loader/shutdown.c |   63 +++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index 19fc31d..d8f5eb5 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -513,8 +513,8 @@ int main(int argc, char **argv) {
     pid_t installpid, childpid;
     int waitStatus;
     int fd = -1;
-    int doReboot = 0;
     int doShutdown =0;
+    reboot_action shutdown_method = HALT;
     int isSerial = 0;
     char * console = NULL;
     int doKill = 1;
@@ -851,6 +851,7 @@ int main(int argc, char **argv) {
 
     if (!WIFEXITED(waitStatus) ||
         (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus))) {
+        shutdown_method = DELAYED_REBOOT;
         printf("install exited abnormally [%d/%d] ", WIFEXITED(waitStatus),
                                                      WEXITSTATUS(waitStatus));
         if (WIFSIGNALED(waitStatus)) {
@@ -858,11 +859,10 @@ int main(int argc, char **argv) {
         }
         printf("\n");
     } else {
-        doReboot = 1;
+        shutdown_method = REBOOT;
     }
 
-    expected_exit = 1;
-    shutDown(doKill, doReboot?REBOOT:HALT);
+    shutDown(doKill, shutdown_method);
 
     return 0;
 }
diff --git a/loader/init.h b/loader/init.h
index 733bc8e..e1e5b70 100644
--- a/loader/init.h
+++ b/loader/init.h
@@ -22,7 +22,10 @@
 typedef enum {
 	REBOOT,
 	POWEROFF,
-	HALT
+	HALT,
+        /* gives user a chance to read the trace before scrolling the text out
+           with disk unmounting and termination info */
+        DELAYED_REBOOT
 } reboot_action;
 
 #endif /* INIT_H */
diff --git a/loader/shutdown.c b/loader/shutdown.c
index 774e11a..3b481f2 100644
--- a/loader/shutdown.c
+++ b/loader/shutdown.c
@@ -62,35 +62,56 @@ static void performUnmounts(void) {
 }
 
 static void performReboot(reboot_action rebootAction) {
-	if (rebootAction == POWEROFF) {
+    switch (rebootAction) {
+    case POWEROFF:
         printf("powering off system\n");
-		sleep(2);
+        sleep(2);
         reboot(RB_POWER_OFF);
-	} else if (rebootAction == REBOOT) {
-		printf("rebooting system\n");
-		sleep(2);
-
+        break;
+    case REBOOT:
+        printf("rebooting system\n");
+        sleep(2);
 #if USE_MINILIBC
-		reboot(0xfee1dead, 672274793, 0x1234567);
+        reboot(0xfee1dead, 672274793, 0x1234567);
 #else
-		reboot(RB_AUTOBOOT);
+        reboot(RB_AUTOBOOT);
 #endif
-	}
+        break;
+    case HALT:
+        printf("halting system\n");
+        reboot(RB_HALT_SYSTEM);
+        break;
+    default:
+        break;
+    }
 }
 
-void shutDown(int doKill, reboot_action rebootAction) {
-	if (doKill) {
-		performUnmounts();
-		performTerminations();
-	}
-
-	if ((rebootAction == POWEROFF || rebootAction == REBOOT) && doKill) {
-		performReboot(rebootAction);
-	}
+static void performDelayedReboot()
+{
+    printf("The system will be rebooted when you press Ctrl-C or Ctrl-Alt-Delete.\n");
+    while (1) {
+        sleep(1);
+    }
+}
 
-	printf("you may safely reboot your system\n");
-	exit(0);
-	return;
+void shutDown(int doKill, reboot_action rebootAction)
+{
+    static int reentered = 0;
+    
+    if (reentered) {
+        performUnmounts();
+        performTerminations();
+        performReboot(rebootAction);
+    }
+    reentered = 1;
+    if (rebootAction != DELAYED_REBOOT && doKill) {
+        performUnmounts();
+        performTerminations();
+        performReboot(rebootAction);
+    } else {
+        performDelayedReboot();
+    }
+    exit(0);
 }
 
 #ifdef AS_SHUTDOWN
-- 
1.6.6.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux