summaryrefslogtreecommitdiff
path: root/lib/uuid/gen_uuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uuid/gen_uuid.c')
-rw-r--r--lib/uuid/gen_uuid.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 42d7563d..22b45134 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -176,8 +176,7 @@ static void get_random_bytes(void *buf, int nbytes)
{
int i, n = nbytes, fd = get_random_fd();
int lose_counter = 0;
- unsigned char *cp = (unsigned char *) buf;
- unsigned short tmp_seed[3];
+ unsigned char *cp = buf;
if (fd >= 0) {
while (n > 0) {
@@ -200,12 +199,16 @@ static void get_random_bytes(void *buf, int nbytes)
for (cp = buf, i = 0; i < nbytes; i++)
*cp++ ^= (rand() >> 7) & 0xFF;
#ifdef DO_JRAND_MIX
- memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed));
- jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid);
- for (cp = buf, i = 0; i < nbytes; i++)
- *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
- memcpy(jrand_seed, tmp_seed,
- sizeof(jrand_seed)-sizeof(unsigned short));
+ {
+ unsigned short tmp_seed[3];
+
+ memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed));
+ jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid);
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
+ memcpy(jrand_seed, tmp_seed,
+ sizeof(jrand_seed) - sizeof(unsigned short));
+ }
#endif
return;
@@ -323,10 +326,12 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
state_fd = open("/var/lib/libuuid/clock.txt",
O_RDWR|O_CREAT, 0660);
(void) umask(save_umask);
- state_f = fdopen(state_fd, "r+");
- if (!state_f) {
- close(state_fd);
- state_fd = -1;
+ if (state_fd >= 0) {
+ state_f = fdopen(state_fd, "r+");
+ if (!state_f) {
+ close(state_fd);
+ state_fd = -1;
+ }
}
}
fl.l_type = F_WRLCK;
@@ -340,7 +345,6 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
if ((errno == EAGAIN) || (errno == EINTR))
continue;
fclose(state_f);
- close(state_fd);
state_fd = -1;
break;
}
@@ -398,9 +402,10 @@ try_again:
if (state_fd > 0) {
rewind(state_f);
- len = fprintf(state_f,
+ len = fprintf(state_f,
"clock: %04x tv: %016lu %08lu adj: %08d\n",
- clock_seq, last.tv_sec, last.tv_usec, adjustment);
+ clock_seq, last.tv_sec, (long)last.tv_usec,
+ adjustment);
fflush(state_f);
if (ftruncate(state_fd, len) < 0) {
fprintf(state_f, " \n");
@@ -408,7 +413,10 @@ try_again:
}
rewind(state_f);
fl.l_type = F_UNLCK;
- fcntl(state_fd, F_SETLK, &fl);
+ if (fcntl(state_fd, F_SETLK, &fl) < 0) {
+ fclose(state_f);
+ state_fd = -1;
+ }
}
*clock_high = clock_reg >> 32;