]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools: kmod: Add handling of compat lsmod
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 22 Dec 2011 05:01:45 +0000 (03:01 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 23 Dec 2011 05:09:05 +0000 (03:09 -0200)
Makefile.am
tools/kmod-lsmod.c
tools/kmod.c
tools/kmod.h

index 3eaef81a9253ae2f2114e803b7fe6161924a1c76..cde141599b0bedfa9294e2a1db3b14b45fa80ccc 100644 (file)
@@ -90,7 +90,8 @@ tools_kmod_lsmod_LDADD = libkmod/libkmod.la
 tools_kmod_modprobe_LDADD = libkmod/libkmod.la
 tools_kmod_modinfo_LDADD = libkmod/libkmod.la
 
-tools_kmod_SOURCES = tools/kmod.c tools/kmod.h
+tools_kmod_SOURCES = tools/kmod.c tools/kmod.h tools/kmod-lsmod.c
+tools_kmod_CPPFLAGS = $(AM_CPPFLAGS) -DKMOD_BUNDLE_TOOL=1
 tools_kmod_LDADD = libkmod/libkmod.la
 endif
 
index 493231c9945dd9f8e23462ceb292047a98218250..381b720f46bc3437bf35cff216cdd4d9d92dd5f6 100644 (file)
@@ -26,7 +26,7 @@
 #include "libkmod.h"
 
 
-int main(int argc, char *argv[])
+static int do_lsmod(int argc, char *argv[])
 {
        struct kmod_ctx *ctx;
        const char *null_config = NULL;
@@ -84,3 +84,20 @@ int main(int argc, char *argv[])
 
        return EXIT_SUCCESS;
 }
+
+#ifndef KMOD_BUNDLE_TOOL
+int main(int argc, char *argv[])
+{
+       return do_lsmod(argc, argv);
+}
+
+#else
+#include "kmod.h"
+
+const struct kmod_cmd kmod_cmd_compat_lsmod = {
+       .name = "lsmod",
+       .cmd = do_lsmod,
+       .help = "compat lsmod command",
+};
+
+#endif
index 712655d90916d29bdaf32b9ee318f0a348e0494d..c5230f827ef8b5bebb59cf83f474dcf02b20a638 100644 (file)
@@ -38,6 +38,10 @@ static const struct kmod_cmd *kmod_cmds[] = {
        &kmod_cmd_help,
 };
 
+static const struct kmod_cmd *kmod_compat_cmds[] = {
+       &kmod_cmd_compat_lsmod,
+};
+
 static int kmod_help(int argc, char *argv[])
 {
        size_t i;
@@ -57,8 +61,14 @@ static int kmod_help(int argc, char *argv[])
                }
        }
 
-       puts("\nkmod will also handle gracefully if called\n"
-                       "from a symlink to previous tools\n");
+       puts("\nkmod also handles gracefully if called from following symlinks:");
+
+       for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
+               if (kmod_compat_cmds[i]->help != NULL) {
+                       printf("  %-12s %s\n", kmod_compat_cmds[i]->name,
+                                               kmod_compat_cmds[i]->help);
+               }
+       }
 
        return EXIT_SUCCESS;
 }
@@ -120,6 +130,25 @@ finish:
        return err;
 }
 
+
+static int handle_kmod_compat_commands(int argc, char *argv[])
+{
+       const char *cmd;
+       int err = -ENOENT;
+       size_t i;
+
+       cmd = basename(argv[0]);
+
+       for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
+               if (strcmp(kmod_compat_cmds[i]->name, cmd) != 0)
+                       continue;
+
+               err = kmod_compat_cmds[i]->cmd(argc, argv);
+       }
+
+       return err;
+}
+
 int main(int argc, char *argv[])
 {
        const char *binname = basename(argv[0]);
@@ -128,7 +157,7 @@ int main(int argc, char *argv[])
        if (strcmp(binname, "kmod") == 0)
                err = handle_kmod_commands(argc, argv);
        else
-               err = -ENOENT;
+               err = handle_kmod_compat_commands(argc, argv);
 
        return err;
 }
index 27cb71afd9b317bf4e0384ce5f2c220af86d7675..54c6b3638a71d3c561cacac8a435b81c532ff35a 100644 (file)
@@ -27,4 +27,6 @@ struct kmod_cmd {
        const char *help;
 };
 
+extern const struct kmod_cmd kmod_cmd_compat_lsmod;
+
 #endif