diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-12-04 19:17:45 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-12-16 11:02:17 +0100 |
commit | efda832d4f0523cdb544a1a6baf862d0ec57da6f (patch) | |
tree | 3fd18251480ba08e8a42f3c50042ce8e4421a75b /src/hostname/hostnamed.c | |
parent | shared/hostname-setup: leave the terminator byte alone (diff) | |
download | systemd-efda832d4f0523cdb544a1a6baf862d0ec57da6f.tar.xz systemd-efda832d4f0523cdb544a1a6baf862d0ec57da6f.zip |
hostnamed: when hostname is set to existing value, suppress notifications
When the hostname is set through network config or such, let's
optimize things a bit by suppressing the logs and dbus notifications.
Diffstat (limited to 'src/hostname/hostnamed.c')
-rw-r--r-- | src/hostname/hostnamed.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 10a5d31ccd..5ada47459d 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -359,8 +359,7 @@ static int context_update_kernel_hostname( return r; (void) nscd_flush_cache(STRV_MAKE("hosts")); - - return 0; + return r; /* 0 if no change, 1 if something was done */ } static int context_write_data_static_hostname(Context *c) { @@ -627,12 +626,16 @@ static int method_set_hostname(sd_bus_message *m, void *userdata, sd_bus_error * if (r < 0) { log_error_errno(r, "Failed to set hostname: %m"); return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %m"); + } else if (r == 0) + log_debug("Hostname was already set to <%s>.", name); + else { + log_info("Hostname set to <%s>", name); + + (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), + "/org/freedesktop/hostname1", "org.freedesktop.hostname1", + "Hostname", "HostnameSource", NULL); } - log_info("Changed hostname to '%s'", name); - - (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "Hostname", NULL); - return sd_bus_reply_method_return(m, NULL); } @@ -691,7 +694,8 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_ log_info("Changed static hostname to '%s'", strna(c->data[PROP_STATIC_HOSTNAME])); - (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL); + (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), + "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL); return sd_bus_reply_method_return(m, NULL); } |