From f14d6810e0a08a1ed5e9f1a213d71f9a531ccf50 Mon Sep 17 00:00:00 2001 From: Maanya Goenka Date: Wed, 7 Jul 2021 18:28:20 -0700 Subject: [PATCH] manager: add a test flag to ignore dependencies The MANAGER_TEST_RUN_IGNORE_DEPENDENCIES flag was added in order to allow the caller to skip the recursive loading of dependency units when loading specific unit files. This includes the default dependencies, the specified dependencies, the slice. This will be used by systemd-analyze to allow checking individual unit files in isolation. --- src/core/manager.h | 11 ++++++----- src/core/unit.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/manager.h b/src/core/manager.h index 4ce43684746..1220c9fb161 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -128,11 +128,12 @@ typedef enum WatchdogType { #include "unit-name.h" typedef enum ManagerTestRunFlags { - MANAGER_TEST_NORMAL = 0, /* run normally */ - MANAGER_TEST_RUN_MINIMAL = 1 << 0, /* create basic data structures */ - MANAGER_TEST_RUN_BASIC = 1 << 1, /* interact with the environment */ - MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 2, /* also run env generators */ - MANAGER_TEST_RUN_GENERATORS = 1 << 3, /* also run unit generators */ + MANAGER_TEST_NORMAL = 0, /* run normally */ + MANAGER_TEST_RUN_MINIMAL = 1 << 0, /* create basic data structures */ + MANAGER_TEST_RUN_BASIC = 1 << 1, /* interact with the environment */ + MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 2, /* also run env generators */ + MANAGER_TEST_RUN_GENERATORS = 1 << 3, /* also run unit generators */ + MANAGER_TEST_RUN_IGNORE_DEPENDENCIES = 1 << 4, /* run while ignoring dependencies */ MANAGER_TEST_FULL = MANAGER_TEST_RUN_BASIC | MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS, } ManagerTestRunFlags; diff --git a/src/core/unit.c b/src/core/unit.c index 1b9fb079b4b..7c39e4d0f8c 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3053,6 +3053,9 @@ int unit_add_dependency( return 0; } + if (u->manager && FLAGS_SET(u->manager->test_run_flags, MANAGER_TEST_RUN_IGNORE_DEPENDENCIES)) + return 0; + /* Note that ordering a device unit after a unit is permitted since it allows to start its job * running timeout at a specific time. */ if (FLAGS_SET(a, UNIT_ATOM_BEFORE) && other->type == UNIT_DEVICE) { @@ -3176,6 +3179,9 @@ int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, boo if (r < 0) return r; + if (u->manager && FLAGS_SET(u->manager->test_run_flags, MANAGER_TEST_RUN_IGNORE_DEPENDENCIES)) + return 0; + r = manager_load_unit(u->manager, name, NULL, NULL, &other); if (r < 0) return r; @@ -3195,6 +3201,9 @@ int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency if (r < 0) return r; + if (u->manager && FLAGS_SET(u->manager->test_run_flags, MANAGER_TEST_RUN_IGNORE_DEPENDENCIES)) + return 0; + r = manager_load_unit(u->manager, name, NULL, NULL, &other); if (r < 0) return r; @@ -3312,6 +3321,9 @@ int unit_set_default_slice(Unit *u) { assert(u); + if (u->manager && FLAGS_SET(u->manager->test_run_flags, MANAGER_TEST_RUN_IGNORE_DEPENDENCIES)) + return 0; + if (UNIT_GET_SLICE(u)) return 0;