summaryrefslogtreecommitdiffstats
path: root/src/test/test-hostname-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-15 11:50:55 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-22 20:10:55 +0100
commit05c6f341b1fc18f59293d115bb4cbee94f8bf3a1 (patch)
tree8897db9c1fa8b9b30dac251744b7d31b75988779 /src/test/test-hostname-util.c
parentbasic/os-util: make the sentinel implicit (diff)
downloadsystemd-05c6f341b1fc18f59293d115bb4cbee94f8bf3a1.tar.xz
systemd-05c6f341b1fc18f59293d115bb4cbee94f8bf3a1.zip
Allow the fallback hostname to be overriden using an environment variable
See https://bugzilla.redhat.com/show_bug.cgi?id=1893417 for the back story: the fallback hostname matters a lot in certain environments. Right now the only way to configure the fallback hostname is by recompiling systemd, which is obviously problematic in case when the fallback hostname shall differ between different editions of the same distro that share a single compiled rpm. By making this overridable through an envvar, we're providing an escape hatch without making this a top-level api. Later on a way to set this through os-release is added, but I think the approach with the variable is still useful. It it very convenient for testing, or to override settings only in a particular service, etc.
Diffstat (limited to 'src/test/test-hostname-util.c')
-rw-r--r--src/test/test-hostname-util.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/test/test-hostname-util.c b/src/test/test-hostname-util.c
index 24c8ed9e3b..6d62958d67 100644
--- a/src/test/test-hostname-util.c
+++ b/src/test/test-hostname-util.c
@@ -10,6 +10,8 @@
#include "tmpfile-util.h"
static void test_hostname_is_valid(void) {
+ log_info("/* %s */", __func__);
+
assert_se(hostname_is_valid("foobar", 0));
assert_se(hostname_is_valid("foobar.com", 0));
assert_se(!hostname_is_valid("foobar.com.", 0));
@@ -49,6 +51,8 @@ static void test_hostname_is_valid(void) {
static void test_hostname_cleanup(void) {
char *s;
+ log_info("/* %s */", __func__);
+
s = strdupa("foobar");
assert_se(streq(hostname_cleanup(s), "foobar"));
s = strdupa("foobar.com");
@@ -94,6 +98,8 @@ static void test_hostname_cleanup(void) {
static void test_hostname_malloc(void) {
_cleanup_free_ char *h = NULL, *l = NULL;
+ log_info("/* %s */", __func__);
+
assert_se(h = gethostname_malloc());
log_info("hostname_malloc: \"%s\"", h);
@@ -101,21 +107,27 @@ static void test_hostname_malloc(void) {
log_info("hostname_short_malloc: \"%s\"", l);
}
-static void test_fallback_hostname(void) {
+static void test_default_hostname(void) {
+ log_info("/* %s */", __func__);
+
if (!hostname_is_valid(FALLBACK_HOSTNAME, 0)) {
log_error("Configured fallback hostname \"%s\" is not valid.", FALLBACK_HOSTNAME);
exit(EXIT_FAILURE);
}
+
+ _cleanup_free_ char *n = get_default_hostname();
+ assert_se(n);
+ log_info("get_default_hostname: \"%s\"", n);
+ assert_se(hostname_is_valid(n, 0));
}
int main(int argc, char *argv[]) {
- test_setup_logging(LOG_INFO);
+ test_setup_logging(LOG_DEBUG);
test_hostname_is_valid();
test_hostname_cleanup();
test_hostname_malloc();
-
- test_fallback_hostname();
+ test_default_hostname();
return 0;
}