diff --git a/src/lldpd.c b/src/lldpd.c index 096377a..a94ad13 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -554,14 +554,16 @@ lldpd_get_lsb_release() { return NULL; } -/* Same like lldpd_get_lsb_release but reads /etc/os-release for PRETTY_NAME=. */ +/* Same like lldpd_get_lsb_release but reads /usr/share/factory/version for Product: and Version:. */ static char * lldpd_get_os_release() { + static char product[512]; + static char version[512]; static char release[1024]; - FILE *fp = fopen("/etc/os-release", "r"); + FILE *fp = fopen("/usr/share/factory/version", "r"); if (!fp) { - LLOG_WARN("could not open /etc/os-release"); + LLOG_WARN("could not open /usr/share/factory/version"); return NULL; } @@ -569,21 +571,24 @@ lldpd_get_os_release() { char *key, *val; while ((fgets(line, 1024, fp) != NULL)) { - key = strtok(line, "="); - val = strtok(NULL, "="); + key = strtok(line, ": "); + val = strtok(NULL, ": "); - if (strncmp(key, "PRETTY_NAME", 1024) == 0) { - strncpy(release, val, 1024); - break; - } + if (strncmp(key, "Product", 512) == 0) + strncpy(product, val, 512); + + if (strncmp(key, "Version", 512) == 0) + strncpy(version, val, 512); } fclose(fp); - /* Remove trailing newline and all " in the string. */ + snprintf(release, sizeof(release), "%s %s", product, version); + + /* Remove newlines in the string. */ char *ptr1 = release; char *ptr2 = release; while (*ptr1 != 0) { - if ((*ptr1 == '"') || (*ptr1 == '\n')) { + if (*ptr1 == '\n') { ++ptr1; } else { *ptr2++ = *ptr1++; @@ -1229,7 +1234,7 @@ lldpd_main(int argc, char *argv[]) close(pid); } - /* Try to read system information from /etc/os-release if possible. + /* Try to read system information from /usr/share/factory/version if possible. Fall back to lsb_release for compatibility. */ lsb_release = lldpd_get_os_release(); if (!lsb_release) {