chiark / gitweb /
[PATCH] add udev logging to info log
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 16 Jan 2004 05:53:20 +0000 (21:53 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:17 +0000 (21:13 -0700)
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
>   Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
>   Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
>   Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'

Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.

If you type:

  'make'            - you will get a binary that prints one or two lines to syslog
                      if a device node is created or deleted

  'make LOG=false'  - you get a binary that prints asolutely nothing

  'make DEBUG=true' - the same as today, it will print all debug lines

12 files changed:
Makefile
logging.c
logging.h [new file with mode: 0644]
namedev.c
namedev.h
namedev_parse.c
udev-add.c
udev-remove.c
udev.c
udev.h
udev_config.c
udevdb.c

index 80c4908ccb05b0b3119941d1b48d0b04b8fc1787..88c7cf0bc767167ccfeb29189a827e15f306424f 100644 (file)
--- a/Makefile
+++ b/Makefile
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
-# Set the following to `true' to make a debuggable build.
+# Set the following to control the use of syslog
+# Set it to `false' to remove all logging
+LOG = true
+
+# Set the following to `true' to log the debug
+# and make a unstripped, unoptimized  binary.
 # Leave this set to `false' for production use.
 DEBUG = false
 
 # Leave this set to `false' for production use.
 DEBUG = false
 
@@ -104,6 +109,10 @@ else
        CFLAGS+=-pipe
 endif
 
        CFLAGS+=-pipe
 endif
 
+ifeq ($(strip $(LOG)),true)
+       CFLAGS  += -DLOG
+endif
+
 # if DEBUG is enabled, then we do not strip or optimize
 ifeq ($(strip $(DEBUG)),true)
        CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG -D_GNU_SOURCE
 # if DEBUG is enabled, then we do not strip or optimize
 ifeq ($(strip $(DEBUG)),true)
        CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG -D_GNU_SOURCE
@@ -216,7 +225,7 @@ $(LOCAL_CFG_DIR)/udev.conf:
 
 $(OBJS): $(GEN_HEADERS)
 
 
 $(OBJS): $(GEN_HEADERS)
 
-$(ROOT): $(OBJS) udev.h namedev.h udev_version.h udev_dbus.h udevdb.h klibc_fixups.h list.h
+$(ROOT): $(OBJS) udev.h namedev.h udev_version.h udev_dbus.h udevdb.h klibc_fixups.h logging.h list.h
        $(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
        $(STRIPCMD) $(ROOT)
 
        $(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
        $(STRIPCMD) $(ROOT)
 
index 4815f39fdc377d261b92b212a4122398b4b1b780..cf1da5e0404681d3919743d22c0f322fed98d910 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -25,9 +25,9 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <syslog.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <syslog.h>
-#include "udev.h"
 
 
-#ifdef DEBUG
+#include "logging.h"
+
 
 static int logging_init = 0;
 static unsigned char udev_logname[42];
 
 static int logging_init = 0;
 static unsigned char udev_logname[42];
@@ -54,5 +54,3 @@ int log_message(int level, const char *format, ...)
        va_end(args);
        return 1;
 }
        va_end(args);
        return 1;
 }
-
-#endif
diff --git a/logging.h b/logging.h
new file mode 100644 (file)
index 0000000..85016ad
--- /dev/null
+++ b/logging.h
@@ -0,0 +1,60 @@
+/*
+ * udev.h
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2003 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
+ *     under the terms of the GNU General Public License as published by the
+ *     Free Software Foundation version 2 of the License.
+ * 
+ *     This program is distributed in the hope that it will be useful, but
+ *     WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *     General Public License for more details.
+ * 
+ *     You should have received a copy of the GNU General Public License along
+ *     with this program; if not, write to the Free Software Foundation, Inc.,
+ *     675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#ifdef LOG
+#include <syslog.h>
+#define info(format, arg...)                                                           \
+       do {                                                                            \
+               log_message (LOG_INFO , format , ## arg);       \
+       } while (0)
+#else
+       #define info(format, arg...) do { } while (0)
+#endif
+
+#ifdef DEBUG
+#define dbg(format, arg...)                                                            \
+       do {                                                                            \
+               log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg);        \
+       } while (0)
+#else
+       #define dbg(format, arg...) do { } while (0)
+#endif
+
+/* Parser needs it's own debugging statement, we usually don't care about this at all */
+#ifdef DEBUG_PARSER
+#define dbg_parse(format, arg...)                                                      \
+       do {                                                                            \
+               log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg);        \
+       } while (0)
+#else
+       #define dbg_parse(format, arg...) do { } while (0)
+#endif
+
+
+extern int log_message (int level, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+
+#endif
index b3b23521d6cf154f1554921546171ddb480809ce..137446e255322143a08fc424c6907d87695fe9bd 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -36,6 +36,7 @@
 #include "list.h"
 #include "udev.h"
 #include "udev_version.h"
 #include "list.h"
 #include "udev.h"
 #include "udev_version.h"
+#include "logging.h"
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
 #include "klibc_fixups.h"
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
 #include "klibc_fixups.h"
@@ -285,12 +286,12 @@ static void wait_for_device_to_initialize(struct sysfs_device *sysfs_device)
                                /* sleep to give the kernel a chance to create the file */
                                sleep(1);
                        }
                                /* sleep to give the kernel a chance to create the file */
                                sleep(1);
                        }
-                       dbg("Timed out waiting for '%s' file, continuing on anyway...", b->file);
+                       dbg("timed out waiting for '%s' file, continuing on anyway...", b->file);
                        goto exit;
                }
                b++;
        }
                        goto exit;
                }
                b++;
        }
-       dbg("Did not find bus type '%s' on list of bus_id_files, contact greg@kroah.com", sysfs_device->bus);
+       dbg("did not find bus type '%s' on list of bus_id_files, contact greg@kroah.com", sysfs_device->bus);
 exit:
        return; /* here to prevent compiler warning... */
 }
 exit:
        return; /* here to prevent compiler warning... */
 }
@@ -534,7 +535,7 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de
                if (sysfs_device != NULL)
                        goto device_found;
        }
                if (sysfs_device != NULL)
                        goto device_found;
        }
-       dbg("Timed out waiting for device symlink, continuing on anyway...");
+       dbg("timed out waiting for device symlink, continuing on anyway...");
        
 device_found:
         /* We have another issue with just the wait above - the sysfs part of
        
 device_found:
         /* We have another issue with just the wait above - the sysfs part of
@@ -559,10 +560,10 @@ device_found:
                        if (sysfs_device->bus[0] != '\0')
                                goto bus_found;
                }
                        if (sysfs_device->bus[0] != '\0')
                                goto bus_found;
                }
-               dbg("Timed out waiting to find the device bus, continuing on anyway\n");
+               dbg("timed out waiting to find the device bus, continuing on anyway");
                goto exit;
 bus_found:
                goto exit;
 bus_found:
-               dbg("Device %s is registered with bus %s\n",
+               dbg("device %s is registered with bus '%s'",
                                sysfs_device->name, sysfs_device->bus);
        }
 exit:
                                sysfs_device->name, sysfs_device->bus);
        }
 exit:
@@ -694,7 +695,8 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud
                }
 
                /* Yup, this rule belongs to us! */
                }
 
                /* Yup, this rule belongs to us! */
-               dbg("found matching rule, '%s' becomes '%s'", dev->kernel, dev->name);
+               info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
+                   udev_rules_filename, dev->config_line, udev->kernel_name, dev->name);
                strfieldcpy(udev->name, dev->name);
                strfieldcpy(udev->symlink, dev->symlink);
                goto found;
                strfieldcpy(udev->name, dev->name);
                strfieldcpy(udev->symlink, dev->symlink);
                goto found;
index f5b63a8805ee728986dcf609eb203beafaf5e06d..42b1e6c1a0a1cabd4db09d9729bf2e2ab160967f 100644 (file)
--- a/namedev.h
+++ b/namedev.h
@@ -65,6 +65,7 @@ struct config_device {
        char name[NAME_SIZE];
        char symlink[NAME_SIZE];
        struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
        char name[NAME_SIZE];
        char symlink[NAME_SIZE];
        struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
+       int config_line;
 };
 
 struct perm_device {
 };
 
 struct perm_device {
index 0712c3b44769350d268845b2bd858d5588407fa8..a17c02e395d8054d4cd42a25316ca03fb1a8af9d 100644 (file)
@@ -36,6 +36,7 @@
 #include <errno.h>
 
 #include "udev.h"
 #include <errno.h>
 
 #include "udev.h"
+#include "logging.h"
 #include "namedev.h"
 
 static int add_config_dev(struct config_device *new_dev)
 #include "namedev.h"
 
 static int add_config_dev(struct config_device *new_dev)
@@ -249,6 +250,7 @@ int namedev_init_rules(void)
                        goto error;
                }
 
                        goto error;
                }
 
