[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] scripts: don't rely on "stat -" support



commit d3688bf60f798074bf38d712a3e15c88cfb81ed4
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Jun 25 17:16:02 2020 +0200
Commit:     Wei Liu <wl@xxxxxxx>
CommitDate: Fri Jun 26 10:08:05 2020 +0000

    scripts: don't rely on "stat -" support
    
    While commit b72682c602b8 ("scripts: Use stat to check lock claim")
    validly indicates that stat has gained support for the special "-"
    command line option in 2009, we should still try to avoid breaking being
    able to run on even older distros. As it has been determined, contary to
    the comment in the script using /dev/stdin (/proc/self/fd/$_lockfd) is
    fine here, as Linux specially treats these /proc inodes.
    
    Suggested-by: Ian Jackson <ian.jackson@xxxxxxxxxx>
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
    Tested-by: Jason Andryuk <jandryuk@xxxxxxxxx>
    Reviewed-by: Jason Andryuk <jandryuk@xxxxxxxxx>
    Release-acked-by: Paul Durrant <paul@xxxxxxx>
---
 tools/hotplug/Linux/locking.sh | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh
index 69aefae6f6..2e6fb35f02 100644
--- a/tools/hotplug/Linux/locking.sh
+++ b/tools/hotplug/Linux/locking.sh
@@ -45,18 +45,14 @@ claim_lock()
     while true; do
         eval "exec $_lockfd<>$_lockfile"
         flock -x $_lockfd || return $?
-        # We can't just stat /dev/stdin or /proc/self/fd/$_lockfd or
-        # use bash's test -ef because those all go through what is
-        # actually a synthetic symlink in /proc and we aren't
-        # guaranteed that our stat(2) won't lose the race with an
-        # rm(1) between reading the synthetic link and traversing the
-        # file system to find the inum.  stat(1) translates '-' into an
-        # fstat(2) of FD 0.  So we just need to arrange the FDs properly
-        # to get the fstat(2) we need.  stat will output two lines like:
+        # Although /dev/stdin (i.e. /proc/self/fd/0) looks like a symlink,
+        # stat(2) bypasses the synthetic symlink and directly accesses the
+        # underlying open-file.  So this works correctly even if the file
+        # has been renamed or unlinked.  stat will output two lines like:
         # WW.XXX
         # YY.ZZZ
         # which need to be separated and compared.
-        if stat=$( stat -L -c '%D.%i' - $_lockfile 0<&$_lockfd 2>/dev/null )
+        if stat=$( stat -L -c '%D.%i' /dev/stdin $_lockfile 0<&$_lockfd 
2>/dev/null )
         then
             local file_stat
             local fd_stat
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.