diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-12-24 19:03:59 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-12-24 19:03:59 +0100 |
commit | 7871c8e9327e4e5b18de9d8081b0f32fa38c2c1f (patch) | |
tree | 56dea3f21fcc707ac392696697a50d18c21a09d5 /src/hostname/hostnamectl.c | |
parent | f9ea108e7c3544c03822277a1112a48dc62f6ed4 (diff) |
hostnamed: make chassis type configurable via /etc/machine-info
For many usecases it is useful to store the chassis type somewhere, and
/etc/machine-info sounds like a good place. Ideally we could always
detect the chassis type from firmware, but frequently that's not
available and in many embedded devices probably entirely unrealistic.
This patch adds a configurable setting CHASSIS= to /etc/machine-info and
exposes this via hostnamectl/hostnamed. hostnamed will guess the chassis
type from DMI if nothing is set explicitly. I also added support for
detecting it from ACPI, which should be more useful as ACPI 5.0 actually
knows a "tablet" chassis type, which neither DMI nor previous ACPI
versions knew.
This also enables DMI-based and ACPI-based detection for non-x86 systems
as ACPI is apparently coming to ARM platforms soon.
I tried to minimize the vocabulary of chassis types understood and
added: desktop, laptop, server, tablet, handset. This is much less than
either APCI or DMI know. If we need more types later on we can easily
add them.
Diffstat (limited to 'src/hostname/hostnamectl.c')
-rw-r--r-- | src/hostname/hostnamectl.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 265c7ecbfe..e38be89b37 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -63,6 +63,7 @@ typedef struct StatusInfo { const char *static_hostname; const char *pretty_hostname; const char *icon_name; + const char *chassis; } StatusInfo; static void print_status_info(StatusInfo *i) { @@ -82,9 +83,11 @@ static void print_status_info(StatusInfo *i) { strna(i->hostname)); printf(" Pretty hostname: %s\n" - " Icon name: %s\n", + " Icon name: %s\n" + " Chassis: %s\n", strna(i->pretty_hostname), - strna(i->icon_name)); + strna(i->icon_name), + strna(i->chassis)); r = sd_id128_get_machine(&mid); if (r >= 0) @@ -133,6 +136,8 @@ static int status_property(const char *name, DBusMessageIter *iter, StatusInfo * i->pretty_hostname = s; if (streq(name, "IconName")) i->icon_name = s; + if (streq(name, "Chassis")) + i->chassis = s; } break; } @@ -321,6 +326,28 @@ static int set_icon_name(DBusConnection *bus, char **args, unsigned n) { DBUS_TYPE_INVALID); } +static int set_chassis(DBusConnection *bus, char **args, unsigned n) { + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; + dbus_bool_t interactive = true; + + assert(args); + assert(n == 2); + + polkit_agent_open_if_enabled(); + + return bus_method_call_with_reply( + bus, + "org.freedesktop.hostname1", + "/org/freedesktop/hostname1", + "org.freedesktop.hostname1", + "SetChassis", + &reply, + NULL, + DBUS_TYPE_STRING, &args[1], + DBUS_TYPE_BOOLEAN, &interactive, + DBUS_TYPE_INVALID); +} + static int help(void) { printf("%s [OPTIONS...] COMMAND ...\n\n" @@ -335,7 +362,8 @@ static int help(void) { "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", + " 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; @@ -434,9 +462,10 @@ static int hostnamectl_main(DBusConnection *bus, int argc, char *argv[], DBusErr const int argc; int (* const dispatch)(DBusConnection *bus, char **args, unsigned n); } verbs[] = { - { "status", LESS, 1, show_status }, - { "set-hostname", EQUAL, 2, set_hostname }, - { "set-icon-name", EQUAL, 2, set_icon_name }, + { "status", LESS, 1, show_status }, + { "set-hostname", EQUAL, 2, set_hostname }, + { "set-icon-name", EQUAL, 2, set_icon_name }, + { "set-chassis", EQUAL, 2, set_chassis }, }; int left; |