From: Lucas De Marchi Date: Fri, 25 Nov 2011 03:25:18 +0000 (-0200) Subject: Add test-insmod to insert modules X-Git-Tag: v1~184 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5494f831f10132bb36ca0b7eef5f5bc60d26303;p=thirdparty%2Fkmod.git Add test-insmod to insert modules Insmod is supported only with file names yet. --- diff --git a/Makefile.am b/Makefile.am index 13b655b0..4a0f09bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,10 +53,13 @@ test_test_init_LDADD = libkmod/libkmod.la test_test_loaded_SOURCES = test/test-loaded.c test_test_loaded_LDADD = libkmod/libkmod.la -noinst_PROGRAMS = test/test-rmmod test/test-rmmod2 \ +noinst_PROGRAMS = test/test-insmod test/test-rmmod test/test-rmmod2 \ $(check_PROGRAMS) test_test_rmmod_SOURCES = test/test-rmmod.c test_test_rmmod_LDADD = libkmod/libkmod.la test_test_rmmod2_SOURCES = test/test-rmmod2.c test_test_rmmod2_LDADD = libkmod/libkmod.la + +test_test_insmod_SOURCES = test/test-insmod.c +test_test_insmod_LDADD = libkmod/libkmod.la diff --git a/test/.gitignore b/test/.gitignore index db1a45e4..bc9eb6ee 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -3,3 +3,4 @@ test-init test-loaded test-rmmod test-rmmod2 +test-insmod diff --git a/test/test-insmod.c b/test/test-insmod.c new file mode 100644 index 00000000..bbff8784 --- /dev/null +++ b/test/test-insmod.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + const char *path; + struct kmod_ctx *ctx; + struct kmod_module *mod; + int err; + + if (argc < 2) { + fprintf(stderr, "Provide a path to a module\n"); + return EXIT_FAILURE; + } + + path = argv[1]; + + ctx = kmod_new(NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + printf("libkmod version %s\n", VERSION); + + err = kmod_module_new_from_path(ctx, path, &mod); + if (err < 0) + exit(EXIT_FAILURE); + + printf("Trying insmod '%s'\n", path); + err = kmod_module_insert_module(mod, 0); + if (err < 0) { + fprintf(stderr, "%s\n", strerror(-err)); + + kmod_module_unref(mod); + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + + kmod_module_unref(mod); + kmod_unref(ctx); + + return EXIT_SUCCESS; +}