diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 135efe9..1e96337 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -820,41 +820,47 @@ 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]; char line[1024]; char *key, *val; char *ptr1 = release; + product[0] = '\0'; + version[0] = '\0'; + release[0] = '\0'; log_debug("localchassis", "grab OS release"); - FILE *fp = fopen("/etc/os-release", "r"); - if (!fp) { - log_debug("localchassis", "could not open /etc/os-release"); - fp = fopen("/usr/lib/os-release", "r"); - } + FILE *fp = fopen("/usr/share/factory/version", "r"); if (!fp) { log_info("localchassis", - "could not open either /etc/os-release or /usr/lib/os-release"); + "could not open either /usr/share/factory/version"); return NULL; } while ((fgets(line, sizeof(line), fp) != NULL)) { - key = strtok(line, "="); - val = strtok(NULL, "="); + key = strtok(line, ":"); + val = strtok(NULL, ":"); - if (strncmp(key, "PRETTY_NAME", sizeof(line)) == 0) { - strlcpy(release, val, sizeof(line)); + if (strncmp(key, "Product", sizeof(product)) == 0) { + strlcpy(product, val, sizeof(product)); + break; + } + else if (strncmp(key, "Version", sizeof(version)) == 0) { + strlcpy(version, val, sizeof(version)); break; } } fclose(fp); /* Remove trailing newline and all " in the string. */ + snprintf(release, sizeof(release), "%s %s", product, version); ptr1 = release + strlen(release) - 1; while (ptr1 != release && - ((*ptr1 == '"') || (*ptr1 == '\n'))) { + ((*ptr1 == '\n'))) { *ptr1 = '\0'; ptr1--; } @@ -1817,7 +1823,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) fatal("main", "unable to spawn lldpcli"); } - /* 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. */ log_debug("main", "get OS/LSB release information"); lsb_release = lldpd_get_os_release();