<div dir="ltr">Afaik, udev only re-emits a uevent once it's done processing all the rules – this part is by design. <span style="font-size:13px">So in your case, while udev worker 1 is still waiting for the RUN to finish, worker 2 receives a kernel uevent for the cryptsetup device and quickly reemits it. (See the output of "udevadm monitor", for example – compare the kernel events and udev events there.)</span></div><span>
</span><p dir="ltr">So personally I'd classify udev rules with side effects as "broken as expected". Avoid recursion, avoid long-running processes, avoid touching X11, and so on.</p><span>
</span><p dir="ltr">If you want to automatically unlock volumes, list them in /etc/crypttab with "auto" and let systemd-cryptsetup handle them. (It works by putting service symlinks in *.device.wants/, so as soon as dev-sda1.device appears, the corresponding "unlock" service is started.)</p><span>
</span><p dir="ltr">If you don't have systemd, well. Maybe tell sh to spawn cryptsetup& "in background" rather than waiting for it...<br>
</p><span>
</span><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 30, 2016, 01:15 Nathaniel McCallum <<a href="mailto:npmccallum@redhat.com">npmccallum@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a rule like this:<br>
<br>
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="crypto_LUKS",<br>
ENV{ID_FS_VERSION}="1", RUN+="sh -c 'echo password | cryptsetup open<br>
$devnode luks-$env{ID_FS_UUID_ENC}'"<br>
<br>
Okay, my real rule isn't so security braindead, but the above will<br>
suffice for concept. :)<br>
<br>
What I find interesting is that the udev events happen backwards in<br>
this case. First, two udev events are generated for the new plaintext<br>
block device and then finally I get the add event for the ciphertext<br>
block device. For instance:<br>
<br>
import pyudev<br>
<br>
context = pyudev.Context()<br>
monitor = pyudev.Monitor.from_netlink(context)<br>
monitor.filter_by('block')<br>
<br>
for dev in iter(monitor.poll, None):<br>
  print dev<br>
...<br>
Device(u'/sys/devices/virtual/block/dm-0')<br>
Device(u'/sys/devices/virtual/block/dm-0')<br>
Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-<br>
1.3:1.0/host52/target52:0:0/52:0:0:0/block/sdc')<br>
<br>
None of the services listening for block events seem to cope well with<br>
this. They all anticipate that sdc will appear first, and then dm-0.<br>
<br>
Is this simply as designed? Is this a bug? Undefined behavior?<br>
<br>
And, most importantly, is there a better way to do what I'm trying to<br>
do? I'd like to avoid running my own daemon if possible.<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</blockquote></div>