]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Print OS platform in "named -V" 12055/head
authorMichal Nowak <mnowak@isc.org>
Tue, 19 May 2026 16:09:36 +0000 (16:09 +0000)
committerMichal Nowak <mnowak@isc.org>
Wed, 24 Jun 2026 15:05:35 +0000 (17:05 +0200)
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
bin/named/os.c

index 52e13680a9225bad27422db94344b3fc8d518b99..0e95ad2ade5c51cd61fbb9a035828c4701435bc7 100644 (file)
@@ -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;
 }