r = read_hostname(&b);
if (r < 0) {
+ hn = NULL;
+
if (r == -ENOENT)
enoent = true;
else
log_warning("Failed to read configured hostname: %s", strerror(-r));
-
- hn = NULL;
} else
hn = b;
- if (!hn) {
- /* Don't override the hostname if it is unset and not
- * explicitly configured */
-
- char *old_hostname = NULL;
-
- old_hostname = gethostname_malloc();
- if (old_hostname) {
- bool already_set;
-
- already_set = old_hostname[0] != 0;
- free(old_hostname);
-
- if (already_set)
- goto finish;
- }
+ if (isempty(hn)) {
+ /* Don't override the hostname if it is already set
+ * and not explicitly configured */
+ if (hostname_is_set())
+ goto finish;
if (enoent)
log_info("No hostname configured.");
assert_se(uname(&u) >= 0);
- if (u.nodename[0])
+ if (!isempty(u.nodename) && !streq(u.nodename, "(none)"))
return strdup(u.nodename);
return strdup(u.sysname);
}
+bool hostname_is_set(void) {
+ struct utsname u;
+
+ assert_se(uname(&u) >= 0);
+
+ return !isempty(u.nodename) && !streq(u.nodename, "(none)");
+}
+
char* getlogname_malloc(void) {
uid_t uid;
long bufsize;
void sigset_add_many(sigset_t *ss, ...);
char* gethostname_malloc(void);
+bool hostname_is_set(void);
char* getlogname_malloc(void);
int getttyname_malloc(int fd, char **r);