From 827b1ceefdfdb3b4b55affb32f3c315abb7ad3fb Mon Sep 17 00:00:00 2001 From: Jan \"Yenya\" Kasprzak Date: Tue, 5 Jun 2012 16:26:58 +0200 Subject: flock: user-configurable exit code When locking the file fails with -n or -w option, caller has no way to distinguish between the exit code 1 of the -c command, and the exit code 1 of flock(1) caused by the conflicting lock. Add a new -E (--conflict-exit-code) option to set the exit code for the case of locking failure to any value. --- sys-utils/flock.1 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'sys-utils/flock.1') diff --git a/sys-utils/flock.1 b/sys-utils/flock.1 index 5a6f27fbb..b50c619cf 100644 --- a/sys-utils/flock.1 +++ b/sys-utils/flock.1 @@ -71,13 +71,19 @@ cases, for example if the enclosed command group may have forked a background process which should not be holding the lock. .TP \fB\-n\fP, \fB\-\-nb\fP, \fB\-\-nonblock\fP -Fail (with an exit code of 1) rather than wait if the lock cannot be +Fail rather than wait if the lock cannot be immediately acquired. +See the +.I \-E +option for the exit code used. .TP \fB\-w\fP, \fB\-\-wait\fP, \fB\-\-timeout\fP \fIseconds\fP -Fail (with an exit code of 1) if the lock cannot be acquired within +Fail if the lock cannot be acquired within .IR seconds . Decimal fractional values are allowed. +See the +.I \-E +option for the exit code used. .TP \fB\-o\fP, \fB\-\-close\fP Close the file descriptor on which the lock is held before executing @@ -86,6 +92,11 @@ This is useful if .B command spawns a child process which should not be holding the lock. .TP +\fB\-E\fP, \fB\-\-conflict\-exit\-code\fP \fInumber\fP +The exit code used when the \fB\-n\fP option is in use, and the +conflicting lock exists, or the \fB\-w\fP option is in use, +and the timeout is reached. The default value is 1. +.TP \fB\-c\fP, \fB\-\-command\fP \fIcommand\fP Pass a single .IR command , @@ -134,7 +145,9 @@ return values for everything else but an options .I \-n or .I \-w -failures which return 1. +failures which return either the value given by the +.I \-E +option, or 1 by default. .SH AUTHOR .UR hpa@zytor.com H. Peter Anvin -- cgit v1.2.3-55-g7522