[PATCH] rework the logging code so that each program logs with the proper name in the syslog.
This commit is contained in:
parent
3a7798f471
commit
95a6f4c8ac
11
Makefile
11
Makefile
|
@ -195,7 +195,6 @@ OBJS = udev_config.o \
|
||||||
udev-add.o \
|
udev-add.o \
|
||||||
udev-remove.o \
|
udev-remove.o \
|
||||||
udevdb.o \
|
udevdb.o \
|
||||||
logging.o \
|
|
||||||
namedev.o \
|
namedev.o \
|
||||||
namedev_parse.o \
|
namedev_parse.o \
|
||||||
$(SYSFS) \
|
$(SYSFS) \
|
||||||
|
@ -254,15 +253,15 @@ $(ROOT): udev.o $(OBJS) $(HEADERS) $(GEN_HEADERS)
|
||||||
$(STRIPCMD) $@
|
$(STRIPCMD) $@
|
||||||
|
|
||||||
$(HELPER): udevinfo.o $(OBJS) $(HEADERS)
|
$(HELPER): udevinfo.o $(OBJS) $(HEADERS)
|
||||||
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o logging.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(STRIPCMD) $@
|
||||||
|
|
||||||
$(DAEMON): udevd.h udevd.o udevd.o logging.o
|
$(DAEMON): udevd.h udevd.o
|
||||||
$(LD) $(LDFLAGS) -lpthread -o $@ $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
$(LD) $(LDFLAGS) -lpthread -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(STRIPCMD) $@
|
||||||
|
|
||||||
$(SENDER): udevd.h udevsend.o udevd.o logging.o
|
$(SENDER): udevd.h udevsend.o
|
||||||
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(STRIPCMD) $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
/* Debugging */
|
/* Debugging */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <syslog.h>
|
#include "../logging.h"
|
||||||
#define dprintf(format, arg...) \
|
#define dprintf(format, arg...) \
|
||||||
do { \
|
do { \
|
||||||
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
||||||
|
@ -43,8 +43,4 @@
|
||||||
#define dprintf(format, arg...) do { } while (0)
|
#define dprintf(format, arg...) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int log_message (int level, const char *format, ...)
|
|
||||||
__attribute__ ((format (printf, 2, 3)));
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _SYSFS_H_ */
|
#endif /* _SYSFS_H_ */
|
||||||
|
|
28
logging.h
28
logging.h
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* logging.h
|
* logging.h
|
||||||
*
|
*
|
||||||
* Userspace devfs
|
* Simple logging functions that can be compiled away into nothing.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
|
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
|
||||||
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
|
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
#define dbg_parse(format, arg...) do { } while (0)
|
#define dbg_parse(format, arg...) do { } while (0)
|
||||||
|
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
|
#include <stdarg.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#undef info
|
#undef info
|
||||||
|
@ -54,9 +55,26 @@
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void log_message (int level, const char *format, ...)
|
||||||
|
__attribute__ ((format (printf, 2, 3)));
|
||||||
|
static inline void log_message (int level, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
vsyslog(level, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* each program must declare this variable somewhere */
|
||||||
|
extern unsigned char logname[42];
|
||||||
|
|
||||||
|
static inline void init_logging(char *program_name)
|
||||||
|
{
|
||||||
|
snprintf(logname, 42,"%s[%d]", program_name, getpid());
|
||||||
|
openlog(logname, 0, LOG_DAEMON);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* LOG */
|
#endif /* LOG */
|
||||||
|
|
||||||
extern int log_message (int level, const char *format, ...)
|
|
||||||
__attribute__ ((format (printf, 2, 3)));
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
2
udev.c
2
udev.c
|
@ -38,6 +38,7 @@
|
||||||
/* global variables */
|
/* global variables */
|
||||||
char **main_argv;
|
char **main_argv;
|
||||||
char **main_envp;
|
char **main_envp;
|
||||||
|
unsigned char logname[42];
|
||||||
|
|
||||||
static void sig_handler(int signum)
|
static void sig_handler(int signum)
|
||||||
{
|
{
|
||||||
|
@ -174,6 +175,7 @@ int main(int argc, char **argv, char **envp)
|
||||||
main_argv = argv;
|
main_argv = argv;
|
||||||
main_envp = envp;
|
main_envp = envp;
|
||||||
|
|
||||||
|
init_logging("udev");
|
||||||
dbg("version %s", UDEV_VERSION);
|
dbg("version %s", UDEV_VERSION);
|
||||||
|
|
||||||
return udev_hotplug(argc, argv);
|
return udev_hotplug(argc, argv);
|
||||||
|
|
3
udevd.c
3
udevd.c
|
@ -42,6 +42,7 @@
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char logname[42];
|
||||||
static pthread_mutex_t msg_lock;
|
static pthread_mutex_t msg_lock;
|
||||||
static pthread_mutex_t msg_active_lock;
|
static pthread_mutex_t msg_active_lock;
|
||||||
static pthread_cond_t msg_active;
|
static pthread_cond_t msg_active;
|
||||||
|
@ -354,6 +355,8 @@ int main(int argc, char *argv[])
|
||||||
pthread_t mgr_exec_tid;
|
pthread_t mgr_exec_tid;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
init_logging("udevd");
|
||||||
|
|
||||||
/* only let one version of the daemon run at any one time */
|
/* only let one version of the daemon run at any one time */
|
||||||
if (one_and_only() != 0)
|
if (one_and_only() != 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
char **main_argv;
|
char **main_argv;
|
||||||
int main_argc;
|
int main_argc;
|
||||||
|
unsigned char logname[42];
|
||||||
|
|
||||||
static int print_all_attributes(const char *path)
|
static int print_all_attributes(const char *path)
|
||||||
{
|
{
|
||||||
|
@ -412,6 +413,8 @@ int main(int argc, char *argv[], char *envp[])
|
||||||
main_argv = argv;
|
main_argv = argv;
|
||||||
main_argc = argc;
|
main_argc = argc;
|
||||||
|
|
||||||
|
init_logging("udevinfo");
|
||||||
|
|
||||||
/* initialize our configuration */
|
/* initialize our configuration */
|
||||||
udev_init_config();
|
udev_init_config();
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "udevd.h"
|
#include "udevd.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
unsigned char logname[42];
|
||||||
|
|
||||||
static inline char *get_action(void)
|
static inline char *get_action(void)
|
||||||
{
|
{
|
||||||
|
@ -126,6 +127,8 @@ int main(int argc, char* argv[])
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_un saddr;
|
struct sockaddr_un saddr;
|
||||||
|
|
||||||
|
init_logging("udevsend");
|
||||||
|
|
||||||
subsystem = argv[1];
|
subsystem = argv[1];
|
||||||
if (subsystem == NULL) {
|
if (subsystem == NULL) {
|
||||||
dbg("no subsystem");
|
dbg("no subsystem");
|
||||||
|
|
Loading…
Reference in New Issue