chiark / gitweb /
[PATCH] rework the logging code so that each program logs with the proper name in...
authorgreg@kroah.com <greg@kroah.com>
Mon, 2 Feb 2004 16:19:41 +0000 (08:19 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:20 +0000 (21:13 -0700)
Makefile
libsysfs/sysfs.h
logging.h
udev.c
udevd.c
udevinfo.c
udevsend.c

index 05d5da5a33447f8bba18291f81f9886d448ebc5c..386583b7ebb41f1a8fe7aa904aca41ec12bcf87b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -195,7 +195,6 @@ OBJS =      udev_config.o   \
        udev-add.o      \
        udev-remove.o   \
        udevdb.o        \
-       logging.o       \
        namedev.o       \
        namedev_parse.o \
        $(SYSFS)        \
@@ -254,15 +253,15 @@ $(ROOT): udev.o $(OBJS) $(HEADERS) $(GEN_HEADERS)
        $(STRIPCMD) $@
 
 $(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) $@
 
-$(DAEMON): udevd.h udevd.o udevd.o logging.o
-       $(LD) $(LDFLAGS) -lpthread -o $@ $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+$(DAEMON): udevd.h udevd.o
+       $(LD) $(LDFLAGS) -lpthread -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
        $(STRIPCMD) $@
 
-$(SENDER): udevd.h udevsend.o udevd.o logging.o
-       $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+$(SENDER): udevd.h udevsend.o
+       $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
        $(STRIPCMD) $@
 
 clean:
index 4ea4919351782c1ddc4818934737477c903efc0d..49c9285bc37aa1c874ca4fa6833cc8a429608d87 100644 (file)
@@ -34,7 +34,7 @@
 
 /* Debugging */
 #ifdef DEBUG
-#include <syslog.h>
+#include "../logging.h" 
 #define dprintf(format, arg...)                                                                \
        do {                                                                            \
                log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg);        \
@@ -43,8 +43,4 @@
 #define dprintf(format, arg...) do { } while (0)
 #endif
 
-extern int log_message (int level, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-
-
 #endif /* _SYSFS_H_ */
index df5922b3e666e0af7a483685f895cfdb80a5b000..e233ddc88972b59ff6906fc4eded9a069bb02f65 100644 (file)
--- a/logging.h
+++ b/logging.h
@@ -1,9 +1,9 @@
 /*
  * 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>
  *
  *     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)
 
 #ifdef LOG
+#include <stdarg.h>
 #include <syslog.h>
 
 #undef info
        } while (0)
 #endif
 
-#endif /* LOG */
-
-extern int log_message (int level, const char *format, ...)
+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
diff --git a/udev.c b/udev.c
index 38b26916c99a63eb1774b5bb41e8c3361363e683..b45fb336be8c631023b891a7a60b3840433a6f07 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -38,6 +38,7 @@
 /* global variables */
 char **main_argv;
 char **main_envp;
+unsigned char logname[42];
 
 static void sig_handler(int signum)
 {
@@ -174,6 +175,7 @@ int main(int argc, char **argv, char **envp)
        main_argv = argv;
        main_envp = envp;
 
+       init_logging("udev");
        dbg("version %s", UDEV_VERSION);
 
        return udev_hotplug(argc, argv);
diff --git a/udevd.c b/udevd.c
index dc7d581c242e798b03d6071619446b1c61fe35f8..331b7e4b84aa9d0229f709268dcbe58248e88701 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -42,6 +42,7 @@
 #include "logging.h"
 
 
+unsigned char logname[42];
 static pthread_mutex_t  msg_lock;
 static pthread_mutex_t  msg_active_lock;
 static pthread_cond_t msg_active;
@@ -354,6 +355,8 @@ int main(int argc, char *argv[])
        pthread_t mgr_exec_tid;
        int retval;
 
+       init_logging("udevd");
+
        /* only let one version of the daemon run at any one time */
        if (one_and_only() != 0)
                exit(0);
index 4d28755b2f04a289e0c755f879101e5f3b8236d6..71a9a6d93e491c7a62d9cbcb74ff5550d7e02e45 100644 (file)
@@ -38,6 +38,7 @@
 
 char **main_argv;
 int main_argc;
+unsigned char logname[42];
 
 static int print_all_attributes(const char *path)
 {
@@ -412,6 +413,8 @@ int main(int argc, char *argv[], char *envp[])
        main_argv = argv;
        main_argc = argc;
 
+       init_logging("udevinfo");
+
        /* initialize our configuration */
        udev_init_config();
 
index 0ddc6839def3d63c2fbc74201dbbfe4395b9fb0c..6af9df77040a386c39a93ddf1245235efd517eda 100644 (file)
@@ -40,6 +40,7 @@
 #include "udevd.h"
 #include "logging.h"
 
+unsigned char logname[42];
 
 static inline char *get_action(void)
 {
@@ -126,6 +127,8 @@ int main(int argc, char* argv[])
        int sock;
        struct sockaddr_un saddr;
 
+       init_logging("udevsend");
+
        subsystem = argv[1];
        if (subsystem == NULL) {
                dbg("no subsystem");