Skip to content

Commit

Permalink
Merge pull request #38 from whlsxl/master
Browse files Browse the repository at this point in the history
fix #37  if /etc/machine-id is empty
  • Loading branch information
Andy2244 authored Apr 19, 2022
2 parents 9831daf + d28ccd0 commit 779f3e3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions wsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ static void set_seed(void)

time((time_t *)&seed);

if (fp) {
fseek(fp, 0, SEEK_END);

if (fp && 0 != ftell(fp) ) {
unsigned long s;
rewind(fp);

while (fscanf(fp, "%8lx", &s) > 0)
seed ^= s;
Expand Down Expand Up @@ -113,10 +116,19 @@ static void uuid_endpoint(char uuid[UUIDLEN])

if (!fp) {
fp = fopen("/proc/sys/kernel/random/boot_id", "r");
} else {
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
if (33 != size) {
fclose(fp);
fp = fopen("/proc/sys/kernel/random/boot_id", "r");
} else {
rewind(fp);
}
}

if (!fp) {
DEBUG(0, W, "Can't open required '/etc/machine-id' or '/proc/sys/kernel/random/boot_id'");
DEBUG(0, W, "Can't open or file empty, required '/etc/machine-id' or '/proc/sys/kernel/random/boot_id'");
return;
}

Expand Down

0 comments on commit 779f3e3

Please sign in to comment.