Merge pull request #13246 from keszybz/add-SystemdOptions-efi-variable
Add efi variable to augment /proc/cmdline
This commit is contained in:
@@ -615,6 +615,10 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-cgroup-setup.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-env-file.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "acpi-fpdt.h"
|
||||
#include "boot-timestamps.h"
|
||||
#include "efivars.h"
|
||||
#include "efi-loader.h"
|
||||
#include "log.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#include "macro.h"
|
||||
#include "missing_prctl.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static uid_t test_uid = -1;
|
||||
static gid_t test_gid = -1;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "cgroup-setup.h"
|
||||
#include "log.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_is_wanted_print(bool header) {
|
||||
_cleanup_free_ char *cmdline = NULL;
|
||||
|
||||
log_info("-- %s --", __func__);
|
||||
assert_se(proc_cmdline(&cmdline) >= 0);
|
||||
log_info("cmdline: %s", cmdline);
|
||||
if (header) {
|
||||
log_info(_CGROUP_HIERARCHY_);
|
||||
(void) system("findmnt -n /sys/fs/cgroup");
|
||||
}
|
||||
|
||||
log_info("is_unified_wanted() → %s", yes_no(cg_is_unified_wanted()));
|
||||
log_info("is_hybrid_wanted() → %s", yes_no(cg_is_hybrid_wanted()));
|
||||
log_info("is_legacy_wanted() → %s", yes_no(cg_is_legacy_wanted()));
|
||||
log_info(" ");
|
||||
}
|
||||
|
||||
static void test_is_wanted(void) {
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||
* explicitly specified. */
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_is_wanted_print(true);
|
||||
test_is_wanted_print(false); /* run twice to test caching */
|
||||
test_is_wanted();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -333,64 +333,15 @@ static void test_fd_is_cgroup_fs(void) {
|
||||
fd = safe_close(fd);
|
||||
}
|
||||
|
||||
static void test_is_wanted_print(bool header) {
|
||||
_cleanup_free_ char *cmdline = NULL;
|
||||
|
||||
log_info("-- %s --", __func__);
|
||||
assert_se(proc_cmdline(&cmdline) >= 0);
|
||||
log_info("cmdline: %s", cmdline);
|
||||
if (header) {
|
||||
|
||||
log_info(_CGROUP_HIERARCHY_);
|
||||
(void) system("findmnt -n /sys/fs/cgroup");
|
||||
}
|
||||
|
||||
log_info("is_unified_wanted() → %s", yes_no(cg_is_unified_wanted()));
|
||||
log_info("is_hybrid_wanted() → %s", yes_no(cg_is_hybrid_wanted()));
|
||||
log_info("is_legacy_wanted() → %s", yes_no(cg_is_legacy_wanted()));
|
||||
log_info(" ");
|
||||
}
|
||||
|
||||
static void test_is_wanted(void) {
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||
* explicitly specified. */
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
}
|
||||
|
||||
static void test_cg_tests(void) {
|
||||
int all, hybrid, systemd, r;
|
||||
|
||||
r = cg_unified_flush();
|
||||
r = cg_unified();
|
||||
if (r == -ENOMEDIUM) {
|
||||
log_notice_errno(r, "Skipping cg hierarchy tests: %m");
|
||||
return;
|
||||
}
|
||||
assert_se(r == 0);
|
||||
assert_se(r >= 0);
|
||||
|
||||
all = cg_all_unified();
|
||||
assert_se(IN_SET(all, 0, 1));
|
||||
@@ -477,9 +428,6 @@ int main(void) {
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_mask_supported());
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_is_cgroup_fs());
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_fd_is_cgroup_fs());
|
||||
test_is_wanted_print(true);
|
||||
test_is_wanted_print(false); /* run twice to test caching */
|
||||
test_is_wanted();
|
||||
test_cg_tests();
|
||||
test_cg_get_keyed_attribute();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cgroup-setup.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "cgroup-util.h"
|
||||
#include "condition.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "efivars.h"
|
||||
#include "efi-loader.h"
|
||||
#include "hostname-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "ima-util.h"
|
||||
@@ -124,7 +124,7 @@ static void test_condition_test_control_group_controller(void) {
|
||||
_cleanup_free_ char *controller_name = NULL;
|
||||
int r;
|
||||
|
||||
r = cg_unified_flush();
|
||||
r = cg_unified();
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping ConditionControlGroupController tests: %m");
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "test-helper.h"
|
||||
#include "random-util.h"
|
||||
#include "alloc-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "cgroup-setup.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int enter_cgroup_subroot(void) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "proc-cmdline.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static int obj;
|
||||
@@ -29,8 +30,9 @@ 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 some_arg_with_space='foo bar' and_one_more=\"zzz aaa\"") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=differnt") == 0);
|
||||
|
||||
/* Test if the override works */
|
||||
/* First test if the overrides for /proc/cmdline still work */
|
||||
_cleanup_free_ char *line = NULL, *value = NULL;
|
||||
assert_se(proc_cmdline(&line) >= 0);
|
||||
|
||||
@@ -44,6 +46,19 @@ static void test_proc_cmdline_override(void) {
|
||||
|
||||
assert_se(proc_cmdline_get_key("and_one_more", 0, &value) > 0 && streq_ptr(value, "zzz aaa"));
|
||||
value = mfree(value);
|
||||
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=") == 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);
|
||||
|
||||
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) {
|
||||
@@ -139,6 +154,24 @@ static void test_proc_cmdline_get_bool(void) {
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_bool("", &value) == -EINVAL);
|
||||
assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("foo_bar", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("foo-bar", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("bar-waldo", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("bar_waldo", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("x_y-z", &value) > 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("x-y-z", &value) > 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("x-y_z", &value) > 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("x_y_z", &value) > 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
|
||||
assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true);
|
||||
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_bool("", &value) == -EINVAL);
|
||||
assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false);
|
||||
@@ -212,27 +245,8 @@ static void test_proc_cmdline_key_startswith(void) {
|
||||
assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx"));
|
||||
}
|
||||
|
||||
static void test_runlevel_to_target(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
in_initrd_force(false);
|
||||
assert_se(streq_ptr(runlevel_to_target(NULL), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL));
|
||||
|
||||
in_initrd_force(true);
|
||||
assert_se(streq_ptr(runlevel_to_target(NULL), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("3"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_proc_cmdline_parse();
|
||||
test_proc_cmdline_override();
|
||||
@@ -244,7 +258,6 @@ int main(void) {
|
||||
test_proc_cmdline_get_key();
|
||||
test_proc_cmdline_get_bool();
|
||||
test_proc_cmdline_get_key_many();
|
||||
test_runlevel_to_target();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "path-lookup.h"
|
||||
#include "set.h"
|
||||
#include "special.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
#include "unit-file.h"
|
||||
@@ -75,11 +76,30 @@ static void test_unit_file_build_name_map(char **ids) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_runlevel_to_target(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
in_initrd_force(false);
|
||||
assert_se(streq_ptr(runlevel_to_target(NULL), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL));
|
||||
|
||||
in_initrd_force(true);
|
||||
assert_se(streq_ptr(runlevel_to_target(NULL), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("3"), NULL));
|
||||
assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_unit_validate_alias_symlink_and_warn();
|
||||
test_unit_file_build_name_map(strv_skip(argv, 1));
|
||||
test_runlevel_to_target();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user