From: Zbigniew Jędrzejewski-Szmek Date: Fri, 4 Dec 2020 18:17:45 +0000 (+0100) Subject: hostnamed: when hostname is set to existing value, suppress notifications X-Git-Tag: v248-rc1~491^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=efda832d4f0523cdb544a1a6baf862d0ec57da6f;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 10a5d31ccdc..5ada47459d0 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); }