Welcome to the Linux Foundation Forum!

How to monitor the USB ports of an old IBM T41?

Hello everyone!

Besides my Macbook I got this old IBM T41 with Ubuntu 10.04 installed on it.

Currently, I'm working on developing a device driver for Ubuntu that'll monitor the USB ports of the computer, and report when a device has either been inserted or removed from either of the ports.

I have entirely read this tutorial: http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,0, but that's about as much experience I got with device drivers. - I'm not completely new to working in this ring level though, as I have already developed my own little GUI toy OS.

Best regards,

Benjamin :cheer: .


  • mfillpot
    mfillpot Posts: 2,177
    It sounds like you are attempting to create a kernel space product like dbus (http://www.freedesktop.org/wiki/Software/dbus#ReferenceImplementation.28dbus-daemonandlibdbus.29), a quick tutorial to using dbus is at http://tuxpool.blogspot.com/2010/04/dbus-tutorial-part-1.html

    I would recommend reading the documentation and source code from the latest implementation of dbus and seeing how it speaks to the kernel so you can built a kernel based implementation.
  • Hello!
    I'm sorry for the long wait, but I just haven't had a chance to do any programming lately, but now I'm back at it again.
    I really appreciate your link to DBus, and I've chosen to go the Python way (at least for a first try, as the DBus API for Python seems to be the most well documented, and the best for beginners).
    Right now my only problem is that my program seem to exit immediately after I execute it.
    This is what I did:
    First I just did a "sudo apt-get install ..." on the following packages:
    And they all seem to "install" correctly.
    The sourcecode is as follows:
    import dbus
    from dbus.mainloop.glib import DBusGMainLoop
    dbus_loop = DBusGMainLoop()
    bus = dbus.SystemBus(mainloop=dbus_loop)
    def device_added_callback(udi):
        print "added"
    def device_removed_callback(udi):
        print "removed"
    When I save it and go: "python main.py" in the Terminal, the program terminate like 1 second after I press enter.
    It's probably something with the code, or so I hope, so it's a little easier to get out of :).

    Best regards,
  • Nevermind. I got it working. I just did a few code modifications and moved around a few things.
    This is the new (and working) code:
    import dbus
    import gobject
    from dbus.mainloop.glib import DBusGMainLoop
    bus = dbus.SystemBus()
    def device_added(udi):
        print "added"
    def device_removed(udi):
        print "removed"
    bus.add_signal_receiver(device_added, "DeviceAdded", "org.freedesktop.Hal.Manager", "org.freedesktop.Hal",
    bus.add_signal_receiver(device_removed, "DeviceRemoved", "org.freedesktop.Hal.Manager", "org.freedesktop.Hal",
    loop = gobject.MainLoop()


Upcoming Training