Re: [sane-devel] Calling a script after USB scanner is plugged

2008-04-25 Thread Johannes Meixner

Hello,

On Apr 24 22:45 Julien BLACHE wrote (shortened):
> udev is an incredible piece of crap, but the good news is that this
> piece of crap is mostly stable those days. Which is a big step forward
> already.
> 
> (and I'll refrain from saying anything at all about the genius who
> invented udev. I'll just mention that he's also the author of "stable
> API is a nonsense".)

There he makes it very clear that
"The kernel to userspace interface is the one that
 application programs use, the syscall interface.
 That interface is _very_ stable over time,
 and will not break."

But this is in "stark contrast" to the interface of udev
(i.e. the syntax and keywords how to specify udev rules)
for applications (e.g. SANE) which provide udev rules
and for a normal user udev is completely unusable.

It seems one must talk to udev in terms of internal kernel
values (e.g. internal kernel event names and so on) instead of
a more abstract and therefore more stable higher level language.

Actually I am not interested in any internal kernel stuff.
I just like to tell udev:
"When a USB device with ID 0x1a2b:0x3c4d appears
 and when it is not already configured,
 then run my setup program and if my setup program
 exits successfully, remember the device and that
 it is already configured (even after a reboot)."

Of course it cannot work when only "my setup program"
remembers which devices it has already configured
because the user might have used another setup program
before (or did the setup manually). Therefore the
information whether or not it is already configured
must be kept at a unique central place.

Of course this requires persistent storage to keep
the device state even after a reboot and I just need
this for a well working plug-and-play user experience
but I guess the kernel people do not want to do this
for whatever internal kernel reason but again I am
actually not interested in any internal kernel stuff.
Here I am an end-user and I just want to have it work.


Kind Regards
Johannes Meixner
-- 
SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
AG Nuernberg, HRB 16746, GF: Markus Rex


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: [sane-devel] Calling a script after USB scanner is plugged

2008-04-24 Thread Johannes Meixner

Hello,

On Apr 23 22:53 Rainer Dorsch wrote:
> Am Mittwoch, 23. April 2008 schrieb Julien BLACHE:
> > Johannes Meixner <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > >> umax1220u scripts are started in a sequence (i.e. not in parallel, when
> > >> one is completed the next one starts).
> >
> > When troubleshooting udev rules, use udevmonitor to actually see
> > what's happening in terms of udev events and their properties.
> >
> 
> That was a very good hint, thanks. A single scanimage -L causes these events:
> 
> UEVENT[1208979136.171525] remove   /class/usb_endpoint/usbdev1.5_ep01 
> (usb_endpoint)
> UEVENT[1208979136.171696] remove   /class/usb_endpoint/usbdev1.5_ep82 
> (usb_endpoint)
> UEVENT[1208979136.171702] remove   /class/usb_endpoint/usbdev1.5_ep83 
> (usb_endpoint)
> UEVENT[1208979136.171707] add  /class/usb_endpoint/usbdev1.5_ep01 
> (usb_endpoint)
> UEVENT[1208979136.171712] add  /class/usb_endpoint/usbdev1.5_ep82 
> (usb_endpoint)
> UEVENT[1208979136.171717] add  /class/usb_endpoint/usbdev1.5_ep83 
> (usb_endpoint)
> UDEV  [1208979136.172276] remove   /class/usb_endpoint/usbdev1.5_ep01 
> (usb_endpoint)
> UDEV  [1208979136.172803] remove   /class/usb_endpoint/usbdev1.5_ep82 
> (usb_endpoint)
> UDEV  [1208979136.173239] remove   /class/usb_endpoint/usbdev1.5_ep83 
> (usb_endpoint)
> UDEV  [1208979136.174020] add  /class/usb_endpoint/usbdev1.5_ep01 
> (usb_endpoint)
> UDEV  [1208979136.174831] add  /class/usb_endpoint/usbdev1.5_ep82 
> (usb_endpoint)
> UDEV  [1208979136.175619] add  /class/usb_endpoint/usbdev1.5_ep83 
> (usb_endpoint)

I wonder how "scanimage -L" causes any add or remove event at all.
I cannot imagine that those add or remove events are the
same add or remove events which happen when the device
is plugged-in at the USB or plugged-off from the USB.

Do you know what those different usb_endpoints are?
Perhaps the different USB interfaces for the one USB device?

I wonder how one could specify a udev rule which matches
to the one "add" event for the one USB device instead of
whatever bulk of "add" events for whatever stuff which
is related to the one USB device.


> > > ACTION!="add", GOTO="end"
> > > SYSFS{idVendor}=="04b8", SYSFS{idProduct}=="010b", RUN+="..."
> > > LABEL="end"
> >
> > Be careful with the labels you use. Always use a unique label name, or
> > you're asking for troubles. (been there, done that, accidentally
> > rendered a number of systems unbootable due to that ...)

