* add struct ul_timer as API abstraction to hide differences between
timer_create() and setitimer()
* add setitimer() detection to ./configure.ac
* add fallback code to use setitimer() if timer_create() not available
(for example on OSX)
Addresses: https://github.com/karelzak/util-linux/issues/584
Signed-off-by: Karel Zak <kzak@redhat.com>
changed in include/c.h and applied via sed:
sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Consolidate --help and --version descriptions. We are
now able to align them to the other options.
We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
... and use errtryhelp() instead of usage().
Note in past "getopt --help" returned 2. But it is otherwise
documented and was just a mistake IMO. See the unreachable exit(0)
which was removed here: d1d03b54
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
(Original patch and commit message edited by Rudi.)
gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.
We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.
Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>