[Pm-utils] lockfile creation not really atomic in pm-utils

Till Maas opensource at till.name
Fri Jan 4 13:40:12 PST 2008


On Fr Januar 4 2008, Victor Lowther wrote:
> While browsing through the source of pm-utils, I noticed that the
> lock/unlocking functions were using file creation/removal and PID
> checking for locking purposes.  In a shell scripting language,
> however, there is no way to atomically create files.
>
> Directory creation, however, is atomic.  Here is a patch to atomicize
> the lock/unlick functions.

You are so cool, there is a bug about this in Red Hat Bugzilla for Fedora and 
I did not know how to fix it. You seem to be the man. But there is one 
problem with your patch left, though. Now a stale lock directory is not 
removed, e.g. when it was left because a suspend failed and one needed to 
reset the computer. Do you know the best solution for this, too?

I guess adding a second lock directory may help here:

mkdir /.suspended
- on success: continue, store PID in /.suspended/pid
- on failure:
mkdir /.suspended/cleanup
- on failure: quit
- on sucess: check pid in /.suspended/pid
     - process still running: remove /.suspended/cleanup and quit
     - else: store own pid in /.suspended/pid
       remove /.suspended/cleanup
       continue

Regards,
Till
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20080104/3d589c41/attachment.pgp 


More information about the Pm-utils mailing list