tools: share setting up libkmod log

This also fixes a bug in "e6996c5 rmmod: route all messages to syslog if
told to" in which "+ verbose" was removed. Instead of letting verbose
add to kmod_get_log_priority(), let it be similar to the other programs
instead.
This commit is contained in:
Lucas De Marchi 2012-11-06 18:26:34 -02:00
parent 92aad74925
commit 52a50fe2e5
5 changed files with 17 additions and 5 deletions

View File

@ -2673,7 +2673,8 @@ static int do_depmod(int argc, char *argv[])
CRIT("kmod_new(\"%s\", {NULL}) failed: %m\n", cfg.dirname);
goto cmdline_failed;
}
kmod_set_log_priority(ctx, verbose);
log_setup_kmod_log(ctx, verbose);
err = depmod_init(&depmod, &cfg, ctx);
if (err < 0) {

View File

@ -21,9 +21,11 @@
#include <stdlib.h>
#include <syslog.h>
#include "libkmod.h"
#include "kmod.h"
static bool log_use_syslog;
static int log_priority = LOG_ERR;
void log_open(bool use_syslog)
{
@ -67,3 +69,11 @@ void log_kmod(void *data, int priority, const char *file, int line,
free(str);
(void)data;
}
void log_setup_kmod_log(struct kmod_ctx *ctx, int priority)
{
log_priority = priority;
kmod_set_log_priority(ctx, log_priority);
kmod_set_log_fn(ctx, log_kmod, NULL);
}

View File

@ -28,6 +28,9 @@ void log_close(void);
void log_kmod(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args);
struct kmod_ctx;
void log_setup_kmod_log(struct kmod_ctx *ctx, int priority);
_always_inline_ const char *prio_to_str(int prio);

View File

@ -929,8 +929,7 @@ static int do_modprobe(int argc, char **orig_argv)
goto done;
}
kmod_set_log_priority(ctx, verbose);
kmod_set_log_fn(ctx, log_kmod, NULL);
log_setup_kmod_log(ctx, verbose);
kmod_load_resources(ctx);

View File

@ -180,8 +180,7 @@ static int do_rmmod(int argc, char *argv[])
goto done;
}
kmod_set_log_priority(ctx, kmod_get_log_priority(ctx));
kmod_set_log_fn(ctx, log_kmod, NULL);
log_setup_kmod_log(ctx, verbose);
for (i = optind; i < argc; i++) {
struct kmod_module *mod;