#include <errno.h>
#include <string.h>
#include <ctype.h>
+#include <sys/utsname.h>
#include "libkmod.h"
#include "libkmod-private.h"
int priority, const char *file, int line,
const char *fn, const char *format, va_list args);
void *userdata;
+ const char *dirname;
int log_priority;
};
vfprintf(stderr, format, args);
}
+const char *kmod_get_dirname(struct kmod_ctx *ctx)
+{
+ return ctx->dirname;
+}
+
/**
* kmod_get_userdata:
* @ctx: kmod library context
return 0;
}
+static const char *get_kernel_release(void)
+{
+ struct utsname u;
+
+ if (uname(&u) < 0)
+ return NULL;
+
+ return strdup(u.release);
+}
+
/**
* kmod_new:
*
*
* 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;
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)
if (--ctx->refcount > 0)
return ctx;
info(ctx, "context %p released\n", ctx);
+ free((char *)ctx->dirname);
free(ctx);
return NULL;
}
* 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,