Many thanks for this enlightening info!
Impressive: A thoroughly thought out fail-safe design!

Actually - just because of a queasy feeling - I used
ACTION!="add", GOTO="sane_backends_autoconfig_rules_end"

Of course "man udev" does not mention that all labels
in all udev rules files must be unique.

I can only guess that what udev actually does is to
concatenate all udev rules files into one single set
of rules and then it is not surprising when arbitrary
nonsense happens depending on which individual udev rules
files exist on a particular system which depends on which
individual software packages are installed on this system.

Very nice to debug!
Very easy to help others!
Makes all users very happy of course - or so they say.

 
> I tried that before after I saw the z60_libsane.rules
> 
> ACTION!="add", GOTO="post_lamp_off"
> SYSFS{idVendor}=="1606", SYSFS{idProduct}=="0010", MODE="0664", 
> GROUP="scanner", NAME="umax%n", RUN+="/usr/local/bin/umax1220u start", 
> ENV{lamp_off}="yes"
> LABEL="post_lamp_off"
> 
> But given the events, it is obvious not surprising that this is not working.
> 
> > > Welcome in the hell of udev, HAL and whatever else sophisticated
> > > stuff which is required to make users happy or so they say...
> >
> > 
> 
> I added now in my script a file system lock:
> 
> if [ ! -e /tmp/umax1220u-plugged ]; then
> 
>   touch /tmp/umax1220u-plugged
> 
> Is anybody aware of a more elegant solution for this problem?

You cannot have "udev" and "elegant" at the same time
and you cannot have "HAL" and "elegant" at the same time.

Just do whatever dirty hack fits at the moment for you
and be prepared that next version is sufficiently different
so that your stuff does no longer work.
Then just do whatever other dirty hack and so on ad nauseam
which makes you happy of course or so they say...


Kind Regards
Johannes Meixner
-- 
SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
AG Nuernberg, HRB 16746, GF: Markus Rex


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: [sane-devel] Calling a script after USB scanner is plugged

2008-04-23 Thread Johannes Meixner

Hello,

On Apr 22 22:18 Rainer Dorsch wrote (shortened):
> I want to call a script after I plugged my USB scanner. I use udev for this 
> by 
> adding a rule
...
> SYSFS{idVendor}=="1606", SYSFS{idProduct}=="0010", MODE="0664", 
> GROUP="scanner", NAME="umax%n", RUN+="/usr/local/bin/umax1220u start", 
...
> When I plug my scanner with this config, it seems an infinite number of 
> umax1220u scripts are started in a sequence (i.e. not in parallel, when one 
> is completed the next one starts).

It seems you need a test if ACTION!="add", i.e. a rule like

ACTION!="add", GOTO="end"
SYSFS{idVendor}=="1606", SYSFS{idProduct}=="0010", ... RUN+="..."
LABEL="end"


I had a similar issue but I got it run only about 5 times
with a rule like

ACTION!="add", GOTO="end"
SYSFS{idVendor}=="04b8", SYSFS{idProduct}=="010b", RUN+="..."
LABEL="end"

Fortunately in my case what is run is idempotent so that
it doesn't matter when it is run about 5 times.
I don't know the root cause, I guess it is the usual udev crap.

Welcome in the hell of udev, HAL and whatever else sophisticated
stuff which is required to make users happy or so they say...


Kind Regards
Johannes Meixner
-- 
SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
AG Nuernberg, HRB 16746, GF: Markus Rex


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]