]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Dont use errno unconditionally
authorKhem Raj <raj.khem@gmail.com>
Fri, 3 Feb 2012 07:09:59 +0000 (23:09 -0800)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 3 Feb 2012 16:52:59 +0000 (14:52 -0200)
fopen() will not reset errno if it succeeds so we should
make sure that we only use errno in error cases.

Also fix the diagnostic messages to not use strerror
when there is no error since strerror will not return
anything useful in this case

tools/kmod-depmod.c

index 0721dafbc96e123dac0c1482c7a5088772c9e45e..1871e18d9db14665025904604947464bdb081ab8 100644 (file)
@@ -941,7 +941,7 @@ static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files,
        }
 
        closedir(d);
-       DBG("parsed configuration files from %s: %s\n", path, strerror(-err));
+       DBG("parsed configuration files from %s\n", path);
        return err;
 }
 
@@ -2293,13 +2293,14 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
        char line[10240];
        FILE *fp;
        unsigned int linenum = 0;
-       int err;
 
        fp = fopen(filename, "r");
-       err = -errno;
-       DBG("load symvers: %s: %s\n", filename, strerror(-err));
-       if (fp == NULL)
+       if (fp == NULL) {
+               int err = -errno;
+               DBG("load symvers: %s: %m\n", filename);
                return err;
+       }
+       DBG("load symvers: %s\n", filename);
 
        /* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
        while (fgets(line, sizeof(line), fp) != NULL) {
@@ -2329,10 +2330,10 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
        }
        depmod_add_fake_syms(depmod);
 
-       DBG("loaded symvers: %s: %s\n", filename, strerror(-err));
+       DBG("loaded symvers: %s\n", filename);
 
        fclose(fp);
-       return err;
+       return 0;
 }
 
 static int depmod_load_system_map(struct depmod *depmod, const char *filename)
@@ -2342,13 +2343,14 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename)
        char line[10240];
        FILE *fp;
        unsigned int linenum = 0;
-       int err;
 
        fp = fopen(filename, "r");
-       err = -errno;
-       DBG("load System.map: %s: %s\n", filename, strerror(-err));
-       if (fp == NULL)
+       if (fp == NULL) {
+               int err = -errno;
+               DBG("load System.map: %s: %m\n", filename);
                return err;
+       }
+       DBG("load System.map: %s\n", filename);
 
        /* eg. c0294200 R __ksymtab_devfs_alloc_devnum */
        while (fgets(line, sizeof(line), fp) != NULL) {
@@ -2381,10 +2383,10 @@ static int depmod_load_system_map(struct depmod *depmod, const char *filename)
        }
        depmod_add_fake_syms(depmod);
 
-       DBG("loaded System.map: %s: %s\n", filename, strerror(-err));
+       DBG("loaded System.map: %s\n", filename);
 
        fclose(fp);
-       return err;
+       return 0;
 }
 
 
@@ -2673,7 +2675,7 @@ static int do_depmod(int argc, char *argv[])
        } else if (system_map != NULL) {
                err = depmod_load_system_map(&depmod, system_map);
                if (err < 0) {
-                       CRIT("could not load %s: %s\n", module_symvers,
+                       CRIT("could not load %s: %s\n", system_map,
                             strerror(-err));
                        goto cmdline_failed;
                }