text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer
Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.
Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cmd_argv[2] will be initialised only if it's specificed with -c. NULL
deref otherwise resulting in crash.
Signed-off-by: Brad Forschinger <bnjf@bnjf.id.au>
It seems that static builds require -lpthread for timer_* functions.
It's better to keep it out of our libs (e.g. libmount) to avoid
unnecessary dependence.
Signed-off-by: Karel Zak <kzak@redhat.com>
Signal ALRM raised by the timer, and the timer only, will be considered
as a timeout criteria.
Secondly time interval is made to use monotonic clock. Documentation of
ITIMER_REAL is unclear whether that time is affected various sources of
clock skew, or does it even tick when system is suspended.
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Jenkins script jobs using flock are a great example of a situation in
which one may want an automation to be verbose, so that when unexpected
events happen there is more hints in logs.
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This adds a concise description of a tool to its usage text.
A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
This patch reverts Sami's "timeout cannot be zero", introduced
in commit 605325b23b.
The --timeout 0 has been originally interpreted as --nonblock. The
patch also add hint about this behavior to the man page.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1149974
Signed-off-by: Karel Zak <kzak@redhat.com>
The kernel regression (probably v3.4, commit 55725513) introduces a
new errno for O_RDONLY on NFS. Now it returns EBADF rather than EIO.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1078618
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
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 <exitcode> (--conflict-exit-code) option to set
the exit code for the case of locking failure to any value.
flock.c:90:23: warning: argument to 'sizeof' in 'memset' call is the
same expression as the destination; did you mean to dereference it?
[-Wsizeof-pointer-memaccess]
memset(sa, 0, sizeof sa);
~~ ^~
Reported-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The commit 75aaee08f0 introduces
regression:
$ echo '#!/bin/sh' > test.sh
$ chmod a+rx test.sh
$ flock -eon ./test.sh ./test.sh
flock: ./test.sh: Text file busy
The lock file cannot be opened in read-write mode by default, because
then we cannot use flock(1) to lock executable files.
The read-write mode for lock files is necessary on NFSv4 where
flock(2) is emulated by by fcntl() -- this situation is possible to
detect by flock(2) EIO error.
This patch reverts the default to O_RDONLY and use O_RDWR only if EIO
error is detected.
Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Additionally enhance readability of complex double "if shorthand's" by
making the segment to be few normal "if's".
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Retire global progname variable and use warn{,x} and err{,x}
functions. As a side effect of using err function the occurences of
err variable had to be converted to referrals to errno variable.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sanitize indentation, spacing, brace positions, comment line lenghts and
positions etc. This commit does not change a thing in code.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
To pleace an exclusive lock on a file, NFSv4 requires
the file to be opened RW because of the emulation of flock()
by fcntl():
http://www.spinics.net/lists/linux-nfs/msg18502.html
So instead of O_RDONLY, open the file in O_RDWR if access()
indicates it is possible (unless shared lock is requested).
From: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
If flock is executed from a process which has set SIGCHLD to SIG_IGN, then
flock will eat cpu and hang indefinitely if given a command to execute.
So before we fork(), make sure to set SIGCHLD handling back to the default
so that the later waitpid() doesn't freak out on us.
[kzak@redhat.com: - add a check for waitpid() return value]
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
With this patch, you can lock directory. Additionally,
lockfile opens with O_NOCTTY.
Try to open file with O_CREAT flag first, and without it
if open fails with EISDIR. Suggested by H. Peter Anvin.
Signed-off-by: Alexey Gladkov <legion@altlinux.org>