chiark / gitweb /
sysusers: fix uninitialized warning
[elogind.git] / src / hostname / hostnamectl.c
index 94b4243b8d7191ff2012a9131652693c00b07d6f..267cd7401103b357816b9de4398ff2e0786b244c 100644 (file)
@@ -35,7 +35,7 @@
 #include "util.h"
 #include "spawn-polkit-agent.h"
 #include "build.h"
-#include "hwclock.h"
+#include "clock-util.h"
 #include "strv.h"
 #include "sd-id128.h"
 #include "virt.h"
@@ -67,6 +67,10 @@ typedef struct StatusInfo {
         char *pretty_hostname;
         char *icon_name;
         char *chassis;
+        char *kernel_name;
+        char *kernel_release;
+        char *os_pretty_name;
+        char *os_cpe_name;
         char *virtualization;
         char *architecture;
 } StatusInfo;
@@ -74,8 +78,6 @@ typedef struct StatusInfo {
 static void print_status_info(StatusInfo *i) {
         sd_id128_t mid = {}, bid = {};
         int r;
-        _cleanup_free_ char *pretty_name = NULL, *cpe_name = NULL;
-        struct utsname u;
 
         assert(i);
 
@@ -105,21 +107,14 @@ static void print_status_info(StatusInfo *i) {
         if (!isempty(i->virtualization))
                 printf("    Virtualization: %s\n", i->virtualization);
 
-        r = parse_env_file("/etc/os-release", NEWLINE,
-                           "PRETTY_NAME", &pretty_name,
-                           "CPE_NAME", &cpe_name,
-                           NULL);
-        if (r < 0)
-                log_warning("Failed to read /etc/os-release: %s", strerror(-r));
-
-        if (!isempty(pretty_name))
-                printf("  Operating System: %s\n", pretty_name);
+        if (!isempty(i->os_pretty_name))
+                printf("  Operating System: %s\n", i->os_pretty_name);
 
-        if (!isempty(cpe_name))
-                printf("       CPE OS Name: %s\n", cpe_name);
+        if (!isempty(i->os_cpe_name))
+                printf("       CPE OS Name: %s\n", i->os_cpe_name);
 
-        assert_se(uname(&u) >= 0);
-        printf("            Kernel: %s %s\n", u.sysname, u.release);
+        if (!isempty(i->kernel_name) && !isempty(i->kernel_release))
+                printf("            Kernel: %s %s\n", i->kernel_name, i->kernel_release);
 
         if (!isempty(i->architecture))
                 printf("      Architecture: %s\n", i->architecture);
@@ -162,6 +157,10 @@ static int show_all_names(sd_bus *bus) {
                 { "PrettyHostname", "s", NULL, offsetof(StatusInfo, pretty_hostname) },
                 { "IconName",       "s", NULL, offsetof(StatusInfo, icon_name) },
                 { "Chassis",        "s", NULL, offsetof(StatusInfo, chassis) },
+                { "KernelName",     "s", NULL, offsetof(StatusInfo, kernel_name) },
+                { "KernelRelease",     "s", NULL, offsetof(StatusInfo, kernel_release) },
+                { "OperatingSystemPrettyName",     "s", NULL, offsetof(StatusInfo, os_pretty_name) },
+                { "OperatingSystemCPEName",        "s", NULL, offsetof(StatusInfo, os_cpe_name) },
                 {}
         };
 
@@ -195,6 +194,10 @@ fail:
         free(info.pretty_hostname);
         free(info.icon_name);
         free(info.chassis);
+        free(info.kernel_name);
+        free(info.kernel_release);
+        free(info.os_pretty_name);
+        free(info.os_cpe_name);
         free(info.virtualization);
         free(info.architecture);