chiark / gitweb /
[PATCH] udev_dbus changes
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 13 Apr 2004 08:21:46 +0000 (01:21 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:35:15 +0000 (21:35 -0700)
On Sun, Apr 11, 2004 at 03:51:07AM +0200, Kay Sievers wrote:
> Here we change extras/dbus/* to
>   o install the binary in /etc/dev.d
>   o append .dev to the binary
>   o add David's copyright
>   o add the listener script to watch the sent dbus messages
>   o removed the undefined udev_log variable
>   o switch printf() to dbg()

Here we install the binary in /usr/sbin/ and symlink it to
/etc/dev.d/ with the .dev suffix.

extras/dbus/Makefile
extras/dbus/dbus-listen-test.py [new file with mode: 0644]
extras/dbus/udev_dbus.c

index 99aa33d8fb7cc6710058815d7ebcd9f22892463b..04f17605e890b07033988fd895ce435367fb99e3 100644 (file)
@@ -22,8 +22,9 @@ exec_prefix = ${prefix}
 etcdir =       ${prefix}/etc
 sbindir =      ${exec_prefix}/sbin
 usrbindir =    ${exec_prefix}/usr/bin
+usrsbindir =   ${exec_prefix}/usr/sbin
 mandir =       ${prefix}/usr/share/man
-hotplugdir =   ${etcdir}/hotplug.d/default
+devddir =      ${etcdir}/dev.d/default
 dbusdir =      ${etcdir}/dbus-1/system.d
 configdir =    ${etcdir}/udev/
 initdir =      ${etcdir}/init.d/
@@ -53,9 +54,13 @@ spotless: clean
 install-dbus-policy:
        $(INSTALL) -d $(DESTDIR)$(dbusdir)
        $(INSTALL_DATA) etc/dbus-1/system.d/udev_sysbus_policy.conf $(DESTDIR)$(dbusdir)
+       $(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(usrsbindir)/$(PROG)
+       - ln -s -f $(DESTDIR)$(usrsbindir)/$(PROG) $(DESTDIR)$(devddir)/$(PROG).dev
 
 uninstall-dbus-policy:
        - rm $(DESTDIR)$(dbusdir)/udev_sysbus_policy.conf
+       - rm $(DESTDIR)$(devddir)/$(PROG).dev
+       - rm $(DESTDIR)$(usrsbindir)/$(PROG)
 
 install: install-dbus-policy all
 
diff --git a/extras/dbus/dbus-listen-test.py b/extras/dbus/dbus-listen-test.py
new file mode 100644 (file)
index 0000000..6a68b5d
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+# receives and prints the messages udev_dbus sent
+# to the org.kernel.udev.NodeMonitor interface
+
+import dbus
+import gtk
+
+def udev_signal_received(dbus_iface, member, service, object_path, message):
+       [filename, sysfs_path] = message.get_args_list()
+       if member=='NodeCreated':
+               print 'Node %s created for %s'%(filename, sysfs_path)
+       elif member=='NodeDeleted':
+               print 'Node %s deleted for %s'%(filename, sysfs_path)
+
+def main():
+       bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
+       bus.add_signal_receiver(udev_signal_received,
+               'org.kernel.udev.NodeMonitor',          # interface
+               'org.kernel.udev',                      # service
+               '/org/kernel/udev/NodeMonitor')         # object
+       gtk.mainloop()
+
+if __name__ == '__main__':
+       main()
+
index e99e92ec8715faedcd3bf4d528cd932aaf5c9c74..4852d429f81751d9f962ee2d2744d90aa8352cf1 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * udev_dbus.c
+ *
+ * Copyright (C) 2003 David Zeuthen <david@fubar.dk>
+ *
+ *     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.
+ *
+ */
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -18,21 +38,18 @@ void log_message(int level, const char *format, ...)
 {
        va_list args;
 
-       if (!udev_log)
-               return;
-
        va_start(args, format);
        vsyslog(level, format, args);
        va_end(args);
 }
 #endif
 
-/** variable for the connection the to system message bus or #NULL
+/*  Variable for the connection the to system message bus or NULL
  *  if we cannot connect or acquire the org.kernel.udev service
  */
 static DBusConnection* sysbus_connection;
 
-/** Disconnect from the system message bus */
+/* Disconnect from the system message bus */
 static void sysbus_disconnect(void)
 {
        if (sysbus_connection == NULL)
@@ -42,7 +59,7 @@ static void sysbus_disconnect(void)
        sysbus_connection = NULL;
 }
 
-/** Connect to the system message bus */
+/* Connect to the system message bus */
 static void sysbus_connect(void)
 {
        DBusError error;
@@ -70,18 +87,18 @@ static void sysbus_connect(void)
        dbus_bus_acquire_service(sysbus_connection, "org.kernel.udev", 0, 
                                 &error);
        if (dbus_error_is_set(&error)) {
-               printf("cannot acquire org.kernel.udev service, error %s: %s'",
-                      error.name, error.message);
+               dbg("cannot acquire org.kernel.udev service, error %s: %s'",
+                   error.name, error.message);
                sysbus_disconnect();
                return;
        }
 }
 
 
-/** Send out a signal that a device node is created
+/*  Send out a signal that a device node is created
  *
- *  @param  devname             name of the device node, e.g. /dev/sda1
- *  @param  path                Sysfs path of device
+ *  @param  devname            Name of the device node, e.g. /dev/sda1
+ *  @param  path               Sysfs path of device
  */
 static void sysbus_send_create(const char *devname, const char *path)
 {
@@ -105,10 +122,10 @@ static void sysbus_send_create(const char *devname, const char *path)
        dbus_connection_flush(sysbus_connection);
 }
 
-/** Send out a signal that a device node is deleted
+/*  Send out a signal that a device node is deleted
  *
- *  @param  devname             Name of the device node, e.g. /udev/sda1
- *  @param  path                Sysfs path of device
+ *  @param  devname            Name of the device node, e.g. /udev/sda1
+ *  @param  path               Sysfs path of device
  */
 static void sysbus_send_remove(const char *devname, const char *path)
 {