]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Accept dir where we should lookup for modules
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 24 Nov 2011 18:41:01 +0000 (16:41 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 25 Nov 2011 01:20:42 +0000 (23:20 -0200)
libkmod/libkmod-private.h
libkmod/libkmod.c
libkmod/libkmod.h
test/test-init.c
test/test-loaded.c
test/test-rmmod.c

index 0ce916707593b2ad19636cccb4b0aa9488c12d33..56ada3a4acdd44cba608cfe7a5003af46110059a 100644 (file)
@@ -51,4 +51,6 @@ struct kmod_list *kmod_list_remove(struct kmod_list *list);
 struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
                                        const void *data) __must_check;
 
+const char *kmod_get_dirname(struct kmod_ctx *ctx) __attribute__((nonnull(1)));
+
 #endif
index 9307f713292fa505f7f613368ab596bfbe4e1278..6417cab9923cb030722e7e147d70ae2e453e5cad 100644 (file)
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <string.h>
 #include <ctype.h>
+#include <sys/utsname.h>
 
 #include "libkmod.h"
 #include "libkmod-private.h"
@@ -49,6 +50,7 @@ struct kmod_ctx {
                        int priority, const char *file, int line,
                        const char *fn, const char *format, va_list args);
        void *userdata;
+       const char *dirname;
        int log_priority;
 };
 
@@ -71,6 +73,11 @@ static void log_stderr(struct kmod_ctx *ctx,
        vfprintf(stderr, format, args);
 }
 
+const char *kmod_get_dirname(struct kmod_ctx *ctx)
+{
+       return ctx->dirname;
+}
+
 /**
  * kmod_get_userdata:
  * @ctx: kmod library context
@@ -118,6 +125,16 @@ static int log_priority(const char *priority)
        return 0;
 }
 
+static const char *get_kernel_release(void)
+{
+       struct utsname u;
+
+       if (uname(&u) < 0)
+               return NULL;
+
+       return strdup(u.release);
+}
+
 /**
  * kmod_new:
  *
@@ -129,7 +146,7 @@ static int log_priority(const char *priority)
  *
  * Returns: a new kmod library context
  **/
-KMOD_EXPORT struct kmod_ctx *kmod_new(void)
+KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname)
 {
        const char *env;
        struct kmod_ctx *ctx;
@@ -142,6 +159,11 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(void)
        ctx->log_fn = log_stderr;
        ctx->log_priority = LOG_ERR;
 
+       if (dirname != NULL)
+               ctx->dirname = strdup(dirname);
+       else
+               ctx->dirname = get_kernel_release();
+
        /* environment overwrites config */
        env = getenv("KMOD_LOG");
        if (env != NULL)
@@ -185,6 +207,7 @@ KMOD_EXPORT struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx)
        if (--ctx->refcount > 0)
                return ctx;
        info(ctx, "context %p released\n", ctx);
+       free((char *)ctx->dirname);
        free(ctx);
        return NULL;
 }
index 2aa0e013221a510adff6935673f05288532ffde9..d68d2ef36f7e5a71736c16fbd8e62a1398ed1c1c 100644 (file)
@@ -36,7 +36,7 @@ extern "C" {
  * environment, user variables, allows custom logging
  */
 struct kmod_ctx;
-struct kmod_ctx *kmod_new(void);
+struct kmod_ctx *kmod_new(const char *dirname);
 struct kmod_ctx *kmod_ref(struct kmod_ctx *ctx);
 struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx);
 void kmod_set_log_fn(struct kmod_ctx *ctx,
index 140b669c8123631471f34668d5e6515ac99e4a5f..18317aafecb6bf913b64ec0b3600ecd7aad8ac63 100644 (file)
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
 {
        struct kmod_ctx *ctx;
 
-       ctx = kmod_new();
+       ctx = kmod_new(NULL);
        if (ctx == NULL)
                exit(EXIT_FAILURE);
 
index c81c28849e32d45c6bd8f7c8574bd02bb9cd4095..e5cfe13d47fc320a0bc0751714e84735bb21446c 100644 (file)
@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
        struct kmod_list *list, *itr;
        int err;
 
-       ctx = kmod_new();
+       ctx = kmod_new(NULL);
        if (ctx == NULL)
                exit(EXIT_FAILURE);
 
index 759743eab5cd20f5e287dfe6651c9f508bd99da4..d7690b34debb3b465e7ddd82116d8afe3faec433 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
        if (argc == 2)
                modname = argv[1];
 
-       ctx = kmod_new();
+       ctx = kmod_new(NULL);
        if (ctx == NULL)
                exit(EXIT_FAILURE);