]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: fix locking of clock state counter file
authorPetr Uzel <petr.uzel@suse.cz>
Mon, 7 Feb 2011 13:18:28 +0000 (14:18 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Feb 2011 15:27:17 +0000 (16:27 +0100)
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@suse.cz>
shlibs/uuid/src/gen_uuid.c

index a90bd8ee01605fb441dac4c1e6e6ae74fd3e4111..720fda4340f4d5a63a28b4b5fa9be86cdf8bf04f 100644 (file)
@@ -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;