scripts: Use stat to check lock claim
authorJason Andryuk <jandryuk@gmail.com>
Thu, 12 Mar 2020 14:54:17 +0000 (10:54 -0400)
committerWei Liu <wl@xen.org>
Mon, 30 Mar 2020 13:35:53 +0000 (14:35 +0100)
commitb72682c602b8d1aaadca439d49cc79c79dbc17bc
treed4926b196d62f6eac2ecaaf152185a130e7d086b
parent4b3f41e9d83209f5334095937aef7763da993781
scripts: Use stat to check lock claim

Replace the perl locking check with stat(1).  Stat is able to fstat
stdin (file descriptor 0) when passed '-' as an argument.  This is now
used to check $_lockfd.  stat(1) support for '-' was introduced to
coreutils in 2009.

After A releases its lock, script B will return from flock and execute
stat.  Since the lockfile has been removed by A, stat prints an error to
stderr and exits non-zero.  Redirect stderr to /dev/null to avoid
filling /var/log/xen/xen-hotplug.log with "No such file or directory"
messages.

Placing the stat call inside the "if" condition ensures we only check
the stat output when the command completed successfully.

This change removes the only runtime dependency of the xen toolstack on
perl.

Suggested-by: Ian Jackson <ian.jackson@citrix.com>
Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/hotplug/Linux/locking.sh