summaryrefslogtreecommitdiffstats
path: root/shlibs/uuid
diff options
context:
space:
mode:
authorPetr Uzel2011-02-14 14:43:26 +0100
committerKarel Zak2011-02-16 16:07:15 +0100
commit34b2e3f13397c5ed8e5686f99e6dd677f944d1f2 (patch)
treef40e0fcbbe9c01a8a7f1ec11360f192349d6e879 /shlibs/uuid
parentlibuuid: do not use invalid file descriptor (diff)
downloadkernel-qcow2-util-linux-34b2e3f13397c5ed8e5686f99e6dd677f944d1f2.tar.gz
kernel-qcow2-util-linux-34b2e3f13397c5ed8e5686f99e6dd677f944d1f2.tar.xz
kernel-qcow2-util-linux-34b2e3f13397c5ed8e5686f99e6dd677f944d1f2.zip
libuuid: get_clock(): report if the clock_seq is safe
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
Diffstat (limited to 'shlibs/uuid')
-rw-r--r--shlibs/uuid/src/gen_uuid.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c
index 6e82a7b7c..f6231927e 100644
--- a/shlibs/uuid/src/gen_uuid.c
+++ b/shlibs/uuid/src/gen_uuid.c
@@ -306,6 +306,12 @@ static int get_node_id(unsigned char *node_id)
/* Assume that the gettimeofday() has microsecond granularity */
#define MAX_ADJUSTMENT 10
+/*
+ * Get clock from global sequence clock counter.
+ *
+ * Return -1 if the clock counter could not be opened/locked (in this case
+ * pseudorandom value is returned in @ret_clock_seq), otherwise return 0.
+ */
static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
uint16_t *ret_clock_seq, int *num)
{
@@ -318,6 +324,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
uint64_t clock_reg;
mode_t save_umask;
int len;
+ int ret = 0;
if (state_fd == -2) {
save_umask = umask(0);
@@ -329,8 +336,11 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
if (!state_f) {
close(state_fd);
state_fd = -1;
+ ret = -1;
}
}
+ else
+ ret = -1;
}
if (state_fd >= 0) {
rewind(state_f);
@@ -340,6 +350,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
fclose(state_f);
close(state_fd);
state_fd = -1;
+ ret = -1;
break;
}
}
@@ -411,7 +422,7 @@ try_again:
*clock_high = clock_reg >> 32;
*clock_low = clock_reg;
*ret_clock_seq = clock_seq;
- return 0;
+ return ret;
}
#if defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H)