From: Karel Zak Date: Mon, 22 Nov 2021 09:23:52 +0000 (+0100) Subject: flock: (adoc) fix example X-Git-Tag: v2.38-rc1~153 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c4de946a3b002b1d23d3d7f088b22bdea46ecbc;p=thirdparty%2Futil-linux.git flock: (adoc) fix example Fixes: https://github.com/util-linux/util-linux/issues/1506 Signed-off-by: Karel Zak --- diff --git a/sys-utils/flock.1.adoc b/sys-utils/flock.1.adoc index f1fb6686f7..ced4bf15e6 100644 --- a/sys-utils/flock.1.adoc +++ b/sys-utils/flock.1.adoc @@ -111,7 +111,7 @@ Grab the exclusive lock "local-lock-file" before running echo with 'a b c'. (; flock -n 9 || exit 1; # ... commands executed under lock ...; ) 9>/var/lock/mylockfile:: The form is convenient inside shell scripts. The mode used to open the file doesn't matter to *flock*; using _>_ or _>>_ allows the lockfile to be created if it does not already exist, however, write permission is required. Using _<_ requires that the file already exists but only read permission is required. -[ $\{FLOCKER} != $0 ] && exec env FLOCKER="$0 flock -en $0 $0 $@ || ::: +[ "$\{FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || : :: This is useful boilerplate code for shell scripts. Put it at the top of the shell script you want to lock and it'll automatically lock itself on the first run. If the env var *$FLOCKER* is not set to the shell script that is being run, then execute *flock* and grab an exclusive non-blocking lock (using the script itself as the lock file) before re-execing itself with the right arguments. It also sets the FLOCKER env var to the right value so it doesn't run again. shell> exec 4<>/var/lock/mylockfile; shell> flock -n 4::