From 700031ade7cbcdcecf1205f98f50ed0da57c7493 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Nov 2014 14:35:21 +0100 Subject: misc: use monotonic time rater than gettimeofday Based on patch Alexander Samilovskih Signed-off-by: Karel Zak --- libmount/src/lock.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libmount/src') diff --git a/libmount/src/lock.c b/libmount/src/lock.c index 8667db999..0a07e9b03 100644 --- a/libmount/src/lock.c +++ b/libmount/src/lock.c @@ -25,6 +25,7 @@ #include "closestream.h" #include "pathnames.h" #include "mountP.h" +#include "timeutils.h" /* * lock handler @@ -258,7 +259,7 @@ static int mnt_wait_mtab_lock(struct libmnt_lock *ml, struct flock *fl, time_t m struct sigaction sa, osa; int ret = 0; - gettimeofday(&now, NULL); + gettime_monotonic(&now); if (now.tv_sec >= maxtime) return 1; /* timeout */ @@ -408,7 +409,7 @@ static int lock_mtab(struct libmnt_lock *ml) } close(i); - gettimeofday(&maxtime, NULL); + gettime_monotonic(&maxtime); maxtime.tv_sec += MOUNTLOCK_MAXTIME; waittime.tv_sec = 0; @@ -434,7 +435,7 @@ static int lock_mtab(struct libmnt_lock *ml) if (ml->lockfile_fd < 0) { /* Strange... Maybe the file was just deleted? */ int errsv = errno; - gettimeofday(&now, NULL); + gettime_monotonic(&now); if (errsv == ENOENT && now.tv_sec < maxtime.tv_sec) { ml->locked = 0; continue; @@ -646,7 +647,7 @@ int test_lock(struct libmnt_test *ts, int argc, char *argv[]) /* start the test in exactly defined time */ if (synctime) { - gettimeofday(&tv, NULL); + gettime_monotonic(&tv); if (synctime && synctime - tv.tv_sec > 1) { usecs = ((synctime - tv.tv_sec) * 1000000UL) - (1000000UL - tv.tv_usec); -- cgit v1.2.3-55-g7522