Merge pull request #18704 from keszybz/fallback-hostame-override
Allow overriding of fallback hostname through envvar and os-release field
This commit is contained in:
@@ -349,27 +349,27 @@ static void test_config_parse(unsigned i, const char *s) {
|
||||
|
||||
switch (i) {
|
||||
case 0 ... 4:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, "1"));
|
||||
break;
|
||||
|
||||
case 5 ... 10:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, "1 2 3"));
|
||||
break;
|
||||
|
||||
case 11:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, "1\\\\ \\\\2"));
|
||||
break;
|
||||
|
||||
case 12:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, x1000("ABCD")));
|
||||
break;
|
||||
|
||||
case 13 ... 14:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, x1000("ABCD") " foobar"));
|
||||
break;
|
||||
|
||||
@@ -379,7 +379,7 @@ static void test_config_parse(unsigned i, const char *s) {
|
||||
break;
|
||||
|
||||
case 17:
|
||||
assert_se(r == 0);
|
||||
assert_se(r == 1);
|
||||
assert_se(streq(setting1, "2"));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -361,6 +361,19 @@ static void test_env_assignment_is_valid(void) {
|
||||
assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\""));
|
||||
}
|
||||
|
||||
static void test_putenv_dup(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(putenv_dup("A=a1", true) == 0);
|
||||
assert_se(streq(getenv("A"), "a1"));
|
||||
assert_se(putenv_dup("A=a1", true) == 0);
|
||||
assert_se(streq(getenv("A"), "a1"));
|
||||
assert_se(putenv_dup("A=a2", false) == 0);
|
||||
assert_se(streq(getenv("A"), "a1"));
|
||||
assert_se(putenv_dup("A=a2", true) == 0);
|
||||
assert_se(streq(getenv("A"), "a2"));
|
||||
}
|
||||
|
||||
static void test_setenv_systemd_exec_pid(void) {
|
||||
_cleanup_free_ char *saved = NULL;
|
||||
const char *e;
|
||||
@@ -416,6 +429,7 @@ int main(int argc, char *argv[]) {
|
||||
test_env_name_is_valid();
|
||||
test_env_value_is_valid();
|
||||
test_env_assignment_is_valid();
|
||||
test_putenv_dup();
|
||||
test_setenv_systemd_exec_pid();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -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