summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-04-19 06:07:06 +0200
committerLennart Poettering <lennart@poettering.net>2011-04-19 06:07:06 +0200
commit4f34ed54f854ff7eeede44cbb99a9fd27a5dce71 (patch)
treef0f8c1ad55bd2474956bcec208c5045e3c780a8a /src
parent73090dc815390f4fca4e3ed8a7e1d3806605daaa (diff)
hostnamed: improve error logging
Diffstat (limited to 'src')
-rw-r--r--src/hostnamed.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/hostnamed.c b/src/hostnamed.c
index d7e553e6d1..8c0035a037 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -192,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"
@@ -476,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",
@@ -528,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",
@@ -582,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",
@@ -673,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;
}