Commit Graph

61 Commits

Author SHA1 Message Date
Karel Zak 4fb27d5c62 flock: fix time_t=long assumptions
This also fixes flock for archs (e.g. sparc64) where suseconds_t is not long.

Fixes: https://github.com/karelzak/util-linux/issues/1069
References: ce3355cc54
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 10:13:27 +02:00
Karel Zak e5781b3d3b flock: keep -E exit status more restrictive
Addresses: https://github.com/karelzak/util-linux/issues/1180
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 10:53:23 +01:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 6df5acf970 lib/timer: add fallback if timer_create() not available
* 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>
2018-12-03 11:23:33 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
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>
2017-06-27 12:26:19 +02:00
Ruediger Meier 6d7bee26bc flock, getopt: write --help to stdout and return 0
... 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>
2017-06-26 14:38:24 +02:00
Ruediger Meier 0b2b32e8a7 misc: fix more strutils related exit codes
Found by grep:

grep -l "\bEXIT_\|exit *( *[0-9][0-9] *)\|strutils\.h" $(grep -L \
    strutils_set_exitcode  $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

The Command shows also some false positives (fstrim.c,
context_mount.c, ...)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:21 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(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>
2017-06-14 11:48:22 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
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>
2017-02-20 12:58:49 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak 93fea49f28 flocks: keep run_program() simple 2016-10-31 13:15:35 +01:00
Karel Zak 391e675c6f flock: fix no-flock patch
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=842598
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-31 12:50:31 +01:00
Terry Burton 703251401c flock: Introduce no-fork option.
When guarding a command with flock it is sometimes preferable to not leave a
flock process waiting around for the command to exit.
2016-04-15 23:15:22 +01:00
Benno Schulenberg 62eea9ce12 textual: adjust grammar and punctuation of some messages
Also equalize three messages to one other one,
and fix a typo in USE_COLORS_BY_DEFAULT.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-08-03 11:18:56 +02:00
Brad Forschinger b5575bc08c flock: NULL deref
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>
2015-05-05 12:42:52 +02:00
Karel Zak 26e8964b9d lib/timer: use separate file for timers
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>
2015-03-06 13:17:20 +01:00
Sami Kerola 378543e13f flock: improve timeout handling
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>
2015-03-05 10:31:01 +01:00
Sami Kerola 59dc9f28b5 flock: add --verbose option
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>
2015-03-03 19:35:27 +00:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
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>
2015-01-06 11:27:38 +01:00
Karel Zak c4604c38b5 flock: zero timeout is valid
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>
2014-10-07 12:12:39 +02:00
Sami Kerola c5c056e7fe flock: add error message to translations
And remove type casting.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:18 +02:00
Benno Schulenberg 7a853ebc38 textual: using angular brackets around individual arguments
And separate short and long options with the standard comma.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-10-01 09:37:08 +02:00
Karel Zak caf1ba11a3 flock: use nfs4 fallback on EBADF too
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>
2014-03-24 11:26:21 +01:00
Benno Schulenberg 4ce393f4d8 textual: fix several typos and angular brackets in messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:14 +02:00
Karel Zak 3c7fbc82da flock: possible pointer dereferences [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:40:42 +01:00
Karel Zak 907624ebb0 flock: use include/timer.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-13 12:13:55 +01:00
Karel Zak 880c4045e5 flock: use strtotimeval() from libcommon
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-13 11:52:34 +01:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:17 +01:00
Benno Schulenberg 0c6625a15d textual: standardize the reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-30 15:24:00 +01:00
Benno Schulenberg 217615e8ed textual: standardize reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Mike Frysinger 295dd90226 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>
2013-01-09 13:36:58 +01:00
Yuri Chornoivan bbac757b1e textual: fix typos in messages 2012-09-04 17:26:31 +02:00
Jan \"Yenya\" Kasprzak 827b1ceefd 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 <exitcode> (--conflict-exit-code) option to set
the exit code for the case of locking failure to any value.
2012-06-15 11:12:06 +02:00
Sami Kerola efb8854f4c sys-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:49:40 +02:00
Karel Zak 1bbf820377 flock: fix sizeof usage [clang -Wsizeof-pointer-memaccess]
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>
2012-01-19 19:30:31 +01:00
Karel Zak eb742a1f66 flock: use O_RDWR as fallback if O_RDONLY returns EIO
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>
2011-11-21 17:26:41 +01:00
Karel Zak bc3ae4c6fc flock: timer code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-21 15:02:56 +01:00
Sami Kerola 605325b23b flock: simplify strtotimeval()
Retire private string to number conversion and use strtod_or_err() instead.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:45:27 +02:00
Sami Kerola 37bb0ce812 flock: use strutils.h to check numeric user input
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:45:27 +02:00
Sami Kerola 56d45cfabe flock: use sysexit.h for all exit values
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>
2011-09-29 22:45:27 +02:00
Sami Kerola e8cea66966 flock: use function attributes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:45:27 +02:00
Sami Kerola dc36ee2a4c flock: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:45:20 +02:00
Sami Kerola d4eafec4d2 flock: use libc error printing facilities
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>
2011-09-29 22:25:16 +02:00
Sami Kerola d89bfedff5 flock: move long_options struct to function scope
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:22:33 +02:00
Sami Kerola 75332f0f2b flock: fix coding style
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>
2011-09-29 22:22:22 +02:00
Petr Uzel 87d83b6ad2 flock: make flock(1) work on NFSv4
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>
2011-09-27 15:02:44 +02:00
Karel Zak 2e49d90f34 flock: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 13:07:30 +02:00
Josiah Worcester d78104d14e fsck, checktty, flock: Use more portable includes.
Signed-off-by: Josiah Worcester <josiahw@gmail.com>
2011-06-14 13:58:37 +02:00
Karel Zak 1fc0b941d6 flock: properly report exec() errors
Reported-by: Barry Davis <barry_davis@stormagic.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-20 11:45:00 +02:00