Skip to contentSkip to conversation

fw_env.c: use default env values if config file cannot be opened

PATCH New Frans Meulenbroeks 2 participants 4 messages Dec 28, 2011 – Feb 12, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fw_env.c: use default env values if config file cannot be opened

If the config file cannot be opened currently one gets an error even though the build in names/sizes are probably ok. By setting the default values first and only exit if there is a read error and not when the config file can be opened the program will try the default settings.

In order to detect that the config file open fails get_config returns -2 to signal this; all other errors return -1

---
 tools/env/fw_env.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
tools/env/fw_env.c +9 -9
index 996682e..992835f 100644
@@ -1225,14 +1225,6 @@ static int parse_config ()
 {
 	struct stat st;
 
-#if defined(CONFIG_FILE)
-	/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
-	if (get_config (CONFIG_FILE)) {
-		fprintf (stderr,
-			"Cannot parse config file: %s\n", strerror (errno));
-		return -1;
-	}
-#else
 	strcpy (DEVNAME (0), DEVICE1_NAME);
 	DEVOFFSET (0) = DEVICE1_OFFSET;
 	ENVSIZE (0) = ENV1_SIZE;
@@ -1261,6 +1253,14 @@ static int parse_config ()
 #endif
 	HaveRedundEnv = 1;
 #endif
+
+#if defined(CONFIG_FILE)
+	/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
+	if (get_config (CONFIG_FILE) == -1) {
+		fprintf (stderr,
+			"Cannot parse config file: %s\n", strerror (errno));
+		return -1;
+	}
 #endif
 	if (stat (DEVNAME (0), &st)) {
 		fprintf (stderr,
@@ -1288,7 +1288,7 @@ static int get_config (char *fname)
 
 	fp = fopen (fname, "r");
 	if (fp == NULL)
-		return -1;
+		return -2;
 
 	while (i < 2 && fgets (dump, sizeof (dump), fp)) {
 		/* Skip incomplete conversions and comment strings */
Signature · 1 line
1.7.8.1
#1 lore raw

PATCH 1/1 fw_env.c: use default env values if config file cannot be opened

Dear Frans Meulenbroeks,

Quoted 5 lines · In message <[email protected]> you…

If the config file cannot be opened currently one gets an error even though the build in names/sizes are probably ok. By setting the default values first and only exit if there is a read error and not when the config file can be opened the program will try the default settings.

I have to admit that I don't like this change of behaviour. When configured for use with a config file, all errors should be treated the same.

But that's just my $ 0.02.

Are there any other opinions / votes how to proceed here?

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Artificial Intelligence is no match for natural stupidity.
#2 lore raw

PATCH 1/1 fw_env.c: use default env values if config file cannot be opened

2012/1/5 Wolfgang Denk <[email protected]>

Quoted 17 lines

Dear Frans Meulenbroeks,

In message <[email protected]>

Quoted 5 lines · you

If the config file cannot be opened currently one gets an error even though the build in names/sizes are probably ok. By setting the default values first and only exit if there is a read error and not when the config file can be opened the program will try the default settings.

I have to admit that I don't like this change of behaviour. When configured for use with a config file, all errors should be treated the same.

But that's just my $ 0.02.

Quoted 8 lines

Are there any other opinions / votes how to proceed here?

Best regards,

Wolfgang Denk

As you mentioned in another reply the common practice nowadays seems to be

to use a conf file.
This has the disadvantage that the conf file can get lost or misplaced. For embedded systems I would prefer compiled-in values (or maybe an autosensing version that just seeks into /dev/mtd0 or so to find the actual location of the environment, if the sector size is known it would not be too hard.

BTW: it could also be argued that the specification of the config file should be in the board config, not in fw_env.h.

Frans

#3 lore raw

PATCH 1/1 fw_env.c: use default env values if config file cannot be opened

Dear Frans,

Quoted 4 lines · In message <CACW_hTY4oqT8bBGTkTopiX=rNpCmG50rNXWY0AfydAX3wZj5Rg@mail.gmail.com>…
Quoted 2 lines

As you mentioned in another reply the common practice nowadays seems to be

to use a conf file.
This has the disadvantage that the conf file can get lost or misplaced.

True. And this is an error situation, for wich a proper error message should be issued, and execution terminated.

Paperingover such a bug is IMHO a very bad idea.

Quoted 2 lines

BTW: it could also be argued that the specification of the config file should be in the board config, not in fw_env.h.

Yes, that could be argued. But this is unrelated tot his patch.

I still tend to reject it.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
That was the thing about deserts. They had their  own  gravity.  They
sucked you into the centre.           - Terry Pratchett, _Small Gods_