Skip to contentSkip to conversation

tools/hotplug/Linux: forced to release lock if holder process is gone

PATCH Applied Kouya Shimura 2 participants 4 messages Dec 14, 2010 – Dec 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/hotplug/Linux: forced to release lock if holder process is gone

When a script using locking.sh is stopped by ctrl-C, the lock file remains. We have to wait 100 seconds for releasing the lock at the next time.

tools/hotplug/Linux/locking.sh +6 -0
diff -r 89116f28083f tools/hotplug/Linux/locking.sh
@@ -61,6 +61,12 @@ _claim_lock()
     then
       owner="$new_owner"
       retries=0
+    else
+      local pid=$(echo $owner | cut -d : -f 1)
+      if [ ! -f "/proc/$pid/status" ]
+      then
+        _release_lock $lockdir
+      fi
     fi
 
     if [ $retries -gt $LOCK_SPINNING_RETRIES ]

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Kouya Shimura writes ("[Xen-devel] [PATCH] tools/hotplug/Linux: forced to release lock if holder process is gone"):

Quoted 2 lines

When a script using locking.sh is stopped by ctrl-C, the lock file remains. We have to wait 100 seconds for releasing the lock at the next time.

Thanks, I have applied your patch.

This kind of thing is one reason why lockfiles where the lock is regarded as held if the file exists are horrible. It's a shame that we don't have any fcntl/flock style locking primitives available in shell.

Ian.

#2 lore raw

Sorry, the patch was unsafe for mutual exclusion. Please apply this too. Since there is a case that the owner file doesn't exist yet when an atomic mkdir operation fails.

Thanks,
Kouya

Quoted 4 lines · Ian Jackson

Kouya Shimura writes ("[Xen-devel] [PATCH] tools/hotplug/Linux: forced to release lock if holder process is gone"):

Quoted 2 lines

When a script using locking.sh is stopped by ctrl-C, the lock file remains. We have to wait 100 seconds for releasing the lock at the next time.

Quoted 8 lines

Thanks, I have applied your patch.

This kind of thing is one reason why lockfiles where the lock is regarded as held if the file exists are horrible. It's a shame that we don't have any fcntl/flock style locking primitives available in shell.

Ian.

tools/hotplug/Linux/locking.sh +1 -1
diff -r 197c0b40423a tools/hotplug/Linux/locking.sh
@@ -63,7 +63,7 @@ _claim_lock()
       retries=0
     else
       local pid=$(echo $owner | cut -d : -f 1)
-      if [ ! -f "/proc/$pid/status" ]
+      if [ -n "$pid" -a "$pid" != "unknown" -a ! -f "/proc/$pid/status" ]
       then
         _release_lock $lockdir
       fi

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Applied
#3 lore raw

Kouya Shimura writes ("Re: [Xen-devel] [PATCH] tools/hotplug/Linux: forced to release lock if holder process is gone"):

Quoted 3 lines

Sorry, the patch was unsafe for mutual exclusion. Please apply this too. Since there is a case that the owner file doesn't exist yet when an atomic mkdir operation fails.

Applied, thanks.

Ian.