Merge pull request #15745 from keszybz/one-more-specifier

Add %l as specifier for short hostname
This commit is contained in:
Lennart Poettering
2020-05-07 22:18:59 +02:00
committed by GitHub
29 changed files with 423 additions and 284 deletions
+22 -3
View File
@@ -31,6 +31,7 @@ bool hostname_is_set(void) {
char* gethostname_malloc(void) {
struct utsname u;
const char *s;
/* This call tries to return something useful, either the actual hostname
* or it makes something up. The only reason it might fail is OOM.
@@ -38,10 +39,28 @@ char* gethostname_malloc(void) {
assert_se(uname(&u) >= 0);
if (isempty(u.nodename) || streq(u.nodename, "(none)"))
return strdup(FALLBACK_HOSTNAME);
s = u.nodename;
if (isempty(s) || streq(s, "(none)"))
s = FALLBACK_HOSTNAME;
return strdup(u.nodename);
return strdup(s);
}
char* gethostname_short_malloc(void) {
struct utsname u;
const char *s;
/* Like above, but kills the FQDN part if present. */
assert_se(uname(&u) >= 0);
s = u.nodename;
if (isempty(s) || streq(s, "(none)") || s[0] == '.') {
s = FALLBACK_HOSTNAME;
assert(s[0] != '.');
}
return strndup(s, strcspn(s, "."));
}
int gethostname_strict(char **ret) {
+1
View File
@@ -9,6 +9,7 @@
bool hostname_is_set(void);
char* gethostname_malloc(void);
char* gethostname_short_malloc(void);
int gethostname_strict(char **ret);
bool valid_ldh_char(char c) _const_;