summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-22 15:47:38 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-22 15:47:38 +0200
commitfb3d2b8fec7c705d8027e6967adae0c2a86acf31 (patch)
tree55c31f76b3660c219ff84e00bf2e2bf73d6980b1 /src
parent78ff1acdfe6a1f50d4ac62dc354c667999be0508 (diff)
hostname: if there's already a hostname set when PID 1 is invoked, don't complain
Diffstat (limited to 'src')
-rw-r--r--src/core/hostname-setup.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c
index 550d3c2113..03b5f472a5 100644
--- a/src/core/hostname-setup.c
+++ b/src/core/hostname-setup.c
@@ -47,7 +47,8 @@ static int read_and_strip_hostname(const char *path, char **hn) {
assert(path);
assert(hn);
- if ((r = read_one_line_file(path, &s)) < 0)
+ r = read_one_line_file(path, &s);
+ if (r < 0)
return r;
hostname_cleanup(s);
@@ -70,7 +71,8 @@ static int read_distro_hostname(char **hn) {
assert(hn);
- if (!(f = fopen(FILENAME, "re")))
+ f = fopen(FILENAME, "re");
+ if (!f)
return -errno;
for (;;) {
@@ -90,7 +92,8 @@ static int read_distro_hostname(char **hn) {
if (!startswith_no_case(s, "HOSTNAME="))
continue;
- if (!(k = strdup(s+9))) {
+ k = strdup(s+9);
+ if (!k) {
r = -ENOMEM;
goto finish;
}
@@ -129,8 +132,8 @@ static int read_hostname(char **hn) {
/* First, try to load the generic hostname configuration file,
* that we support on all distributions */
- if ((r = read_and_strip_hostname("/etc/hostname", hn)) < 0) {
-
+ r = read_and_strip_hostname("/etc/hostname", hn);
+ if (r < 0) {
if (r == -ENOENT)
return read_distro_hostname(hn);
@@ -144,10 +147,12 @@ int hostname_setup(void) {
int r;
char *b = NULL;
const char *hn = NULL;
+ bool enoent = false;
- if ((r = read_hostname(&b)) < 0) {
+ r = read_hostname(&b);
+ if (r < 0) {
if (r == -ENOENT)
- log_info("No hostname configured.");
+ enoent = true;
else
log_warning("Failed to read configured hostname: %s", strerror(-r));
@@ -161,7 +166,8 @@ int hostname_setup(void) {
char *old_hostname = NULL;
- if ((old_hostname = gethostname_malloc())) {
+ old_hostname = gethostname_malloc();
+ if (old_hostname) {
bool already_set;
already_set = old_hostname[0] != 0;
@@ -171,6 +177,9 @@ int hostname_setup(void) {
goto finish;
}
+ if (enoent)
+ log_info("No hostname configured.");
+
hn = "localhost";
}