]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: fixup kmod_module_get_initstate() error reporting
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 7 May 2025 12:10:42 +0000 (13:10 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 20 May 2025 02:51:43 +0000 (21:51 -0500)
Currently, the function will report the exact same issue twice. Where
the second DBG() and the error code returned, should highlight the
(potential) stat(2) failure.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-module.c

index 2b51010ed2f9c82217f826fcfb00d2452eef0a08..a9d103e6dba2524d24f212c25e0d528c24f86b56 100644 (file)
@@ -1434,7 +1434,6 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod)
        fd = open(path, O_RDONLY | O_CLOEXEC);
        if (fd < 0) {
                err = -errno;
-
                DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err));
 
                if (pathlen > (int)sizeof("/initstate") - 1) {
@@ -1442,9 +1441,10 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod)
                        path[pathlen - (sizeof("/initstate") - 1)] = '\0';
                        if (stat(path, &st) == 0 && S_ISDIR(st.st_mode))
                                return KMOD_MODULE_COMING;
-               }
 
-               DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err));
+                       err = -errno;
+                       DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err));
+               }
                return err;
        }