From 344de60901f0e3ce0d2f112b7be97fc6d0e2f071 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 21 May 2012 17:19:58 +0200 Subject: hostname-setup: also consider (Ε„one) an unset hostname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/util.c | 10 +++++++++- src/shared/util.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/shared') diff --git a/src/shared/util.c b/src/shared/util.c index ae0ce320ad..0234f3b483 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2949,12 +2949,20 @@ char* gethostname_malloc(void) { 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; diff --git a/src/shared/util.h b/src/shared/util.h index 3dce047b40..e727ee7389 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -337,6 +337,7 @@ void rename_process(const char name[8]); 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); -- cgit v1.2.3-54-g00ecf