logoalt Hacker News

jofla_netyesterday at 6:54 PM3 repliesview on HN

this is great thanks,

was just wondering, could something else remove the dir in between the if and then, before trap?

Just wondering about the atomicity.


Replies

chasilyesterday at 7:23 PM

The permissions on the parent and lock directory could restrict the access to a specific user and group, but yes, other processes could interfere with this locking if directed to do so.

One condition where this interference is helpful is a crash, where a @reboot entry in the crontab could:

  [ -d /your/lockdir ] && rmdir /your/lockdir
You would also not want to place the lock directory in /tmp or otherwise where other users could manipulate (or see) it. In Red Hat, there is a /var/run/lock directory that might be appropriate.

My biggest use case for directory locking in scripts is handling inotify events.

cryptonectoryesterday at 9:30 PM

The problem with lock files and lock directories is that if the lock holder dies without cleaning up you now need to do something to clean up.

show 1 reply
formerly_provenyesterday at 7:09 PM

Yes, but that is not a weakness in the locking.