aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2012-11-01 12:24:58 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-11-01 12:46:03 -0200
commit86cc1f2328d548e28eb18b5e5f4cab7f7190a023 (patch)
tree58747005e698c4cae04e48b4c105f58176c8cd43
parent1e947e3c8749e6ce0d80be372de9f5e670bd1802 (diff)
downloadkmod-86cc1f2328d548e28eb18b5e5f4cab7f7190a023.tar.gz
modprobe: prefix libkmod messages to stderr with modprobe:
When we are logging to stderr we are previously relying on libkmod sending it to the default location in case we are not asked to log to syslog. The problem is that modprobe may be used in scripts that don't want to log to syslog (since they are not daemons, like scripts to generate initrd) and then it's difficult to know where the message comes from. This patch treats only the messages coming from libkmod.
-rw-r--r--tools/modprobe.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/tools/modprobe.c b/tools/modprobe.c
index 7bcf2b0..17a8c17 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -796,19 +796,31 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)
return new_argv;
}
-static void log_syslog(void *data, int priority, const char *file, int line,
+static void log_modprobe(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args)
{
- char *str;
const char *prioname = prio_to_str(priority);
+ char *str;
if (vasprintf(&str, format, args) < 0)
return;
+
+ if (use_syslog) {
+#ifdef ENABLE_DEBUG
+ syslog(priority, "%s: %s:%d %s() %s", prioname, file, line,
+ fn, str);
+#else
+ syslog(priority, "%s: %s", prioname, str);
+#endif
+ } else {
#ifdef ENABLE_DEBUG
- syslog(LOG_NOTICE, "%s: %s:%d %s() %s", prioname, file, line, fn, str);
+ fprintf(stderr, "modprobe: %s: %s:%d %s() %s", prioname, file,
+ line, fn, str);
#else
- syslog(LOG_NOTICE, "%s: %s", prioname, str);
+ fprintf(stderr, "modprobe: %s: %s", prioname, str);
#endif
+ }
+
free(str);
(void)data;
}
@@ -974,10 +986,9 @@ static int do_modprobe(int argc, char **orig_argv)
kmod_load_resources(ctx);
kmod_set_log_priority(ctx, verbose);
- if (use_syslog) {
+ kmod_set_log_fn(ctx, log_modprobe, NULL);
+ if (use_syslog)
openlog("modprobe", LOG_CONS, LOG_DAEMON);
- kmod_set_log_fn(ctx, log_syslog, NULL);
- }
if (do_show_config)
err = show_config(ctx);