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 > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 07-14-2010, 02:36 PM
Martin Sivak
 
Default Improve parsing and pass the devel flag to loader through the command line

This gets rid of ugly checking for this in /proc/cmdline in loader and init checks if devel is actually a single word to avoid conflicts
---
loader/init.c | 36 +++++++++++++++++++++++++++++++++---
loader/loader.c | 28 +++++++++++++---------------
2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index d824390..cdba95e 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -494,11 +494,37 @@ int main(int argc, char **argv) {
/* check for development mode early */
int fdn;
if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
+
+ /* get cmdline info */
int len = read(fdn, buf, sizeof(buf) - 1);
+ char *develstart;
close(fdn);
- if (len > 0 && strstr(buf, "devel")) {
- printf("Enabling development mode - cores will be dumped
");
- isDevelMode = 1;
+
+ /* check the arguments */
+ if (len > 0) {
+ develstart = buf;
+ while (develstart && (*develstart) != '') {
+
+ /* strip spaces */
+ while(*develstart == ' ') develstart++;
+ if(*develstart == '') break;
+
+ /* not the word we are looking for */
+ if (strncmp(develstart, "devel", 5)) {
+ develstart = strchr(develstart, ' ');
+ continue;
+ }
+
+ /* is it isolated? */
+ if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '')) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode++;
+ break;
+ }
+
+ /* Find next argument */
+ develstart = strchr(develstart, ' ');
+ }
}
}

@@ -758,6 +784,10 @@ int main(int argc, char **argv) {
*argvp++ = console;
}

+ if (isDevelMode) {
+ *argvp++ = "--devel";
+ }
+
*argvp++ = NULL;

printf("running %s
", argvc[0]);
diff --git a/loader/loader.c b/loader/loader.c
index 0856332..32f84fc 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1790,9 +1790,7 @@ int restart_anaconda(struct loaderData_s *loaderData) {
return 1;
}

-static int anaconda_trace_init(void) {
- int isDevelMode = 0;
- gchar *buf;
+static int anaconda_trace_init(int isDevelMode) {

#ifdef USE_MTRACE
setenv("MALLOC_TRACE","/malloc",1);
@@ -1803,14 +1801,6 @@ static int anaconda_trace_init(void) {
* is well before we might take a SEGV, so they'll go to tty8 */
initializeTtys();

- /* check for development mode early */
- if (g_file_get_contents("/proc/cmdline", &buf, NULL, NULL) == TRUE) {
- if (strstr(buf, "devel")) {
- isDevelMode = 1;
- }
- g_free(buf);
- }
-
/* set up signal handler unless we want it to crash in devel mode */
if(!isDevelMode)
setupBacktrace();
@@ -1885,7 +1875,8 @@ static void loadScsiDhModules(void)
}

int main(int argc, char ** argv) {
- int rc, ret, pid, status;
+ int i, rc, ret, pid, status;
+ int isDevelMode = 0;

struct stat sb;
struct serial_struct si;
@@ -1916,6 +1907,7 @@ int main(int argc, char ** argv) {
GOptionEntry optionTable[] = {
{ "cmdline", 0, 0, G_OPTION_ARG_STRING, &cmdLine, NULL, NULL },
{ "ksfile", 0, 0, G_OPTION_ARG_STRING, &ksFile, NULL, NULL },
+ { "devel", 0, 0, G_OPTION_ARG_NONE, &isDevelMode, NULL, NULL },
{ "mediacheck", 0, 0, G_OPTION_ARG_NONE, &mediacheck, NULL, NULL },
{ "virtpconsole", 0, 0, G_OPTION_ARG_STRING, &virtpcon, NULL, NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
@@ -1923,6 +1915,14 @@ int main(int argc, char ** argv) {
{ NULL },
};

+ /* get possible devel mode flag very early */
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--devel")) {
+ isDevelMode++;
+ break;
+ }
+ }
+
/* get init PID if we have it */
if ((f = fopen("/var/run/init.pid", "r")) != NULL) {
char linebuf[256];
@@ -1946,7 +1946,7 @@ int main(int argc, char ** argv) {
setenv ("LC_COLLATE", "C", 1);

/* Very first thing, set up tracebacks and debug features. */
- rc = anaconda_trace_init();
+ rc = anaconda_trace_init(isDevelMode);

/* now we parse command line options */
g_option_context_set_help_enabled(optCon, FALSE);
@@ -2176,8 +2176,6 @@ int main(int argc, char ** argv) {

/* Disable all network interfaces in NetworkManager by default */
#if !defined(__s390__) && !defined(__s390x__)
- int i;
-
if ((i = writeDisabledNetInfo()) != 0) {
logMessage(ERROR, "writeDisabledNetInfo failure: %d", i);
}
--
1.6.6.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 04:39 PM.

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