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
(cherry picked from commit b5ca9d3372)
This commit is contained in:
Michal Nowak 2026-05-19 16:09:36 +00:00
parent d9640a3a0b
commit 20197027a1

View file

@ -913,12 +913,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
@ -930,8 +975,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;
}