[PATCH 5/9] libuuid: get_clock(): report if the clock_seq is safe

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

 



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

diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c
index 6e82a7b..f623192 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)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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