devtools/lib
Luke Shumaker d333440810
lib/common.sh: lock, slock: Allow locks to be inherited.
Allow for locks to be inherited.  Inheriting the lock is something that
mkarchroot could do previously, but has since lost the ability to do.  This
allows for the programs to be more compos-able.

Do this by instead of unconditionally opening $file on $fd, first check if
$file is already open on $fd; and go ahead use it if it is.

The naive way of doing this would be to `$(readlink /dev/fd/$fd)` and
compare that to `$file`.  However, if `$file` is itself a symlink; or there
is a symlink somewhere in the path to `$file`, then this could easily fail.
Instead, check `[[ "/dev/fd/$fd" -ef "$file" ]]`.  Even though the Bash
documentation (`help test`) says that `-ef` checks for if the two files are
hard links to eachother, because it uses stat(3) (which resolves symlinks)
to do this check, it also works with the /dev/fd/ soft links.
2017-04-05 22:03:00 +02:00
..
archroot.sh archbuild/makechrootpkg: Delete subvolumes in roots 2017-03-07 20:39:11 +01:00
common.sh lib/common.sh: lock, slock: Allow locks to be inherited. 2017-04-05 22:03:00 +02:00
valid-tags.sh archrelease: Validate tags before releasing 2012-02-12 12:35:14 +01:00