2013-04-13 13:09:53 +02:00
|
|
|
From: Frederic Crozat <fcrozat@suse.com>
|
|
|
|
Date: Fri, 15 Feb 2013 16:04:39 +0000
|
|
|
|
Subject: handle /etc/HOSTNAME
|
|
|
|
|
|
|
|
(bnc#803653)
|
|
|
|
---
|
2013-04-26 18:25:08 +02:00
|
|
|
src/core/hostname-setup.c | 22 +++++++++++++++++-----
|
|
|
|
src/hostname/hostnamed.c | 12 +++++++++++-
|
|
|
|
2 files changed, 28 insertions(+), 6 deletions(-)
|
2013-04-13 13:09:53 +02:00
|
|
|
|
2013-04-26 18:25:08 +02:00
|
|
|
diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c
|
|
|
|
index ac508af..15d206c 100644
|
|
|
|
--- a/src/core/hostname-setup.c
|
|
|
|
+++ b/src/core/hostname-setup.c
|
|
|
|
@@ -61,12 +61,24 @@ int hostname_setup(void) {
|
|
|
|
|
|
|
|
r = read_and_strip_hostname("/etc/hostname", &b);
|
|
|
|
if (r < 0) {
|
|
|
|
- if (r == -ENOENT)
|
|
|
|
- enoent = true;
|
|
|
|
- else
|
|
|
|
+ if (r == -ENOENT) {
|
|
|
|
+ /* use SUSE fallback */
|
|
|
|
+ r = read_and_strip_hostname("/etc/HOSTNAME", &b);
|
|
|
|
+ if (r < 0) {
|
|
|
|
+ if (r == -ENOENT)
|
|
|
|
+ enoent = true;
|
|
|
|
+ else
|
|
|
|
+ log_warning("Failed to read configured hostname: %s", strerror(-r));
|
|
|
|
+ hn = NULL;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ hn = b;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
log_warning("Failed to read configured hostname: %s", strerror(-r));
|
|
|
|
-
|
|
|
|
- hn = NULL;
|
|
|
|
+ hn = NULL;
|
|
|
|
+ }
|
|
|
|
} else
|
|
|
|
hn = b;
|
|
|
|
|
2013-04-13 13:09:53 +02:00
|
|
|
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
|
2013-04-19 22:31:17 +02:00
|
|
|
index c7f454c..cfbd706 100644
|
2013-04-13 13:09:53 +02:00
|
|
|
--- a/src/hostname/hostnamed.c
|
|
|
|
+++ b/src/hostname/hostnamed.c
|
|
|
|
@@ -129,6 +129,10 @@ static int read_data(void) {
|
|
|
|
if (r < 0 && r != -ENOENT)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
+ r = read_one_line_file("/etc/HOSTNAME", &data[PROP_STATIC_HOSTNAME]);
|
|
|
|
+ if (r < 0 && r != -ENOENT)
|
|
|
|
+ return r;
|
|
|
|
+
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -283,6 +287,7 @@ static int write_data_hostname(void) {
|
|
|
|
|
|
|
|
static int write_data_static_hostname(void) {
|
|
|
|
|
|
|
|
+ int r;
|
|
|
|
if (isempty(data[PROP_STATIC_HOSTNAME])) {
|
|
|
|
|
|
|
|
if (unlink("/etc/hostname") < 0)
|
|
|
|
@@ -290,7 +295,12 @@ static int write_data_static_hostname(void) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-19 22:31:17 +02:00
|
|
|
- return write_string_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
|
2013-04-13 13:09:53 +02:00
|
|
|
+
|
2013-04-19 22:31:17 +02:00
|
|
|
+ r = write_string_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
|
2013-04-13 13:09:53 +02:00
|
|
|
+ if (!r) {
|
|
|
|
+ r = symlink_atomic("/etc/hostname", "/etc/HOSTNAME");
|
|
|
|
+ }
|
|
|
|
+ return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int write_data_other(void) {
|