util: introduce sethostname_idempotent

Function queries system hostname and applies changes only when necessary. Also,
migrate all client of sethostname to sethostname_idempotent while at it.
This commit is contained in:
Michal Sekletar
2014-10-27 10:37:46 +01:00
parent caa2f4c0c9
commit 605f81a896
5 changed files with 25 additions and 3 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ int hostname_setup(void) {
hn = "localhost";
}
if (sethostname(hn, strlen(hn)) < 0) {
if (sethostname_idempotent(hn) < 0) {
log_warning("Failed to set hostname to <%s>: %m", hn);
return -errno;
}