X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhostname%2Fhostnamectl.c;h=f8e1a811f8ccdce639145921c31e91c69e267980;hb=bd8f65387673e29f46136a4ed172097035002c23;hp=94b4243b8d7191ff2012a9131652693c00b07d6f;hpb=e9a2e453bbe3522db4341e4a2a49ae8aab8eb5a3;p=elogind.git diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 94b4243b8..f8e1a811f 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -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,11 @@ typedef struct StatusInfo { char *pretty_hostname; char *icon_name; char *chassis; + char *deployment; + char *kernel_name; + char *kernel_release; + char *os_pretty_name; + char *os_cpe_name; char *virtualization; char *architecture; } StatusInfo; @@ -74,8 +79,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); @@ -90,9 +93,11 @@ static void print_status_info(StatusInfo *i) { printf("Transient hostname: %s\n", i->hostname); printf(" Icon name: %s\n" - " Chassis: %s\n", + " Chassis: %s\n" + " Deployment: %s\n", strna(i->icon_name), - strna(i->chassis)); + strna(i->chassis), + strna(i->deployment)); r = sd_id128_get_machine(&mid); if (r >= 0) @@ -105,21 +110,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 +160,11 @@ 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) }, + { "Deployment", "s", NULL, offsetof(StatusInfo, deployment) }, + { "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 +198,11 @@ fail: free(info.pretty_hostname); free(info.icon_name); free(info.chassis); + free(info.deployment); + free(info.kernel_name); + free(info.kernel_release); + free(info.os_pretty_name); + free(info.os_cpe_name); free(info.virtualization); free(info.architecture); @@ -306,8 +314,14 @@ static int set_chassis(sd_bus *bus, char **args, unsigned n) { return set_simple_string(bus, "SetChassis", args[1]); } -static int help(void) { +static int set_deployment(sd_bus *bus, char **args, unsigned n) { + assert(args); + assert(n == 2); + + return set_simple_string(bus, "SetDeployment", args[1]); +} +static void help(void) { printf("%s [OPTIONS...] COMMAND ...\n\n" "Query or change system hostname.\n\n" " -h --help Show this help\n" @@ -322,10 +336,9 @@ static int help(void) { " status Show current hostname settings\n" " set-hostname NAME Set system hostname\n" " set-icon-name NAME Set icon name for host\n" - " set-chassis NAME Set chassis type for host\n", - program_invocation_short_name); - - return 0; + " set-chassis NAME Set chassis type for host\n" + " set-deployment NAME Set deployment environment for host\n" + , program_invocation_short_name); } static int parse_argv(int argc, char *argv[]) { @@ -355,12 +368,13 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) switch (c) { case 'h': - return help(); + help(); + return 0; case ARG_VERSION: puts(PACKAGE_STRING); @@ -399,7 +413,6 @@ static int parse_argv(int argc, char *argv[]) { default: assert_not_reached("Unhandled option"); } - } return 1; } @@ -420,6 +433,7 @@ static int hostnamectl_main(sd_bus *bus, int argc, char *argv[]) { { "set-hostname", EQUAL, 2, set_hostname }, { "set-icon-name", EQUAL, 2, set_icon_name }, { "set-chassis", EQUAL, 2, set_chassis }, + { "set-deployment", EQUAL, 2, set_deployment }, }; int left; @@ -483,7 +497,7 @@ static int hostnamectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, "");