FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian Laptop

 
 
LinkBack Thread Tools
 
Old 04-06-2011, 08:10 PM
Chris Lumens
 
Default Move debugging features into loader.c.

---
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
", 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.
"));
--
1.7.4.1

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

Thread Tools




All times are GMT. The time now is 08:44 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org