udev-ish replacement for hal-cups-utils?

Martin Pitt martin.pitt at ubuntu.com
Tue Jul 14 00:24:10 PDT 2009


Hello all,

Tim Waugh [2009-07-13 21:40 +0100]:
> To recap on why this data needs to be stored: we need the device ID,
> obtained from the device at connection time, at the point where the
> device has already been disconnected.  This is so we can match it to the
> existing CUPS queue by constructing a device URI and comparing with
> those of the existing queues.
> 
> Looks like I'll need to investigate Martin's suggestion of using
> IMPORT{program} then.

I think it's much easier than that. You can exploit the fact that
device properties ($ENV{}) are still available at a removal event
(unlike the sysfs attributes). Try this:

------------------ 8< -----------------------
$ cat /etc/udev/rules.d/printer.rules
ACTION=="add", KERNEL=="lp*", ATTRS{ieee1284_id}=="?*", ENV{ID_IEEE1284}="$attr{ieee1284_id}", RUN+="/bin/sh -c 'echo add $attr{ieee1284_id} >> /tmp/printer.log'"

ACTION=="remove", ENV{ID_IEEE1284}=="?*", RUN+="/bin/sh -c 'echo remove $env{ID_IEEE1284} >> /tmp/printer.log'"
------------------ 8< -----------------------

Turn on printer, then turn it off again.

$ cat /tmp/printer.log 
add MFG:Samsung_CMD:GDI_MDL:ML-1610_CLS:PRINTER_MODE:GDI_STATUS:IDLE_
remove MFG:Samsung_CMD:GDI_MDL:ML-1610_CLS:PRINTER_MODE:GDI_STATUS:IDLE_

The "add" udev rule watches out for new "lp..." kernel devices (which are an
interface of the USB device) and grabs the device id from the parent
with ATTRS. Then we save the ieee1284_id attribute into an ID_IEEE1284
property (which is stored in udev's DB, and thus doesn't immediately
go away on device removal).

The "remove" rule can then just test if a device with the ID_IEEE1284
was removed, and still use that property value in the RUN argument.

For the real implementation you would of course replace RUN with
something like "printer_setup add '$env{ID_IEEE1284}' '%p'". printer_setup must
be in /lib/udev/, or specify the full path; %p is the device node path
(like /dev/usb/lp0).

Please let me know if you have any further questions.

Thanks,

Martin

-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/devkit-devel/attachments/20090714/4c51e2c9/attachment.pgp 


More information about the devkit-devel mailing list