summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-31 22:00:40 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-31 22:00:40 -0200
commit1e947e3c8749e6ce0d80be372de9f5e670bd1802 (patch)
tree36883678f2e296b10633d3f876284097e69063a4
parent4434d8ba363900e47190f39297ee690485794c1c (diff)
downloadkmod-1e947e3c8749e6ce0d80be372de9f5e670bd1802.tar.gz
kmod-1e947e3c8749e6ce0d80be372de9f5e670bd1802.tar.bz2
kmod-1e947e3c8749e6ce0d80be372de9f5e670bd1802.zip
modprobe: use prio_to_str() helper
-rw-r--r--tools/modprobe.c64
1 files changed, 25 insertions, 39 deletions
diff --git a/tools/modprobe.c b/tools/modprobe.c
index d03bce6..7bcf2b0 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -152,21 +152,10 @@ static inline void _show(const char *fmt, ...)
va_end(args);
}
-static inline void _log(int prio, const char *fmt, ...)
+static _always_inline_ const char *prio_to_str(int prio)
{
const char *prioname;
- char buf[32], *msg;
- va_list args;
-
- if (prio > verbose)
- return;
-
- va_start(args, fmt);
- if (vasprintf(&msg, fmt, args) < 0)
- msg = NULL;
- va_end(args);
- if (msg == NULL)
- return;
+ char buf[32];
switch (prio) {
case LOG_CRIT:
@@ -192,6 +181,27 @@ static inline void _log(int prio, const char *fmt, ...)
prioname = buf;
}
+ return prioname;
+}
+
+static inline void _log(int prio, const char *fmt, ...)
+{
+ const char *prioname;
+ char *msg;
+ va_list args;
+
+ if (prio > verbose)
+ return;
+
+ va_start(args, fmt);
+ if (vasprintf(&msg, fmt, args) < 0)
+ msg = NULL;
+ va_end(args);
+ if (msg == NULL)
+ return;
+
+ prioname = prio_to_str(prio);
+
if (use_syslog)
syslog(LOG_NOTICE, "%s: %s", prioname, msg);
else
@@ -789,32 +799,8 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)
static void log_syslog(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args)
{
- char *str, buf[32];
- const char *prioname;
-
- switch (priority) {
- case LOG_CRIT:
- prioname = "FATAL";
- break;
- case LOG_ERR:
- prioname = "ERROR";
- break;
- case LOG_WARNING:
- prioname = "WARNING";
- break;
- case LOG_NOTICE:
- prioname = "NOTICE";
- break;
- case LOG_INFO:
- prioname = "INFO";
- break;
- case LOG_DEBUG:
- prioname = "DEBUG";
- break;
- default:
- snprintf(buf, sizeof(buf), "LOG-%03d", priority);
- prioname = buf;
- }
+ char *str;
+ const char *prioname = prio_to_str(priority);
if (vasprintf(&str, format, args) < 0)
return;