From: Petr Uzel Date: Mon, 7 Feb 2011 13:18:28 +0000 (+0100) Subject: libuuid: fix locking of clock state counter file X-Git-Tag: v2.19~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c190c6c2e987816ca0f273e2de528701d10cbbc1;p=thirdparty%2Futil-linux.git libuuid: fix locking of clock state counter file 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 --- diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c index a90bd8ee01..720fda4340 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;