Message ID | 1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com |
---|---|
State | Rejected |
Headers | show |
Dear Frans Meulenbroeks, In message <1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com> you wrote: > 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
2012/1/5 Wolfgang Denk <wd@denx.de> > Dear Frans Meulenbroeks, > > In message <1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com> > you wrote: > > 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 > > > 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
Dear Frans, In message <CACW_hTY4oqT8bBGTkTopiX=rNpCmG50rNXWY0AfydAX3wZj5Rg@mail.gmail.com> you wrote: > > > 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. > 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
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 996682e..992835f 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -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 */
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 Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com> --- tools/env/fw_env.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)