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);
assert(hn);
- if (!(f = fopen(FILENAME, "re")))
+ f = fopen(FILENAME, "re");
+ if (!f)
return -errno;
for (;;) {
if (!startswith_no_case(s, "HOSTNAME="))
continue;
- if (!(k = strdup(s+9))) {
+ k = strdup(s+9);
+ if (!k) {
r = -ENOMEM;
goto finish;
}
/* 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);
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));
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;
goto finish;
}
+ if (enoent)
+ log_info("No hostname configured.");
+
hn = "localhost";
}