summaryrefslogtreecommitdiffstats
path: root/sys-utils/flock.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timer: add fallback if timer_create() not availableKarel Zak2018-12-031-3/+5
| | | | | | | | | | | | | * 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>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-1/+1
| | | | | | | | | 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>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | 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>
* flock, getopt: write --help to stdout and return 0Ruediger Meier2017-06-261-25/+27
| | | | | | | | | | ... 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>
* misc: fix more strutils related exit codesRuediger Meier2017-06-221-0/+2
| | | | | | | | | | | | 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>
* misc: fix ggc-7 fallthrough warningsSami Kerola2017-06-141-1/+1
| | | | | | | | | | | | | | | | | | | (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>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-1/+1
| | | | | | | | | | 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>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-5/+3Star
| | | | | | | | 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>
* flocks: keep run_program() simpleKarel Zak2016-10-311-8/+7Star
|
* flock: fix no-flock patchKarel Zak2016-10-311-17/+28
| | | | | Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=842598 Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: Introduce no-fork option.Terry Burton2016-04-161-27/+41
| | | | | When guarding a command with flock it is sometimes preferable to not leave a flock process waiting around for the command to exit.
* textual: adjust grammar and punctuation of some messagesBenno Schulenberg2015-08-031-1/+1
| | | | | | | 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>
* flock: NULL derefBrad Forschinger2015-05-051-1/+1
| | | | | | | 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>
* lib/timer: use separate file for timersKarel Zak2015-03-061-0/+1
| | | | | | | | 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>
* flock: improve timeout handlingSami Kerola2015-03-051-7/+10
| | | | | | | | | | | | 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>
* flock: add --verbose optionSami Kerola2015-03-031-2/+29
| | | | | | | | | 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>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | 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>
* flock: zero timeout is validKarel Zak2014-10-071-2/+0Star
| | | | | | | | | | | This patch reverts Sami's "timeout cannot be zero", introduced in commit 605325b23b36238c8f3ae165e37cab9064553cf7. 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>
* flock: add error message to translationsSami Kerola2014-10-011-1/+1
| | | | | | And remove type casting. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: using angular brackets around individual argumentsBenno Schulenberg2014-10-011-10/+10
| | | | | | And separate short and long options with the standard comma. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* flock: use nfs4 fallback on EBADF tooKarel Zak2014-03-241-0/+1
| | | | | | | | 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>
* textual: fix several typos and angular brackets in messagesBenno Schulenberg2013-06-071-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* flock: possible pointer dereferences [coverity scan]Karel Zak2013-03-271-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: use include/timer.hKarel Zak2013-03-131-18/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: use strtotimeval() from libcommonKarel Zak2013-03-131-12/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* translation: unify exec error messagesSami Kerola2013-02-061-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: standardize the reporting of program name plus package versionBenno Schulenberg2013-01-301-2/+1Star
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: standardize reporting of program name plus package versionBenno Schulenberg2013-01-251-1/+2
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* flock: improve usage stringsMike Frysinger2013-01-091-3/+3
| | | | | | | | 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>
* textual: fix typos in messagesYuri Chornoivan2012-09-041-1/+1
|
* flock: user-configurable exit codeJan \"Yenya\" Kasprzak2012-06-151-10/+16
| | | | | | | | | 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.
* sys-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: fix sizeof usage [clang -Wsizeof-pointer-memaccess]Karel Zak2012-01-191-1/+1
| | | | | | | | | | | 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>
* flock: use O_RDWR as fallback if O_RDONLY returns EIOKarel Zak2011-11-211-20/+48
| | | | | | | | | | | | | | | | | | | | | | | The commit 75aaee08f06b92d119ed827c53d1af5474eb16ff 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>
* flock: timer code refactoringKarel Zak2011-11-211-13/+20
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: simplify strtotimeval()Sami Kerola2011-09-291-26/+8Star
| | | | | | Retire private string to number conversion and use strtod_or_err() instead. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: use strutils.h to check numeric user inputSami Kerola2011-09-291-4/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: use sysexit.h for all exit valuesSami Kerola2011-09-291-9/+14
| | | | | | | 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>
* flock: use function attributesSami Kerola2011-09-291-3/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: align with howto-usage-function.txtSami Kerola2011-09-291-15/+16
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: use libc error printing facilitiesSami Kerola2011-09-291-43/+22Star
| | | | | | | | 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>
* flock: move long_options struct to function scopeSami Kerola2011-09-291-14/+14
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* flock: fix coding styleSami Kerola2011-09-291-280/+282
| | | | | | | 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>
* flock: make flock(1) work on NFSv4Petr Uzel2011-09-271-2/+5
| | | | | | | | | | | | | | 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>
* flock: cleanup usage()Karel Zak2011-08-161-14/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fsck, checktty, flock: Use more portable includes.Josiah Worcester2011-06-141-0/+2
| | | | Signed-off-by: Josiah Worcester <josiahw@gmail.com>
* flock: properly report exec() errorsKarel Zak2010-08-201-1/+1
| | | | | Reported-by: Barry Davis <barry_davis@stormagic.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* portability: use standard constantsFrançois Revol2010-07-261-1/+1
| | | | | Signed-off-by: François Revol <revol@free.fr> Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: fix hang when parent ignores SIGCHLDMike Frysinger2009-12-071-1/+9
| | | | | | | | | | | | 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>