summaryrefslogtreecommitdiffstats
path: root/sys-utils/flock.c
diff options
context:
space:
mode:
authorSami Kerola2015-02-10 00:18:09 +0100
committerKarel Zak2015-03-05 10:31:01 +0100
commit378543e13f93c522b976efddd1610a19a6601b1c (patch)
tree38467867c9467eb6cc23b91516be9364ef74bb7c /sys-utils/flock.c
parentflock: add --verbose option (diff)
downloadkernel-qcow2-util-linux-378543e13f93c522b976efddd1610a19a6601b1c.tar.gz
kernel-qcow2-util-linux-378543e13f93c522b976efddd1610a19a6601b1c.tar.xz
kernel-qcow2-util-linux-378543e13f93c522b976efddd1610a19a6601b1c.zip
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>
Diffstat (limited to 'sys-utils/flock.c')
-rw-r--r--sys-utils/flock.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index 707c5992b..368ad1a9f 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -43,7 +43,6 @@
#include "nls.h"
#include "strutils.h"
#include "closestream.h"
-#include "timer.h"
#include "monotonic.h"
static void __attribute__((__noreturn__)) usage(int ex)
@@ -77,9 +76,12 @@ static void __attribute__((__noreturn__)) usage(int ex)
static sig_atomic_t timeout_expired = 0;
-static void timeout_handler(int sig __attribute__((__unused__)))
+static void timeout_handler(int sig __attribute__((__unused__)),
+ siginfo_t *info,
+ void *context __attribute__((__unused__)))
{
- timeout_expired = 1;
+ if (info->si_code == SI_TIMER)
+ timeout_expired = 1;
}
static int open_file(const char *filename, int *flags)
@@ -113,7 +115,8 @@ static int open_file(const char *filename, int *flags)
int main(int argc, char *argv[])
{
- struct itimerval timeout, old_timer;
+ static timer_t t_id;
+ struct itimerval timeout;
int have_timeout = 0;
int type = LOCK_EX;
int block = 0;
@@ -131,7 +134,6 @@ int main(int argc, char *argv[])
int conflict_exit_code = 1;
char **cmd_argv = NULL, *sh_c_argv[4];
const char *filename = NULL;
- struct sigaction old_sa;
enum {
OPT_VERBOSE = CHAR_MAX + 1
};
@@ -246,7 +248,8 @@ int main(int argc, char *argv[])
have_timeout = 0;
block = LOCK_NB;
} else
- setup_timer(&timeout, &old_timer, &old_sa, timeout_handler);
+ if (setup_timer(&t_id, &timeout, &timeout_handler))
+ err(EX_OSERR, _("cannot not setup timer"));
}
if (verbose)
@@ -298,7 +301,7 @@ int main(int argc, char *argv[])
}
if (have_timeout)
- cancel_timer(&old_timer, &old_sa);
+ cancel_timer(&t_id);
if (verbose) {
struct timeval delta;