summaryrefslogtreecommitdiff
path: root/lib/uuid
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2008-02-15 17:41:38 -0500
committerTheodore Ts'o <tytso@mit.edu>2008-02-16 10:05:48 -0500
commite70f32b79d29e287f8347c5d41c6716f094cc654 (patch)
tree0a4af0f1b82efe794d9fde7c49817e2d9be8d6a5 /lib/uuid
parent67ab6bc86b19912d970c6b45e63b7bc93ca38494 (diff)
downloade2fsprogs-e70f32b79d29e287f8347c5d41c6716f094cc654.tar.gz
libuuid: use fcntl locking instead of lockf
Cygwin doesn't support lockf(), so move to fcntl() locking as more portable. Also fix a bug which could cause get_lock() to loop forever if the attempt to lock the file fails for some reason. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/uuid')
-rw-r--r--lib/uuid/gen_uuid.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 9254eb68..d4befe48 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -266,6 +266,7 @@ 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;
unsigned long long clock_reg;
mode_t save_umask;
@@ -280,14 +281,20 @@ 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 (lockf(state_fd, F_LOCK, 0) < 0) {
+ while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
if ((errno == EAGAIN) || (errno == EINTR))
continue;
fclose(state_f);
close(state_fd);
state_fd = -1;
+ break;
}
}
if (state_fd >= 0) {
@@ -348,7 +355,8 @@ try_again:
clock_seq, last.tv_sec, last.tv_usec, adjustment);
fflush(state_f);
rewind(state_f);
- lockf(state_fd, F_ULOCK, 0);
+ fl.l_type = F_UNLCK;
+ fcntl(state_fd, F_SETLK, &fl);
}
*clock_high = clock_reg >> 32;