chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
391ade8
)
hostname: don't override the hostname with localhost if it is already set and /etc...
author
Lennart Poettering
<lennart@poettering.net>
Mon, 14 Mar 2011 17:05:52 +0000
(18:05 +0100)
committer
Lennart Poettering
<lennart@poettering.net>
Mon, 14 Mar 2011 17:05:52 +0000
(18:05 +0100)
src/hostname-setup.c
patch
|
blob
|
history
diff --git
a/src/hostname-setup.c
b/src/hostname-setup.c
index ef68d783953d3e2fc8894f8c6db996d058651258..e9869bb4dff4d64f6d8d1500bd956815fc38cd26 100644
(file)
--- a/
src/hostname-setup.c
+++ b/
src/hostname-setup.c
@@
-174,16
+174,36
@@
int hostname_setup(void) {
else
log_warning("Failed to read configured hostname: %s", strerror(-r));
else
log_warning("Failed to read configured hostname: %s", strerror(-r));
- hn =
"localhost"
;
+ hn =
NULL
;
} else
hn = b;
} else
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) {
log_warning("Failed to set hostname to <%s>: %m", hn);
r = -errno;
} else
log_info("Set hostname to <%s>.", hn);
if (sethostname(hn, strlen(hn)) < 0) {
log_warning("Failed to set hostname to <%s>: %m", hn);
r = -errno;
} else
log_info("Set hostname to <%s>.", hn);
+finish:
free(b);
return r;
free(b);
return r;