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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user