[PATCH 11/16] Move debugging features into loader.c.

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

 



---
 loader/init.c   |   68 -------------------------------------------------------
 loader/loader.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 68 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index d4f9c0d..3138b87 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -83,66 +83,6 @@ static void fatal_error(int usePerror) {
 #endif
 }
 
-static char *setupMallocPerturb(char *value)
-{
-    FILE *f;
-    unsigned char x;
-    size_t rc;
-    char *ret = NULL;
-    
-    f = fopen("/dev/urandom", "r");
-    if (!f)
-        return NULL;
-
-    rc = fread(&x, 1, 1, f);
-    fclose(f);
-    if (rc < 1)
-        return NULL;
-
-    rc = asprintf(&ret, "MALLOC_PERTURB_=%hhu", x);
-    if (rc < 0)
-        return NULL;
-    return ret;
-}
-
-/* these functions return a newly allocated string that never gets freed;
- * their lifetime is essentially that of main(), and we'd have to track which
- * are allocated and which aren't, which is pretty pointless... */
-typedef char *(*setupEnvCallback)(char *entry);
-
-static void setupEnv(void)
-{
-    struct {
-        char *name;
-        setupEnvCallback cb;
-    } setupEnvCallbacks[] = {
-        { "MALLOC_PERTURB_", setupMallocPerturb },
-        { NULL, NULL }
-    };
-    int x;
-
-    /* neither array is very big, so this algorithm isn't so bad.  If env[]
-     * gets bigger for some reason, we should probably just alphebatize both
-     * (manually) and then only initialize y one time.
-     */
-    for (x = 0; setupEnvCallbacks[x].name != NULL; x++) {
-        int y;
-        int l = strlen(setupEnvCallbacks[x].name) + 1;
-        char cmpstr[l + 1];
-
-        strncpy(cmpstr, setupEnvCallbacks[x].name, l);
-        strcat(cmpstr, "=");
-
-        for (y = 0; env[y] != NULL; y++) {
-            if (!strncmp(env[y], cmpstr, l)) {
-                char *new = setupEnvCallbacks[x].cb(env[y] + l);
-                if (new)
-                    env[y] = new;
-            }
-        }
-    }
-}
-
 int main(int argc, char **argv) {
     pid_t installpid;
     int waitStatus;
@@ -171,14 +111,6 @@ int main(int argc, char **argv) {
 
     printf("anaconda installer init version %s starting\n", VERSION);
 
-    /* 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");
-    }
-
-
     if (!(installpid = fork())) {
         /* child */
         *argvp++ = "/sbin/loader";
diff --git a/loader/loader.c b/loader/loader.c
index 9e3ab24..4365e40 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1794,6 +1794,11 @@ int restart_anaconda(struct loaderData_s *loaderData) {
 }
 
 static int anaconda_trace_init(int isDevelMode) {
+    /* if anaconda dies suddenly we are doomed, so at least make a coredump */
+    struct rlimit corelimit = { RLIM_INFINITY,  RLIM_INFINITY};
+    if (setrlimit(RLIMIT_CORE, &corelimit)) {
+        perror("setrlimit failed - no coredumps will be available");
+    }
 
 #ifdef USE_MTRACE
     setenv("MALLOC_TRACE","/malloc",1);
@@ -1811,6 +1816,59 @@ static int anaconda_trace_init(int isDevelMode) {
     return 0;
 }
 
+static char *setupMallocPerturb(char *value)
+{
+    FILE *f;
+    unsigned char x;
+    size_t rc;
+    char *ret = NULL;
+
+    f = fopen("/dev/urandom", "r");
+    if (!f)
+        return NULL;
+
+    rc = fread(&x, 1, 1, f);
+    fclose(f);
+    if (rc < 1)
+        return NULL;
+
+    rc = asprintf(&ret, "MALLOC_PERTURB_=%hhu", x);
+    if (rc < 0)
+        return NULL;
+    return ret;
+}
+
+/* these functions return a newly allocated string that never gets freed;
+ * their lifetime is essentially that of main(), and we'd have to track which
+ * are allocated and which aren't, which is pretty pointless... */
+typedef char *(*setupEnvCallback)(char *entry);
+
+static void setupEnv(void)
+{
+    struct {
+        char *name;
+        setupEnvCallback cb;
+    } setupEnvCallbacks[] = {
+        { "MALLOC_PERTURB_", setupMallocPerturb },
+        { NULL, NULL }
+    };
+    int x;
+
+    /* neither array is very big, so this algorithm isn't so bad.  If env[]
+     * gets bigger for some reason, we should probably just alphebatize both
+     * (manually) and then only initialize y one time.
+     */
+    for (x = 0; setupEnvCallbacks[x].name != NULL; x++) {
+        char *value = getenv(setupEnvCallbacks[x].name);
+
+        if (value != NULL) {
+            char *new = setupEnvCallbacks[x].cb(value);
+            if (new)
+                setenv(setupEnvCallbacks[x].name, new, 1);
+        }
+    }
+}
+
 static void add_to_path_env(const char *env, const char *val)
 {
     char *oldenv, *newenv;
@@ -1917,6 +1975,7 @@ int main(int argc, char ** argv) {
 
     /* Very first thing, set up tracebacks and debug features. */
     rc = anaconda_trace_init(isDevelMode);
+    setupEnv();
 
     if (!access("/var/run/loader.run", R_OK)) {
         printf(_("loader has already been run.  Starting shell.\n"));
-- 
1.7.4.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