chiark / gitweb /
hostnamectl: add more really basic system info to the status output
[elogind.git] / src / hostname / hostnamectl.c
index de2f724..1d448bd 100644 (file)
@@ -25,6 +25,7 @@
 #include <getopt.h>
 #include <string.h>
 #include <sys/timex.h>
+#include <sys/utsname.h>
 
 #include "dbus-common.h"
 #include "util.h"
@@ -66,7 +67,9 @@ typedef struct StatusInfo {
 static void print_status_info(StatusInfo *i) {
         sd_id128_t mid, bid;
         int r;
-        const char *id;
+        const char *id = NULL;
+        _cleanup_free_ char *pretty_name = NULL, *cpe_name = NULL;
+        struct utsname u;
 
         assert(i);
 
@@ -90,8 +93,24 @@ static void print_status_info(StatusInfo *i) {
         if (r >= 0)
                 printf("           Boot ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(bid));
 
-        if (detect_virtualization(&id) >= 0)
+        if (detect_virtualization(&id) > 0)
                 printf("    Virtualization: %s\n", id);
+
+        r = parse_env_file("/etc/os-release", NEWLINE,
+                           "PRETTY_NAME", &pretty_name,
+                           "CPE_NAME", &cpe_name,
+                           NULL);
+
+        if (!isempty(pretty_name))
+                printf("  Operating System: %s\n", pretty_name);
+
+        if (!isempty(cpe_name))
+                printf("       CPE OS Name: %s\n", cpe_name);
+
+        assert_se(uname(&u) >= 0);
+        printf("            Kernel: %s %s\n"
+               "      Architecture: %s\n", u.sysname, u.release, u.machine);
+
 }
 
 static int status_property(const char *name, DBusMessageIter *iter, StatusInfo *i) {
@@ -303,19 +322,19 @@ static int set_icon_name(DBusConnection *bus, char **args, unsigned n) {
 
 static int help(void) {
 
-        printf("%s [OPTIONS...] {COMMAND} ...\n\n"
-               "Query or set system hostname.\n\n"
+        printf("%s [OPTIONS...] COMMAND ...\n\n"
+               "Query or change system hostname.\n\n"
                "  -h --help              Show this help\n"
                "     --version           Show package version\n"
-               "     --no-ask-password   Do not prompt for password\n"
                "     --transient         Only set transient hostname\n"
                "     --static            Only set static hostname\n"
                "     --pretty            Only set pretty hostname\n"
+               "     --no-ask-password   Do not prompt for password\n"
                "  -H --host=[USER@]HOST  Operate on remote host\n\n"
                "Commands:\n"
-               "  status                          Show current hostname settings\n"
-               "  set-hostname [NAME]             Set system hostname\n"
-               "  set-icon-name [NAME]            Set icon name for host\n",
+               "  status                 Show current hostname settings\n"
+               "  set-hostname NAME      Set system hostname\n"
+               "  set-icon-name NAME     Set icon name for host\n",
                program_invocation_short_name);
 
         return 0;
@@ -348,7 +367,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hp:as:H:P", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "hH:P", options, NULL)) >= 0) {
 
                 switch (c) {