Ferk / udev-media-automount

A simple automount mechanism using udev rules
Other
121 stars 59 forks source link

fix: race condition between cleanup and mounting #24

Closed patrislav1 closed 3 months ago

patrislav1 commented 7 months ago

There's a race condition between the cleanup step (i.e. removing old/unused mountpoints with rmdir) and the mount step. Since udev launches multiple instances of the script in parallel, it's possible that one instance tries to mount a device just after another instance has deleted the associated mountpoint. (This is not a theoretical scenario, I had this actually happen on a system booting with multiple SD cards attached).

This patch fixes the race condition with a lock in /var/run, making the script execution sequential.

patrislav1 commented 7 months ago

BTW. this also affects the duplicate label detection:

Before patch

/dev/mmcblk0p1 on /media/boot.vfat type vfat (rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0111,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro)
/dev/mmcblk1p1 on /media/boot.vfat type vfat (rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0111,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro)

After patch

/dev/mmcblk0p1 on /media/boot.vfat type vfat (rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0111,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro)
/dev/mmcblk1p1 on /media/boot.vfat_1 type vfat (rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0111,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro)