fflush(stdout);
va_end(args);
}
-
-static void _log(int prio, const char *fmt, ...)
-{
- 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;
-
- switch (prio) {
- 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", prio);
- prioname = buf;
- }
-
- fprintf(stderr, "depmod: %s: %s", prioname, msg);
- free(msg);
-
- if (prio <= LOG_CRIT)
- exit(EXIT_FAILURE);
-}
-#define CRIT(...) _log(LOG_CRIT, __VA_ARGS__)
-#define ERR(...) _log(LOG_ERR, __VA_ARGS__)
-#define WRN(...) _log(LOG_WARNING, __VA_ARGS__)
-#define INF(...) _log(LOG_INFO, __VA_ARGS__)
-#define DBG(...) _log(LOG_DEBUG, __VA_ARGS__)
#define SHOW(...) _show(__VA_ARGS__)
#include "kmod.h"
-#define LOGPREFIX "insmod: "
-#define ERR(...) fprintf(stderr, LOGPREFIX "ERROR: " __VA_ARGS__)
-
static const char cmdopts_s[] = "psfVh";
static const struct option cmdopts[] = {
{"version", no_argument, 0, 'V'},
(void)data;
}
+void log_printf(int prio, const char *fmt, ...)
+{
+ const char *prioname;
+ char *msg;
+ va_list args;
+
+ if (prio > log_priority)
+ 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 (log_use_syslog)
+ syslog(prio, "%s: %s", prioname, msg);
+ else
+ fprintf(stderr, "%s: %s: %s", binname, prioname, msg);
+ free(msg);
+
+ if (prio <= LOG_CRIT)
+ exit(EXIT_FAILURE);
+}
+
void log_setup_kmod_log(struct kmod_ctx *ctx, int priority)
{
log_priority = priority;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
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);
+void log_printf(int prio, const char *fmt, ...);
+#define CRIT(...) log_printf(LOG_CRIT, __VA_ARGS__)
+#define ERR(...) log_printf(LOG_ERR, __VA_ARGS__)
+#define WRN(...) log_printf(LOG_WARNING, __VA_ARGS__)
+#define INF(...) log_printf(LOG_INFO, __VA_ARGS__)
+#define DBG(...) log_printf(LOG_DEBUG, __VA_ARGS__)
struct kmod_ctx;
void log_setup_kmod_log(struct kmod_ctx *ctx, int priority);
#include "kmod.h"
-#define LOGPREFIX "modinfo: "
-#define ERR(...) fprintf(stderr, LOGPREFIX "ERROR: " __VA_ARGS__)
-
static char separator = '\n';
static const char *field = NULL;
#include <sys/utsname.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <syslog.h>
#include <limits.h>
#include "libkmod.h"
static int log_priority = LOG_CRIT;
static int use_syslog = 0;
+#define LOG(...) log_printf(log_priority, __VA_ARGS__)
#define DEFAULT_VERBOSE LOG_WARNING
static int verbose = DEFAULT_VERBOSE;
fflush(stdout);
va_end(args);
}
-
-static 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(prio, "%s: %s", prioname, msg);
- else
- fprintf(stderr, "modprobe: %s: %s", prioname, msg);
- free(msg);
-
- if (prio <= LOG_CRIT)
- exit(EXIT_FAILURE);
-}
-#define ERR(...) _log(LOG_ERR, __VA_ARGS__)
-#define WRN(...) _log(LOG_WARNING, __VA_ARGS__)
-#define INF(...) _log(LOG_INFO, __VA_ARGS__)
-#define DBG(...) _log(LOG_DEBUG, __VA_ARGS__)
-#define LOG(...) _log(log_priority, __VA_ARGS__)
#define SHOW(...) _show(__VA_ARGS__)
static int show_config(struct kmod_ctx *ctx)
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <syslog.h>
#include "libkmod.h"
#include "macro.h"
binname);
}
-static 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(prio, "%s: %s", prioname, msg);
- else
- fprintf(stderr, "rmmod: %s: %s", prioname, msg);
- free(msg);
-
- if (prio <= LOG_CRIT)
- exit(EXIT_FAILURE);
-}
-#define ERR(...) _log(LOG_ERR, __VA_ARGS__)
-
static int check_module_inuse(struct kmod_module *mod) {
struct kmod_list *holders;