hotplug/Linux: close lockfd after lock attempt
authorOlaf Hering <olaf@aepfle.de>
Thu, 18 Oct 2012 08:35:01 +0000 (09:35 +0100)
committerOlaf Hering <olaf@aepfle.de>
Thu, 18 Oct 2012 08:35:01 +0000 (09:35 +0100)
When a HVM guest is shutdown some of the 'remove' events can not claim
the lock for some reason. Instead they try to grab the lock in a busy
loop, until udev reaps the xen-hotplug-cleanup helper.
After analyzing the resulting logfile its not obvious what the cause is.
The only explanation is that bash (?) gets confused if the same lockfd
is opened again and again. Closing it in each iteration seem to fix the
issue.

This was observed with sles11sp2 (bash 3.2) and 4.2 xend.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Campbell <Ian.campbell@citrix.com>
[ ijc -- added the comment ]
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/hotplug/Linux/locking.sh

index 0e2a531cb3e34ce0b67924c254b74d8e864d9f1a..e34f155438ae9c1fdf97bd0d0beef5b5f049ca57 100644 (file)
@@ -59,6 +59,9 @@ claim_lock()
             print "y\n" if $fd_inum eq $file_inum;
                              ' "$_lockfile" )
         if [ x$rightfile = xy ]; then break; fi
+       # Some versions of bash appear to be buggy if the same
+       # $_lockfile is opened repeatedly. Close the current fd here.
+        eval "exec $_lockfd<&-"
     done
 }