From d28ccd0b91881ad8e52ed66e36c2db644a6990bf Mon Sep 17 00:00:00 2001 From: Hailong Wang Date: Wed, 13 Apr 2022 21:14:08 +0800 Subject: [PATCH] fix #37 if /etc/machine-id is empty --- wsd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wsd.c b/wsd.c index 607f26d..0a363d8 100644 --- a/wsd.c +++ b/wsd.c @@ -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; @@ -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; }