Add %l as specifier for the hostname without any domain component

As described in #15603, it is a fairly common setup to use a fqdn as the
configured hostname. But it is often convenient to use just the actual
hostname, i.e. until the first dot. This adds support in tmpfiles, sysusers,
and unit files for %l which expands to that.

Fixes #15603.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-05-07 17:36:44 +02:00
parent eef4b80033
commit e97708fa3e
12 changed files with 72 additions and 14 deletions
+11
View File
@@ -140,6 +140,16 @@ static void test_read_etc_hostname(void) {
unlink(path);
}
static void test_hostname_malloc(void) {
_cleanup_free_ char *h = NULL, *l = NULL;
assert_se(h = gethostname_malloc());
log_info("hostname_malloc: \"%s\"", h);
assert_se(l = gethostname_short_malloc());
log_info("hostname_short_malloc: \"%s\"", l);
}
static void test_fallback_hostname(void) {
if (!hostname_is_valid(FALLBACK_HOSTNAME, false)) {
log_error("Configured fallback hostname \"%s\" is not valid.", FALLBACK_HOSTNAME);
@@ -154,6 +164,7 @@ int main(int argc, char *argv[]) {
test_hostname_is_valid();
test_hostname_cleanup();
test_read_etc_hostname();
test_hostname_malloc();
test_fallback_hostname();