Re: [systemd-devel] Using udev to notify application of device insertion/removal

2018-07-13 Thread Lennart Poettering
On Mo, 02.07.18 13:34, Paul D. DeRocco (pdero...@ix.netcom.com) wrote:

> System: Yocto-based RT Linux 4.10.17, systemd 232, 32-bit x86, no GUI.
> 
> I've created the following "midiUSB.rules" file:
> 
> ACTION=="add", KERNEL=="midiC*", SUBSYSTEM=="sound",
> SYMLINK+="snd/midi%b", RUN="/bin/touch /media/sda1/share/devchg"
> ACTION=="remove", KERNEL=="midiC*", SUBSYSTEM=="sound", RUN="/bin/touch
> /media/sda1/share/devchg"

This suggests the file you touch is located on removable media, which
makes me immediately wonder if maybe you are simply in some race,
where the removable media is not mounted at the time the touch runs.

Also, do note that systemd-udevd.service runs in its own mount
namespace, and mount propagation is somewhat limited.
> So it looks like it believes it's going to run my touch command when it's
> removed, but when I actually do it, I don't see the timestamp change.
> 
> Any ideas on what's wrong, or how to debug this further?

Run "strace -p1 -f -s500" on udevd, and look for the touch command
being execve()'ed anywhere.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Using udev to notify application of device insertion/removal

2018-07-02 Thread Paul D. DeRocco
System: Yocto-based RT Linux 4.10.17, systemd 232, 32-bit x86, no GUI.

I've created the following "midiUSB.rules" file:

ACTION=="add", KERNEL=="midiC*", SUBSYSTEM=="sound",
SYMLINK+="snd/midi%b", RUN="/bin/touch /media/sda1/share/devchg"
ACTION=="remove", KERNEL=="midiC*", SUBSYSTEM=="sound", RUN="/bin/touch
/media/sda1/share/devchg"

(pardon the spurious email line breaks)

When I plug in a MIDI device, this gives me a device path like
"/dev/snd/midi1-8.3:1.0" based on what USB port I plugged it into, in
addition to the usual "/dev/snd/midiC1D0". When I unplug it, both names go
away. Perfect.

What's the "touch" command for? My "application" firmware needs to be
notified of any such change. It's already using an inotify to monitor that
directory for other reasons, so having it bump the timestamp on a dummy
file allows me to detect the change with one added line of code in my app.

The problem is, it's touching the timestamp when I insert the device, but
not when I remove it.

I used "udevadmin monitor", and got this (among other events) for the
insertion:

KERNEL[6175.279426] add
/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/card1/midi
C1D0 (sound)
ACTION=add
DEVNAME=/dev/snd/midiC1D0
DEVPATH=/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/ca
rd1/midiC1D0
MAJOR=116
MINOR=40
SEQNUM=1781
SUBSYSTEM=sound

and this for the removal:

KERNEL[6181.373765] remove
/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/card1/midi
C1D0 (sound)
ACTION=remove
DEVNAME=/dev/snd/midiC1D0
DEVPATH=/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/ca
rd1/midiC1D0
MAJOR=116
MINOR=40
SEQNUM=1784
SUBSYSTEM=sound

Looks okay, right? I used "udevadmin test" with the DEVPATH shown above,
and (after stripping all the boilerplate) I got this for the insertion:

GROUP 29 /lib/udev/rules.d/50-udev-default.rules:39
LINK 'snd/midi' /etc/udev/rules.d/midiUSB.rules:1
RUN '/bin/touch /media/sda1/share/devchg'
/etc/udev/rules.d/midiUSB.rules:1
handling device node '/dev/snd/midiC1D0', devnum=c116:40, mode=0660,
uid=0, gid=29
preserve permissions /dev/snd/midiC1D0, 020660, uid=0, gid=29
preserve already existing symlink '/dev/char/116:40' to '../snd/midiC1D0'
found 'c116:40' claiming '/run/udev/links/\x2fsnd\x2fmidi'
creating link '/dev/snd/midi' to '/dev/snd/midiC1D0'
preserve already existing symlink '/dev/snd/midi' to 'midiC1D0'
created db file '/run/udev/data/c116:40' for
'/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/card1/mid
iC1D0'
ACTION=add
DEVLINKS=/dev/snd/midi
DEVNAME=/dev/snd/midiC1D0
DEVPATH=/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/ca
rd1/midiC1D0
MAJOR=116
MINOR=40
SUBSYSTEM=sound
USEC_INITIALIZED=4019498530
run: '/bin/touch /media/sda1/share/devchg'
Unload module index
Unloaded link configuration context.

and this for the removal:

RUN '/bin/touch /media/sda1/share/devchg'
/etc/udev/rules.d/midiUSB.rules:2
no reference left, remove '/dev/snd/midi'
ACTION=remove
DEVLINKS=/dev/snd/midi
DEVNAME=/dev/snd/midiC1D0
DEVPATH=/devices/pci:00/:00:1d.7/usb1/1-8/1-8.3/1-8.3:1.0/sound/ca
rd1/midiC1D0
MAJOR=116
MINOR=40
SUBSYSTEM=sound
USEC_INITIALIZED=4019498530
run: '/bin/touch /media/sda1/share/devchg'
Unload module index
Unloaded link configuration context.

So it looks like it believes it's going to run my touch command when it's
removed, but when I actually do it, I don't see the timestamp change.

Any ideas on what's wrong, or how to debug this further?

-- 

Ciao,   Paul D. DeRocco
Paulmailto:pdero...@ix.netcom.com

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel