[PATCH 1/2] 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 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index 1a38df3..6d6450e 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -45,6 +45,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>
@@ -441,13 +442,16 @@ int main(int argc, char **argv) {
     int doShutdown =0;
     reboot_action shutdown_method = HALT;
     int isSerial = 0;
+    int isDevelMode = 0;
     char * console = NULL;
     int doKill = 1;
     char * argvc[15];
+    char buf[1024];
     char ** argvp = argvc;
     char twelve = 12;
     struct serial_struct si;
     int i, disable_keys;
+    int ret;
 
     if (!strncmp(basename(argv[0]), "poweroff", 8)) {
         printf("Running poweroff...\n");
@@ -487,6 +491,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");
+            isDevelMode = 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... "); 
     if (mount("/dev", "/dev", "tmpfs", 0, NULL))
         fatal_error(1);
@@ -535,12 +558,11 @@ 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 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 - no coredumps will be available");
     }
 
     doKill = getKillPolicy();
@@ -658,7 +680,6 @@ int main(int argc, char **argv) {
         tcsetattr(0, TCSANOW, &ts);
     }
 
-    int ret;
     ret = sethostname("localhost.localdomain", 21);
     /* the default domainname (as of 2.0.35) is "(none)", which confuses 
      glibc */
@@ -785,6 +806,25 @@ int main(int argc, char **argv) {
             printf("-- received signal %d", WTERMSIG(waitStatus));
         }
         printf("\n");
+
+        /* If debug mode was requested, spawn shell */
+        if(isDevelMode) {
+            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;
     }
-- 
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