hostnamed.c revision 102d8f8169427cb68cdebf5ee0f0e07788e9c2b2
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek This file is part of systemd.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Copyright 2011 Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek (at your option) any later version.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
f4f15635ec05293ffcc83a5b39f624bbabbd8fd0Lennart Poetteringtypedef struct Context {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek for (p = 0; p < _PROP_MAX; p++) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringstatic void context_free(Context *c, sd_bus *bus) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering bus_verify_polkit_async_registry_free(bus, c->polkit_registry);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringstatic int context_read_data(Context *c) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek c->data[PROP_HOSTNAME] = gethostname_malloc();
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering r = read_one_line_file("/etc/hostname", &c->data[PROP_STATIC_HOSTNAME]);
e150e82097211f09b911c7784a89ef9efed713caMichał Bartoszkiewicz if (r < 0 && r != -ENOENT)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = parse_env_file("/etc/machine-info", NEWLINE,
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME],
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputo if (r < 0 && r != -ENOENT)
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstatic bool check_nss(void) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering dl = dlopen("libnss_myhostname.so.2", RTLD_LAZY);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer return true;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstatic bool valid_chassis(const char *chassis) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstatic const char* fallback_chassis(void) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek v = detect_virtualization(NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return "container";
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = read_one_line_file("/sys/firmware/acpi/pm_profile", &type);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* We only list the really obvious cases here as the ACPI data
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * is not really super reliable.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * See the ACPI 5.0 Spec Section 5.2.9.1 for details:
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "desktop";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "laptop";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "server";
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek return "tablet";
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek r = read_one_line_file("/sys/class/dmi/id/chassis_type", &type);
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek /* We only list the really obvious cases here. The DMI data is
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek unreliable enough, so let's not do any additional guesswork
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek See the SMBIOS Specification 2.7.1 section 7.4.1 for
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek details about the values listed here:
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "desktop";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "laptop";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "handset";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return "server";
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstatic char* context_fallback_icon_name(Context *c) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return strappend("computer-", c->data[PROP_CHASSIS]);
5c3bde3fa8613e09e694198862ea9038566af422Zbigniew Jędrzejewski-Szmek return strappend("computer-", chassis);
34c10968cbe3b5591b3c0ce225b8694edd9709d0Lennart Poetteringstatic int context_write_data_hostname(Context *c) {
5c3bde3fa8613e09e694198862ea9038566af422Zbigniew Jędrzejewski-Szmek if (isempty(c->data[PROP_HOSTNAME]))
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputostatic int context_write_data_static_hostname(Context *c) {
089ed40bf4b1df0408c9123f7dfcaa23768668f5Vito Caputo return write_string_file_atomic_label("/etc/hostname", c->data[PROP_STATIC_HOSTNAME]);
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputostatic int context_write_data_other(Context *c) {
e167d7fd8d5fe918b6d675e16aeca2c43398a5b2Lennart Poettering [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = load_env_file("/etc/machine-info", NULL, &l);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (r < 0 && r != -ENOENT)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek for (p = 2; p < _PROP_MAX; p++) {
f7dc3ab9f43b67abcbd34062b9352ab42debec49Lennart Poettering if (asprintf(&t, "%s=%s", name[p], strempty(c->data[p])) < 0) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (unlink("/etc/machine-info") < 0)
089ed40bf4b1df0408c9123f7dfcaa23768668f5Vito Caputo r = write_env_file_label("/etc/machine-info", l);
ea69bd41c5923f4f278a09bb7d8cb1abcfa122e1Lennart Poettering name = n = context_fallback_icon_name(c);
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek r = sd_bus_message_append(reply, "s", name);
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek r = sd_bus_message_append(reply, "s", name);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk r = sd_bus_message_read(m, "sb", &name, &interactive);
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk return sd_bus_reply_method_errno(bus, m, r, NULL);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return sd_bus_reply_method_errorf(bus, m, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return sd_bus_reply_method_return(bus, m, NULL);
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-hostname", interactive, &error, method_set_hostname, c);
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk return sd_bus_reply_method_errno(bus, m, r, &error);
ea69bd41c5923f4f278a09bb7d8cb1abcfa122e1Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek log_error("Failed to set host name: %s", strerror(-r));
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return sd_bus_reply_method_errnof(bus, m, r, "Failed to set hostname: %s", strerror(-r));
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering log_info("Changed host name to '%s'", strna(c->data[PROP_HOSTNAME]));
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "Hostname", NULL);
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek return sd_bus_reply_method_return(bus, m, NULL);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstatic int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek r = sd_bus_message_read(m, "sb", &name, &interactive);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return sd_bus_reply_method_errno(bus, m, r, NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME]))
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return sd_bus_reply_method_return(bus, m, NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-static-hostname", interactive, &error, method_set_static_hostname, c);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return sd_bus_reply_method_errno(bus, m, r, &error);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek free(c->data[PROP_STATIC_HOSTNAME]);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering return sd_bus_reply_method_errorf(bus, m, SD_BUS_ERROR_INVALID_ARGS, "Invalid static hostname '%s'", name);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering r = context_write_data_static_hostname(c);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering log_error("Failed to write static host name: %s", strerror(-r));
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering return sd_bus_reply_method_errnof(bus, m, r, "Failed to set static hostname: %s", strerror(-r));
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering log_info("Changed static host name to '%s'", strna(c->data[PROP_STATIC_HOSTNAME]));
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering return sd_bus_reply_method_return(bus, m, NULL);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poetteringstatic int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop, sd_bus_message_handler_t cb) {
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering r = sd_bus_message_read(m, "sb", &name, &interactive);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering return sd_bus_reply_method_errno(bus, m, r, NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (streq_ptr(name, c->data[prop]))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return sd_bus_reply_method_return(bus, m, NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Since the pretty hostname should always be changed at the
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * same time as the static one, use the same policy action for
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = bus_verify_polkit_async(bus, &c->polkit_registry, m, prop == PROP_PRETTY_HOSTNAME ?
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek "org.freedesktop.hostname1.set-static-hostname" :
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek "org.freedesktop.hostname1.set-machine-info", interactive, &error, cb, c);
2678031a179a9b91fc799f8ef951a548c66c4b49Lennart Poettering return sd_bus_reply_method_errno(bus, m, r, &error);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* The icon name might ultimately be used as file
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * name, so better be safe than sorry */
fa6ac76083b8ffc1309876459f54f9f0e2843731Lennart Poettering if (prop == PROP_ICON_NAME && !filename_is_safe(name))
fa6ac76083b8ffc1309876459f54f9f0e2843731Lennart Poettering return sd_bus_reply_method_errorf(bus, m, SD_BUS_ERROR_INVALID_ARGS, "Invalid icon name '%s'", name);
2678031a179a9b91fc799f8ef951a548c66c4b49Lennart Poettering (string_has_cc(name) || chars_intersect(name, "\t")))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return sd_bus_reply_method_errorf(bus, m, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (prop == PROP_CHASSIS && !valid_chassis(name))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return sd_bus_reply_method_errorf(bus, m, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = context_write_data_other(c);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek log_error("Failed to write machine info: %s", strerror(-r));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return sd_bus_reply_method_errnof(bus, m, r, "Failed to write machine info: %s", strerror(-r));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek prop == PROP_PRETTY_HOSTNAME ? "pretty host name" :
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->data[prop]));
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1",
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek prop == PROP_PRETTY_HOSTNAME ? "PrettyHostname" :
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek prop == PROP_CHASSIS ? "Chassis" : "IconName", NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return sd_bus_reply_method_return(bus, m, NULL);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int method_set_pretty_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return set_machine_info(userdata, bus, m, PROP_PRETTY_HOSTNAME, method_set_pretty_hostname);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int method_set_icon_name(sd_bus *bus, sd_bus_message *m, void *userdata) {
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk return set_machine_info(userdata, bus, m, PROP_ICON_NAME, method_set_icon_name);
8266e1c04db8cabe3c68510a0c1f07c09ecdb2e8Lennart Poetteringstatic int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdata) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_chassis);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic const sd_bus_vtable hostname_vtable[] = {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, 0),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, 0),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_hostname, 0),
8266e1c04db8cabe3c68510a0c1f07c09ecdb2e8Lennart Poettering SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, 0),
8266e1c04db8cabe3c68510a0c1f07c09ecdb2e8Lennart Poettering SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, 0),
8266e1c04db8cabe3c68510a0c1f07c09ecdb2e8Lennart Poettering SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, 0),
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek _cleanup_bus_unref_ sd_bus *bus = NULL;
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek log_error("Failed to get system bus connection: %s", strerror(-r));
d378991747d67fff1d4dc39e7fb2bc8f49f1b561Mirco Tischler r = sd_bus_add_object_vtable(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", hostname_vtable, c);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek log_error("Failed to register object: %s", strerror(-r));
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek r = sd_bus_request_name(bus, "org.freedesktop.hostname1", SD_BUS_NAME_DO_NOT_QUEUE);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering log_error("Failed to register name: %s", strerror(-r));
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek if (r != SD_BUS_NAME_PRIMARY_OWNER) {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek log_error("Failed to acquire name.");
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering log_error("Failed to attach bus to event loop: %s", strerror(-r));
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmekint main(int argc, char *argv[]) {
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek _cleanup_event_unref_ sd_event *event = NULL;
c2457105d76e3daf159f554a9bafb9751b23d756Holger Hans Peter Freyther _cleanup_bus_unref_ sd_bus *bus = NULL;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek log_error("This program takes no arguments.");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek log_warning("Warning: nss-myhostname is not installed. Changing the local hostname might make it unresolveable. Please install nss-myhostname!");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek log_error("This program takes no arguments.");
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden log_error("Failed to allocate event loop: %s", strerror(-r));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek r = connect_bus(&context, event, &bus);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering log_error("Failed to read timezone data: %s", strerror(-r));
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering log_error("Failed to run event loop: %s", strerror(-r));