summaryrefslogtreecommitdiffstats
path: root/sys-utils/flock.1
diff options
context:
space:
mode:
authorMike Frysinger2012-12-26 21:10:29 +0100
committerKarel Zak2013-01-09 13:36:58 +0100
commit295dd90226852a1f3b3dd108ed01dd1d7da92240 (patch)
treedd5a98b5e1afe2079b67680bb744291236a55b3a /sys-utils/flock.1
parentinclude/ttyutils: add default chardata (diff)
downloadkernel-qcow2-util-linux-295dd90226852a1f3b3dd108ed01dd1d7da92240.tar.gz
kernel-qcow2-util-linux-295dd90226852a1f3b3dd108ed01dd1d7da92240.tar.xz
kernel-qcow2-util-linux-295dd90226852a1f3b3dd108ed01dd1d7da92240.zip
flock: improve usage strings
The current examples miss the best usage of all: specifying the command and its arguments directly on the command line. Add that to both the program usage and the man page. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'sys-utils/flock.1')
-rw-r--r--sys-utils/flock.115
1 files changed, 13 insertions, 2 deletions
diff --git a/sys-utils/flock.1 b/sys-utils/flock.1
index b50c619cf..b28526f69 100644
--- a/sys-utils/flock.1
+++ b/sys-utils/flock.1
@@ -29,10 +29,10 @@
flock \- manage locks from shell scripts
.SH SYNOPSIS
.B flock
-[options] <file> -c <command>
+[options] <file|directory> <command> [command args]
.br
.B flock
-[options] <directory> -c <command>
+[options] <file|directory> -c <command>
.br
.B flock
[options] <file descriptor number>
@@ -120,6 +120,9 @@ shell2> flock -s -w .007 /tmp -c echo; /bin/echo $?
Set shared lock to directory /tmp and the second command will not fail.
Notice that attempting to get exclusive lock with second command would fail.
.TP
+shell> flock -x local-lock-file echo 'a b c'
+Grab the exclusive lock "local-lock-file" before running echo with 'a b c'.
+.TP
(
.TQ
flock -n 9 || exit 1
@@ -138,6 +141,14 @@ allows the lockfile to be created if it does not already exist, however,
write permission is required. Using
.I <
requires that the file already exists but only read permission is required.
+.TP
+[ "${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.
.SH "EXIT STATUS"
The command uses
.B sysexits.h