[PATCH] Add better debugging capabilities to loader

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

 



- when development ('devel' argument) mode is requested, init enables
  core dumping and starts shell in the case of unexpected exit
---
 loader/init.c   |   54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 loader/loader.c |    7 -------
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index 175f1d7..820d3ef 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -44,6 +44,7 @@
 #include <sys/stat.h>
 #include <sys/swap.h>
 #include <sys/time.h>
+#include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/wait.h>
@@ -516,9 +517,11 @@ int main(int argc, char **argv) {
     int doShutdown =0;
     reboot_action shutdown_method = HALT;
     int isSerial = 0;
+    int isDebugMode = 0;
     char * console = NULL;
     int doKill = 1;
     char * argvc[15];
+    char buf[1024];
     char ** argvp = argvc;
     char twelve = 12;
     struct serial_struct si;
@@ -563,6 +566,25 @@ int main(int argc, char **argv) {
         fatal_error(1);
     printf("done\n");
 
+    /* unless the user specifies that they want utf8 */
+    int fdn;
+    if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
+        int len = read(fdn, buf, sizeof(buf) - 1);
+        close(fdn);
+        if (len > 0 && strstr(buf, "devel")) {
+            printf("Enabling development mode - cores will be dumped\n");
+            isDebugMode = 1;
+        }
+    }
+
+    /* these args are only for testing from commandline */
+    for (i = 1; i < argc; i++) {
+        if (!strcmp (argv[i], "serial")) {
+            isSerial = 1;
+            break;
+        }
+    }
+
     printf("creating /dev filesystem... "); 
     fflush(stdout);
     if (mount("/dev", "/dev", "tmpfs", 0, NULL))
@@ -618,14 +640,17 @@ int main(int argc, char **argv) {
         fatal_error(1);
     printf("done\n");
 
-    /* these args are only for testing from commandline */
-    for (i = 1; i < argc; i++) {
-        if (!strcmp (argv[i], "serial")) {
-            isSerial = 1;
-            break;
+    if (isDebugMode) {
+        /* if anaconda dies suddenly we are doomed, so at least make a coredump */
+        struct rlimit corelimit = { RLIM_INFINITY,  RLIM_INFINITY};
+        int ret = setrlimit(RLIMIT_CORE, &corelimit);
+        if (ret) {
+            perror("setrlimit failed - no coredumps will be available");
         }
     }
 
+
+
     doKill = getKillPolicy();
 
 #if !defined(__s390__) && !defined(__s390x__)
@@ -872,6 +897,25 @@ int main(int argc, char **argv) {
             printf("-- received signal %d", WTERMSIG(waitStatus));
         }
         printf("\n");
+
+        /* If debug mode was requested, spawn shell */
+        if(isDebugMode) {
+            pid_t shellpid;
+
+            printf("Development mode requested spawning shell...\n");
+
+            if ((shellpid = fork()) == 0) {
+                execl("/sbin/bash", "/sbin/bash", NULL);
+            }
+            else if (shellpid > 0) {
+                waitpid(shellpid, NULL, 0);
+            }
+            else {
+                perror("Execution of debug shell failed.");
+            }
+
+        }
+
     } else {
         shutdown_method = REBOOT;
     }
diff --git a/loader/loader.c b/loader/loader.c
index 46f6f5e..8287311 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -2385,13 +2385,6 @@ int main(int argc, char ** argv) {
     stopNewt();
     closeLog();
 
-    /* if anaconda dies suddenly we are doomed, so at least make a coredump */
-    struct rlimit corelimit = { RLIM_INFINITY,  RLIM_INFINITY};
-    ret = setrlimit(RLIMIT_CORE, &corelimit);
-    if (ret) {
-        perror("setrlimit failed");
-    }
-
     if (FL_RESCUE(flags)) {
         fmt = _("Running anaconda %s, the %s rescue mode - please wait.\n");
     } else {
-- 
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