+               dev.config_line = lineno;
                retval = add_config_dev(&dev);
                if (retval) {
                        dbg("add_config_dev returned with error %d", retval);
                retval = add_config_dev(&dev);
                if (retval) {
                        dbg("add_config_dev returned with error %d", retval);
index 802d85b5b07d408fe612b41398b2416abc061a73..9aa8bdb3e91bb113edda18917ceef50a624424d4 100644 (file)
@@ -37,6 +37,7 @@
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
+#include "logging.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
@@ -141,6 +142,7 @@ static int create_node(struct udevice *dev)
        if (strrchr(dev->name, '/'))
                create_path(filename);
 
        if (strrchr(dev->name, '/'))
                create_path(filename);
 
+       info("creating device node '%s'", filename);
        dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
        retval = mknod(filename, dev->mode, res);
        if (retval)
        dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
        retval = mknod(filename, dev->mode, res);
        if (retval)
index c5de6c823fc8d938a2eb35e55c4da22126b588ac..9db63ed93e536111266fcf694d3cdd00aff4e5da 100644 (file)
@@ -31,6 +31,7 @@
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
+#include "logging.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
@@ -73,7 +74,7 @@ static int delete_node(struct udevice *dev)
        strncpy(filename, udev_root, sizeof(filename));
        strncat(filename, dev->name, sizeof(filename));
 
        strncpy(filename, udev_root, sizeof(filename));
        strncat(filename, dev->name, sizeof(filename));
 
-       dbg("unlinking node '%s'", filename);
+       info("removing device node '%s'", filename);
        retval = unlink(filename);
        if (retval) {
                dbg("unlink(%s) failed with error '%s'",
        retval = unlink(filename);
        if (retval) {
                dbg("unlink(%s) failed with error '%s'",
diff --git a/udev.c b/udev.c
index b395be2abb15e362457a875ba4620900295c1ba5..b872f42494e68070e34452e6221dca619fb5e650 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -34,6 +34,7 @@
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
 #include "udev.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
+#include "logging.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
diff --git a/udev.h b/udev.h
index 678731c7d194a0843dfceedf7368b0857262b19f..90aa82393911bafece7d3d9d59ef9882e9214aff 100644 (file)
--- a/udev.h
+++ b/udev.h
 #include "libsysfs/libsysfs.h"
 #include <sys/param.h>
 
 #include "libsysfs/libsysfs.h"
 #include <sys/param.h>
 
-#ifdef DEBUG
-#include <syslog.h>
-#define dbg(format, arg...)                                                            \
-       do {                                                                            \
-               log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg);        \
-       } while (0)
-#else
-       #define dbg(format, arg...) do { } while (0)
-#endif
-
-/* Parser needs it's own debugging statement, we usually don't care about this at all */
-#ifdef DEBUG_PARSER
-#define dbg_parse(format, arg...)                                                      \
-       do {                                                                            \
-               log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg);        \
-       } while (0)
-#else
-       #define dbg_parse(format, arg...) do { } while (0)
-#endif
-
-
-extern int log_message (int level, const char *format, ...)
-       __attribute__ ((format (printf, 2, 3)));
-
 #define COMMENT_CHARACTER              '#'
 
 #define NAME_SIZE      100
 #define COMMENT_CHARACTER              '#'
 
 #define NAME_SIZE      100
@@ -71,7 +47,6 @@ struct udevice {
        unsigned char program_result[NAME_SIZE];
        unsigned char kernel_number[NAME_SIZE];
        unsigned char kernel_name[NAME_SIZE];
        unsigned char program_result[NAME_SIZE];
        unsigned char kernel_number[NAME_SIZE];
        unsigned char kernel_name[NAME_SIZE];
-
 };
 
 #define strfieldcpy(to, from) \
 };
 
 #define strfieldcpy(to, from) \
index 074bd7b35bae53a4a5cd1b7f89e4dac761b46cdf..44b5767b85776893f7db1ef3e9e6b91012474807 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "udev.h"
 #include "udev_version.h"
 
 #include "udev.h"
 #include "udev_version.h"
+#include "logging.h"
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
 
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
 
index 8d077ea94fc766b652cdd0af705210867e23218f..2d99f51d0e4ef819efc0b1638a3910db7b23c092 100644 (file)
--- a/udevdb.c
+++ b/udevdb.c
@@ -35,6 +35,7 @@
 
 #include "udev_version.h"
 #include "udev.h"
 
 #include "udev_version.h"
 #include "udev.h"
+#include "logging.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "tdb/tdb.h"
 #include "namedev.h"
 #include "udevdb.h"
 #include "tdb/tdb.h"