Skip to contentSkip to conversation

libmount/lock: add monotonic clock support

PATCH New Alexander 1 participant 1 message May 5, 2014 Util-Linux package

lore
Share & tools
lore

Alexander

author
#0 lore raw

PATCH 3/3 libmount/lock: add monotonic clock support

Quoted 1 line

From b8ca74bfdb93034e9d1c52ab8702ff02dab8787c Mon Sep 17 00:00:00 2001

From: Alex Samilovskih <[email protected]>
Date: Fri, 2 May 2014 18:28:31 +0000
Subject: [PATCH 3/3] Add support for monotonic clock in libmount

---
 libmount/src/lock.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libmount/src/lock.c +5 -4
index 8667db9..41f8ed1 100644
@@ -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);
+		gettimeofday(&tv);
 		if (synctime && synctime - tv.tv_sec > 1) {
 			usecs = ((synctime - tv.tv_sec) * 1000000UL) -
 						(1000000UL - tv.tv_usec);
Signature · 1 line
1.9.2