udev is your friend

I was solving yet another problem with deployment where we replace a printer with one interface (a parallel port /dev/lp0) with the same printer with a different interface (a usb port /dev/usb/lp0). Our junior programmer solved this ultimately, however udev worked perfectly for this. I wanted the /dev to automatically switch back and forth between the printers while cups pointed to one /dev. This allows one to have a static /etc/cups/printers.conf yet dynamically react to these printer changes.
Please note that since its the same printer, and we won’t have two of them at the same time, one wants the user to not notice that a configuration change was necessary.
The rule in udev was:
KERNEL==”lp0″, SYMLINK+=”lblprinter”
and for the usb
SUBSYSTEM==”usb”, (printer id here), SYMLINK+=”lblprinter”
What our programmer found was that the lp0 symlink would NOT be created (called TRIGGERED) until some event occurs with /dev/lp0. Interestingly odd since the normal “device is detected” triggers the rules in udev.
To solve this we put “touch /dev/lp0″ into the SUSE 11 /etc/initscript and poof when it boots it creates the symlink. This is the desired behaviour.
What is cool, is that I plugged the usb printer in, the /dev/lblprinter symlinked to /dev/usb/lp0. It worked fine. Then when I unplugged the usb printer, the original symlink appeared.
Waycooool. Life is good.
-T-

  • Share/Bookmark
This entry was posted in Miscellaneous Apps and Services and tagged , , , , , . Bookmark the permalink.

2 Responses to udev is your friend

  1. John Boukis says:

    Is not Udev one of Sadam Hussein’s kids? I am not so sure he is my friend.

  2. Tom CTO says:

    No, that was some other obscure name, but I give you props for being close.
    -T-

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>