scripts: don't rely on "stat -" support
PATCH 1/1 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.
tools/hotplug/Linux/locking.sh +5 -9
@@ -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
Jan Beulich writes ("[PATCH] scripts: don't rely on "stat -" support"):
Quoted 9 lines
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 <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Thanks.
The only code change here is this:
tools/hotplug/Linux/locking.sh claim_lock() · line 45
Quoted 5 lines
tools/hotplug/Linux/locking.sh +1
-1@@ -45,18 +45,14 @@ claim_lock() - 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 )
Has anyone executed this ?
Paul, can we have a release-ack ?
Thanks,
Ian.
Quoted 23 lines · Ian Jackson
Jan Beulich writes ("[PATCH] scripts: don't rely on "stat -" support"):
Quoted 9 lines
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 <[email protected]>Signed-off-by Jan Beulich <[email protected]>Thanks.
The only code change here is this:
tools/hotplug/Linux/locking.sh claim_lock() · line 45
Quoted 5 lines
tools/hotplug/Linux/locking.sh +1
-1@@ -45,18 +45,14 @@ claim_lock() - 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 )Reviewed-by Ian Jackson <[email protected]>
Quoted 1 line
Has anyone executed this ?
I have, of course, to confirm this fixes my issue. But I'm not sure that's what you've meant to ask - you may have wanted assurance that someone else has also tried it.
Jan
Quoted 25 lines · Jan Beulich
Quoted 23 lines · Ian Jackson
Jan Beulich writes ("[PATCH] scripts: don't rely on "stat -" support"):
Quoted 9 lines
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 <[email protected]>Signed-off-by Jan Beulich <[email protected]>Thanks.
The only code change here is this:
tools/hotplug/Linux/locking.sh claim_lock() · line 45
Quoted 5 lines
tools/hotplug/Linux/locking.sh +1
-1@@ -45,18 +45,14 @@ claim_lock() - 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 )Reviewed-by Ian Jackson <[email protected]>
Quoted 5 lines
Quoted 1 line
Has anyone executed this ?
I have, of course, to confirm this fixes my issue. But I'm not sure that's what you've meant to ask - you may have wanted assurance that someone else has also tried it.
Jason Andryuk writes ("Re: [PATCH] scripts: don't rely on "stat -" support"):
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Ian Jackson
Quoted 23 lines
Jan Beulich writes ("[PATCH] scripts: don't rely on "stat -" support"):
Quoted 9 lines
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 <[email protected]>Signed-off-by Jan Beulich <[email protected]>Thanks.
The only code change here is this:
tools/hotplug/Linux/locking.sh claim_lock() · line 45
Quoted 5 lines
tools/hotplug/Linux/locking.sh +1
-1@@ -45,18 +45,14 @@ claim_lock() - 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 )Reviewed-by Ian Jackson <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Has anyone executed this ?
I have, of course, to confirm this fixes my issue. But I'm not sure that's what you've meant to ask - you may have wanted assurance that someone else has also tried it.
Tested-by Jason Andryuk <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
:-).
Thanks,
Ian.
Quoted 37 lines
-----Original Message-----
From: Ian Jackson <[email protected]>
Sent: 25 June 2020 17:36
To: Jason Andryuk <[email protected]>
Cc: Jan Beulich <[email protected]>; Paul Durrant <[email protected]>; [email protected]; Wei Liu <[email protected]>
Subject: Re: [PATCH] scripts: don't rely on "stat -" supportJason Andryuk writes ("Re: [PATCH] scripts: don't rely on "stat -" support"):
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Ian Jackson
Quoted 24 lines
Jan Beulich writes ("[PATCH] scripts: don't rely on "stat -" support"):
Quoted 9 lines
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 <[email protected]>Signed-off-by Jan Beulich <[email protected]>Thanks.
The only code change here is this:
tools/hotplug/Linux/locking.sh claim_lock() · line 45
Quoted 5 lines
tools/hotplug/Linux/locking.sh +1
-1@@ -45,18 +45,14 @@ claim_lock() - 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 )Reviewed-by Ian Jackson <[email protected]>Has anyone executed this ?
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I have, of course, to confirm this fixes my issue. But I'm not sure that's what you've meant to ask - you may have wanted assurance that someone else has also tried it.
Tested-by Jason Andryuk <[email protected]>Reviewed-by Jason Andryuk <[email protected]>:-).
In which case...
Quoted 2 lines
Thanks,
Ian.