chiark / gitweb /
rules: clean up stale CD drive mounts after ejection
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 28 Jan 2015 12:57:47 +0000 (13:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 16:04:06 +0000 (17:04 +0100)
Ejecting a CD with the hardware drive button only causes a change uevent, but
the device node stays around (just without a medium). Pick up these uevents and
mark the device as SYSTEMD_READY=0 on ejection, so that systemd stops the
device unit and consequently all mount units on it.

On media insertion, mark the device as SYSTEMD_READY=1 again.

https://bugs.freedesktop.org/show_bug.cgi?id=72206
https://bugzilla.opensuse.org/show_bug.cgi?id=909418
https://bugs.archlinux.org/task/42071
https://bugs.launchpad.net/bugs/1168742

rules/60-cdrom_id.rules

index 6eaf76a72cde4dca2df08485376898d3cb4fb4cc..5c3b52ebb9eebfd1e1e174bf5d9bb912c4592dcd 100644 (file)
@@ -15,6 +15,11 @@ ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdr
 # enable the receiving of media eject button events
 IMPORT{program}="cdrom_id --lock-media $devnode"
 
+# ejecting a CD does not remove the device node, so mark the systemd device
+# unit as inactive while there is no medium; this automatically cleans up of
+# stale mounts after ejecting
+ENV{DISK_MEDIA_CHANGE}=="?*", ENV{ID_CDROM_MEDIA}!="?*", ENV{SYSTEMD_READY}="0"
+
 KERNEL=="sr0", SYMLINK+="cdrom", OPTIONS+="link_priority=-100"
 
 LABEL="cdrom_end"