Merge pull request #10742 from poettering/c-utf8

default to C.UTF-8 locale, and many improvements to env var file parsing/kernel cmdline parsing
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-11-15 12:47:17 +01:00
committed by GitHub
43 changed files with 404 additions and 329 deletions
+7 -8
View File
@@ -55,7 +55,7 @@ static void test_parse_env_file(void) {
fflush(f);
fclose(f);
r = load_env_file(NULL, t, NULL, &a);
r = load_env_file(NULL, t, &a);
assert_se(r >= 0);
STRV_FOREACH(i, a)
@@ -82,7 +82,7 @@ static void test_parse_env_file(void) {
}
r = parse_env_file(
NULL, t, NULL,
NULL, t,
"one", &one,
"two", &two,
"three", &three,
@@ -92,8 +92,7 @@ static void test_parse_env_file(void) {
"seven", &seven,
"eight", &eight,
"export nine", &nine,
"ten", &ten,
NULL);
"ten", &ten);
assert_se(r >= 0);
@@ -128,7 +127,7 @@ static void test_parse_env_file(void) {
r = write_env_file(p, a);
assert_se(r >= 0);
r = load_env_file(NULL, p, NULL, &b);
r = load_env_file(NULL, p, &b);
assert_se(r >= 0);
}
@@ -157,7 +156,7 @@ static void test_parse_multiline_env_file(void) {
fflush(f);
fclose(f);
r = load_env_file(NULL, t, NULL, &a);
r = load_env_file(NULL, t, &a);
assert_se(r >= 0);
STRV_FOREACH(i, a)
@@ -176,7 +175,7 @@ static void test_parse_multiline_env_file(void) {
r = write_env_file(p, a);
assert_se(r >= 0);
r = load_env_file(NULL, p, NULL, &b);
r = load_env_file(NULL, p, &b);
assert_se(r >= 0);
}
@@ -467,7 +466,7 @@ static void test_load_env_file_pairs(void) {
f = fdopen(fd, "r");
assert_se(f);
r = load_env_file_pairs(f, fn, NULL, &l);
r = load_env_file_pairs(f, fn, &l);
assert_se(r >= 0);
assert_se(strv_length(l) == 14);
+44 -6
View File
@@ -28,15 +28,22 @@ static void test_proc_cmdline_parse(void) {
static void test_proc_cmdline_override(void) {
log_info("/* %s */", __func__);
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm") == 0);
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm some_arg_with_space='foo bar' and_one_more=\"zzz aaa\"") == 0);
/* Test if the override works */
_cleanup_free_ char *line = NULL, *value = NULL;
assert_se(proc_cmdline(&line) >= 0);
/* Test if parsing makes uses of the override */
assert_se(streq(line, "foo_bar=quux wuff-piep=tuet zumm"));
assert_se(streq(line, "foo_bar=quux wuff-piep=tuet zumm some_arg_with_space='foo bar' and_one_more=\"zzz aaa\""));
assert_se(proc_cmdline_get_key("foo_bar", 0, &value) > 0 && streq_ptr(value, "quux"));
value = mfree(value);
assert_se(proc_cmdline_get_key("some_arg_with_space", 0, &value) > 0 && streq_ptr(value, "foo bar"));
value = mfree(value);
assert_se(proc_cmdline_get_key("and_one_more", 0, &value) > 0 && streq_ptr(value, "zzz aaa"));
value = mfree(value);
}
static int parse_item_given(const char *key, const char *value, void *data) {
@@ -50,6 +57,10 @@ static int parse_item_given(const char *key, const char *value, void *data) {
assert_se(streq(value, "quux"));
else if (streq(key, "wuff-piep"))
assert_se(streq(value, "tuet "));
else if (streq(key, "space"))
assert_se(streq(value, "x y z"));
else if (streq(key, "miepf"))
assert_se(streq(value, "uuu"));
else if (in_initrd() && *strip && streq(key, "zumm"))
assert_se(!value);
else if (in_initrd() && !*strip && streq(key, "rd.zumm"))
@@ -67,13 +78,12 @@ static void test_proc_cmdline_given(bool flip_initrd) {
in_initrd_force(!in_initrd());
bool t = true, f = false;
assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm",
assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm space='x y z' miepf=\"uuu\"",
parse_item_given, &t, PROC_CMDLINE_STRIP_RD_PREFIX) >= 0);
assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm",
assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm space='x y z' miepf=\"uuu\"",
parse_item_given, &f, 0) >= 0);
if (flip_initrd)
in_initrd_force(!in_initrd());
}
@@ -82,7 +92,7 @@ static void test_proc_cmdline_get_key(void) {
_cleanup_free_ char *value = NULL;
log_info("/* %s */", __func__);
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm") == 0);
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm spaaace='ö ü ß' ticks=\"''\"") == 0);
assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL);
assert_se(proc_cmdline_get_key("abc", 0, NULL) == 0);
@@ -114,6 +124,11 @@ static void test_proc_cmdline_get_key(void) {
assert_se(proc_cmdline_get_key("zumm", 0, &value) == 0 && value == NULL);
assert_se(proc_cmdline_get_key("zumm", PROC_CMDLINE_VALUE_OPTIONAL, &value) > 0 && value == NULL);
assert_se(proc_cmdline_get_key("zumm", 0, NULL) > 0);
assert_se(proc_cmdline_get_key("spaaace", 0, &value) > 0 && streq_ptr(value, "ö ü ß"));
value = mfree(value);
assert_se(proc_cmdline_get_key("ticks", 0, &value) > 0 && streq_ptr(value, "''"));
}
static void test_proc_cmdline_get_bool(void) {
@@ -135,6 +150,28 @@ static void test_proc_cmdline_get_bool(void) {
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
}
static void test_proc_cmdline_get_key_many(void) {
_cleanup_free_ char *value1 = NULL, *value2 = NULL, *value3 = NULL, *value4 = NULL, *value5 = NULL, *value6 = NULL;
log_info("/* %s */", __func__);
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm SPACE='one two' doubleticks=\" aaa aaa \"") == 0);
assert_se(proc_cmdline_get_key_many(0,
"wuff-piep", &value3,
"foo_bar", &value1,
"idontexist", &value2,
"zumm", &value4,
"SPACE", &value5,
"doubleticks", &value6) == 4);
assert_se(streq_ptr(value1, "quux"));
assert_se(!value2);
assert_se(streq_ptr(value3, "tuet"));
assert_se(!value4);
assert_se(streq_ptr(value5, "one two"));
assert_se(streq_ptr(value6, " aaa aaa "));
}
static void test_proc_cmdline_key_streq(void) {
log_info("/* %s */", __func__);
@@ -199,6 +236,7 @@ int main(void) {
test_proc_cmdline_key_startswith();
test_proc_cmdline_get_key();
test_proc_cmdline_get_bool();
test_proc_cmdline_get_key_many();
test_runlevel_to_target();
return 0;
+5 -5
View File
@@ -531,7 +531,7 @@ static void test_load_env_file_1(void) {
assert_se(fd >= 0);
assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
r = load_env_file(NULL, name, NULL, &data);
r = load_env_file(NULL, name, &data);
assert_se(r == 0);
assert_se(streq(data[0], "a=a"));
assert_se(streq(data[1], "b=bc"));
@@ -553,7 +553,7 @@ static void test_load_env_file_2(void) {
assert_se(fd >= 0);
assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
r = load_env_file(NULL, name, NULL, &data);
r = load_env_file(NULL, name, &data);
assert_se(r == 0);
assert_se(streq(data[0], "a=a"));
assert_se(data[1] == NULL);
@@ -570,7 +570,7 @@ static void test_load_env_file_3(void) {
assert_se(fd >= 0);
assert_se(write(fd, env_file_3, sizeof(env_file_3)) == sizeof(env_file_3));
r = load_env_file(NULL, name, NULL, &data);
r = load_env_file(NULL, name, &data);
assert_se(r == 0);
assert_se(data == NULL);
}
@@ -585,7 +585,7 @@ static void test_load_env_file_4(void) {
assert_se(fd >= 0);
assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));
r = load_env_file(NULL, name, NULL, &data);
r = load_env_file(NULL, name, &data);
assert_se(r == 0);
assert_se(streq(data[0], "HWMON_MODULES=coretemp f71882fg"));
assert_se(streq(data[1], "MODULE_0=coretemp"));
@@ -604,7 +604,7 @@ static void test_load_env_file_5(void) {
assert_se(fd >= 0);
assert_se(write(fd, env_file_5, sizeof(env_file_5)) == sizeof(env_file_5));
r = load_env_file(NULL, name, NULL, &data);
r = load_env_file(NULL, name, &data);
assert_se(r == 0);
assert_se(streq(data[0], "a="));
assert_se(streq(data[1], "b="));