From: Lucas De Marchi Date: Thu, 22 Dec 2011 05:01:45 +0000 (-0200) Subject: tools: kmod: Add handling of compat lsmod X-Git-Tag: v3~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fcf69e62b5d0f428b31b8cc311120567ad9ee88;p=thirdparty%2Fkmod.git tools: kmod: Add handling of compat lsmod --- diff --git a/Makefile.am b/Makefile.am index 3eaef81a..cde14159 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/tools/kmod-lsmod.c b/tools/kmod-lsmod.c index 493231c9..381b720f 100644 --- a/tools/kmod-lsmod.c +++ b/tools/kmod-lsmod.c @@ -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 diff --git a/tools/kmod.c b/tools/kmod.c index 712655d9..c5230f82 100644 --- a/tools/kmod.c +++ b/tools/kmod.c @@ -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; } diff --git a/tools/kmod.h b/tools/kmod.h index 27cb71af..54c6b363 100644 --- a/tools/kmod.h +++ b/tools/kmod.h @@ -27,4 +27,6 @@ struct kmod_cmd { const char *help; }; +extern const struct kmod_cmd kmod_cmd_compat_lsmod; + #endif