chiark / gitweb /
sysctl.d, binfmt.d, modules-load.d: switch to stacked config dirs in /lib, /etc,...
[elogind.git] / src / hostnamed.c
index 4ba1d4a57014a05ad882a9a56283db1f012063f8..8c0035a03774c17ee837ce7cb22bf3747cebbda6 100644 (file)
@@ -3,7 +3,7 @@
 /***
   This file is part of systemd.
 
-  Copyright 2010 Lennart Poettering
+  Copyright 2011 Lennart Poettering
 
   systemd is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
@@ -134,7 +134,13 @@ static const char* fallback_icon_name(void) {
 
         /* We only list the really obvious cases here. The DMI data is
            unreliable enough, so let's not do any additional guesswork
-           on top of that. */
+           on top of that.
+
+           See the SMBIOS Specification 2.7.1 section 7.4.1 for
+           details about the values listed here:
+
+           http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
+         */
 
         switch (t) {
 
@@ -150,6 +156,7 @@ static const char* fallback_icon_name(void) {
                 return "computer-laptop";
 
         case 0x11:
+        case 0x1C:
                 return "computer-server";
         }
 
@@ -185,6 +192,7 @@ static int write_data_static_hostname(void) {
 }
 
 static int write_data_other(void) {
+
         static const char * const name[_PROP_MAX] = {
                 [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
                 [PROP_ICON_NAME] = "ICON_NAME"
@@ -469,10 +477,12 @@ static DBusHandlerResult hostname_message_handler(
                         data[PROP_HOSTNAME] = h;
 
                         r = write_data_hostname();
-                        if (r < 0)
+                        if (r < 0) {
+                                log_error("Failed to set host name: %s", strerror(-r));
                                 return bus_send_error_reply(connection, message, NULL, r);
+                        }
 
-                        log_info("Changed host name to '%s'", data[PROP_HOSTNAME]);
+                        log_info("Changed host name to '%s'", strempty(data[PROP_HOSTNAME]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -521,10 +531,12 @@ static DBusHandlerResult hostname_message_handler(
                         }
 
                         r = write_data_static_hostname();
-                        if (r < 0)
+                        if (r < 0) {
+                                log_error("Failed to write static host name: %s", strerror(-r));
                                 return bus_send_error_reply(connection, message, NULL, r);
+                        }
 
-                        log_info("Changed static host name to '%s'", data[PROP_HOSTNAME]);
+                        log_info("Changed static host name to '%s'", strempty(data[PROP_HOSTNAME]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -575,10 +587,12 @@ static DBusHandlerResult hostname_message_handler(
                         }
 
                         r = write_data_other();
-                        if (r < 0)
+                        if (r < 0) {
+                                log_error("Failed to write machine info: %s", strerror(-r));
                                 return bus_send_error_reply(connection, message, NULL, r);
+                        }
 
-                        log_info("Changed %s to '%s'", k == PROP_PRETTY_HOSTNAME ? "pretty host name" : "icon name", data[k]);
+                        log_info("Changed %s to '%s'", k == PROP_PRETTY_HOSTNAME ? "pretty host name" : "icon name", strempty(data[k]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -666,6 +680,7 @@ int main(int argc, char *argv[]) {
 
         if (dbus_bus_request_name(bus, "org.freedesktop.hostname1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
                 log_error("Failed to register name on bus: %s", error.message);
+                r = -EEXIST;
                 goto finish;
         }