Commit Graph

52 Commits

Author SHA1 Message Date
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
François Revol 1bf4407a1d portability: use standard constants
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-07-26 11:41:04 +02:00
Mike Frysinger 60cd48bd14 flock: fix hang when parent ignores SIGCHLD
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>
2009-12-07 15:23:40 +01:00
Karel Zak db1749cf6c flock: add NLS support, remove tailing white-spaces
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-11 13:37:45 +01:00
Karel Zak 56d23414c1 flock: fix printf format error in usage()
flock.c: In function ‘usage’:
flock.c:75: warning: too few arguments for format

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-11 13:37:45 +01:00
Karel Zak 841f86dbc2 flockc: segfaults when file name is not given
$ flock -s
Segmentation fault

ltrace:
__libc_start_main(0x8048870, 2, 0xbfe9f404, 0x8049070, 0x8049060 <unfinished ...>
getopt_long(2, 0xbfe9f404, "+sexnouw:hV?", 0x80494e0, 0xbfe9f354) = 115
getopt_long(2, 0xbfe9f404, "+sexnouw:hV?", 0x80494e0, 0xbfe9f354) = -1
strtol(0, 0xbfe9f34c, 10, 0x80494e0, 0xbfe9f354 <unfinished ...>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

Addresses-Red-Had-Bugzilla: #489672
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-11 13:37:40 +01:00
Alexey Gladkov ff5717391c flock: Allow lock directory
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>
2008-12-03 10:33:53 +01:00
maximilian attems d3e8f6598b remove CVS keywords
this patch removes old CVS keywords from comments.

mount(8) works for newer Linux then 0.99 ;)

Signed-off-by: maximilian attems <max@stro.at>
2008-07-28 11:10:08 +02:00
Karel Zak a120aaa70d Imported from util-linux-2.13-pre7 tarball. 2006-12-07 00:27:22 +01:00
Karel Zak baf39af15b Imported from util-linux-2.13-pre2 tarball. 2006-12-07 00:26:58 +01:00