mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-01-17 17:46:20 +07:00
hostname: don't override the hostname with localhost if it is already set and /etc/hostname unset
This commit is contained in:
parent
391ade8606
commit
9bec0b1e8d
@ -174,16 +174,36 @@ int hostname_setup(void) {
|
|||||||
else
|
else
|
||||||
log_warning("Failed to read configured hostname: %s", strerror(-r));
|
log_warning("Failed to read configured hostname: %s", strerror(-r));
|
||||||
|
|
||||||
hn = "localhost";
|
hn = NULL;
|
||||||
} else
|
} else
|
||||||
hn = b;
|
hn = b;
|
||||||
|
|
||||||
|
if (!hn) {
|
||||||
|
/* Don't override the hostname if it is unset and not
|
||||||
|
* explicitly configured */
|
||||||
|
|
||||||
|
char *old_hostname = NULL;
|
||||||
|
|
||||||
|
if ((old_hostname = gethostname_malloc())) {
|
||||||
|
bool already_set;
|
||||||
|
|
||||||
|
already_set = old_hostname[0] != 0;
|
||||||
|
free(old_hostname);
|
||||||
|
|
||||||
|
if (already_set)
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
hn = "localhost";
|
||||||
|
}
|
||||||
|
|
||||||
if (sethostname(hn, strlen(hn)) < 0) {
|
if (sethostname(hn, strlen(hn)) < 0) {
|
||||||
log_warning("Failed to set hostname to <%s>: %m", hn);
|
log_warning("Failed to set hostname to <%s>: %m", hn);
|
||||||
r = -errno;
|
r = -errno;
|
||||||
} else
|
} else
|
||||||
log_info("Set hostname to <%s>.", hn);
|
log_info("Set hostname to <%s>.", hn);
|
||||||
|
|
||||||
|
finish:
|
||||||
free(b);
|
free(b);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
Loading…
Reference in New Issue
Block a user