From: Michal Nowak Date: Tue, 19 May 2026 16:09:36 +0000 (+0000) Subject: Print OS platform in "named -V" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5ca9d33726dc81d0165a7b3893bedcbde2315a9;p=thirdparty%2Fbind9.git Print OS platform in "named -V" The "running on" line emitted by `named -V` (as well as the startup log and `rndc status`, which share the same source) now appends the PRETTY_NAME value from /etc/os-release in parentheses after the uname output, e.g.: running on Linux x86_64 6.19.14-... (Fedora Linux 42 (Workstation Edition)) This helps disambiguate environments where the kernel string is not a reliable indicator of the userspace, such as RHEL clones and containers whose kernel does not match the host OS. When /etc/os-release is absent, /usr/lib/os-release is tried as a fallback per the systemd os-release(5) specification. When neither is available or no PRETTY_NAME is found, the output is unchanged. Assisted-by: Claude:claude-opus-4-7 --- diff --git a/bin/named/os.c b/bin/named/os.c index 52e13680a92..0e95ad2ade5 100644 --- a/bin/named/os.c +++ b/bin/named/os.c @@ -918,12 +918,57 @@ named_os_tzset(void) { } #ifdef HAVE_UNAME -static char unamebuf[sizeof(struct utsname)]; +static char osreleasebuf[256]; +static char + unamebuf[sizeof(struct utsname) + sizeof(osreleasebuf) + sizeof(" ()")]; #else static const char unamebuf[] = { "unknown architecture" }; #endif static const char *unamep = NULL; +#ifdef HAVE_UNAME +static const char * +getosrelease(void) { + FILE *fp; + char line[sizeof(osreleasebuf)]; + char *value; + size_t len; + + fp = fopen("/etc/os-release", "r"); + if (fp == NULL) { + fp = fopen("/usr/lib/os-release", "r"); + } + if (fp == NULL) { + return ""; + } + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strncmp(line, "PRETTY_NAME=", 12) != 0) { + continue; + } + value = line + 12; + len = strlen(value); + if (len > 0 && value[len - 1] == '\n') { + value[--len] = '\0'; + } + if (len >= 2 && (*value == '"' || *value == '\'') && + value[len - 1] == *value) + { + value[len - 1] = '\0'; + value++; + } + if (*value == '\0') { + continue; + } + snprintf(osreleasebuf, sizeof(osreleasebuf), " (%s)", value); + fclose(fp); + return osreleasebuf; + } + fclose(fp); + return ""; +} +#endif /* ifdef HAVE_UNAME */ + static void getuname(void) { #ifdef HAVE_UNAME @@ -935,8 +980,8 @@ getuname(void) { return; } - snprintf(unamebuf, sizeof(unamebuf), "%s %s %s %s", uts.sysname, - uts.machine, uts.release, uts.version); + snprintf(unamebuf, sizeof(unamebuf), "%s %s %s %s%s", uts.sysname, + uts.machine, uts.release, uts.version, getosrelease()); #endif /* ifdef HAVE_UNAME */ unamep = unamebuf; }