udev cdrom规则无法运行脚本

时间:2017-05-29 21:16:57

标签: udev

以下是/etc/udev/rules.d/10-autodvd.rules中的规则文件

SUBSYSTEM=="block", KERNEL=="sr0", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr0"
SUBSYSTEM=="block", KERNEL=="sr1", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr1"
SUBSYSTEM=="block", KERNEL=="sr2", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr2"
SUBSYSTEM=="block", KERNEL=="sr3", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr3"
SUBSYSTEM=="block", KERNEL=="sr4", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr4"

实际运行脚本似乎真的很受欢迎,有没有更好的方法呢?

1 个答案:

答案 0 :(得分:1)

Udev在词汇上对规则文件进行排序,并且在应用规则时,ID_CDROM_MEDIA_DVD变量可能尚未设置。这是systemd udev的默认安装的情况。 ID_CDROM*变量在60-cdrom_id.rules中设置,因此您应该重命名规则文件以在此之后进行排序。

请注意,您不应该使用RUN + =键启动长时间运行的程序。

   RUN{type}
   [...]
       This can only be used for very short-running
       foreground tasks. Running an event process for
       a long period of time may block all further
       events for this or a dependent device.

       Starting daemons or other long-running
       processes is not appropriate for udev; the
       forked processes, detached or not, will be
       unconditionally killed after the event handling
       has finished.

您的规则可以写成一条规则:

SUBSYSTEM=="block", KERNEL=="sr[0-4]", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh %k"