[PATCH] libuuid: fix locking of clock state counter file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fcntl(2) does not work for synchronization of threads belonging
to the same process. Use flock(2) instead.

http://marc.info/?l=util-linux-ng&m=129708412829971&w=2

Signed-off-by: Petr Uzel <petr.uzel@xxxxxxx>
---
 shlibs/uuid/src/gen_uuid.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c
index a90bd8e..720fda4 100644
--- a/shlibs/uuid/src/gen_uuid.c
+++ b/shlibs/uuid/src/gen_uuid.c
@@ -315,7 +315,6 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
 	THREAD_LOCAL FILE		*state_f;
 	THREAD_LOCAL uint16_t		clock_seq;
 	struct timeval			tv;
-	struct flock			fl;
 	uint64_t			clock_reg;
 	mode_t				save_umask;
 	int				len;
@@ -331,14 +330,9 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
 			state_fd = -1;
 		}
 	}
-	fl.l_type = F_WRLCK;
-	fl.l_whence = SEEK_SET;
-	fl.l_start = 0;
-	fl.l_len = 0;
-	fl.l_pid = 0;
 	if (state_fd >= 0) {
 		rewind(state_f);
-		while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
+		while (flock(state_fd, LOCK_EX) < 0) {
 			if ((errno == EAGAIN) || (errno == EINTR))
 				continue;
 			fclose(state_f);
@@ -409,8 +403,7 @@ try_again:
 			fflush(state_f);
 		}
 		rewind(state_f);
-		fl.l_type = F_UNLCK;
-		fcntl(state_fd, F_SETLK, &fl);
+		flock(state_fd, LOCK_UN);
 	}
 
 	*clock_high = clock_reg >> 32;
-- 
1.7.1


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

Attachment: pgp0F68wWM2Ik.pgp
Description: PGP signature


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux