From: Daan De Meyer Date: Sun, 21 Apr 2024 16:31:53 +0000 (+0200) Subject: test: Don't allocate scope if already running in unit with delegated cgroup X-Git-Tag: v256-rc1~87^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F32387%2Fhead;p=thirdparty%2Fsystemd.git test: Don't allocate scope if already running in unit with delegated cgroup If we're already running in a unit with delegation turned on, let's skip allocation of a scope unit and cgroup subroot. This allows journald to correctly attribute the logs of all subprocesses spawned by tests such as test-execute to the test-execute service when the test is running in a service. --- diff --git a/src/basic/log.c b/src/basic/log.c index 6faa6ad4fce..0d740c675ec 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -256,7 +256,7 @@ fail: return r; } -static bool stderr_is_journal(void) { +bool stderr_is_journal(void) { _cleanup_free_ char *w = NULL; const char *e; uint64_t dev, ino; diff --git a/src/basic/log.h b/src/basic/log.h index 6df164e06f7..726f035cfca 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -85,6 +85,7 @@ int log_show_tid_from_string(const char *e); assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1); #define PROJECT_FILE (&__FILE__[STRLEN(RELATIVE_SOURCE_PATH) + 1]) +bool stderr_is_journal(void); int log_open(void); void log_close(void); void log_forget_fds(void); diff --git a/src/shared/tests.c b/src/shared/tests.c index a0b1472d898..9169513e09c 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -189,12 +189,16 @@ static int allocate_scope(void) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - _cleanup_free_ char *scope = NULL; + _cleanup_free_ char *scope = NULL, *cgroup_root = NULL; const char *object; int r; /* Let's try to run this test in a scope of its own, with delegation turned on, so that PID 1 doesn't * interfere with our cgroup management. */ + if (cg_pid_get_path(NULL, 0, &cgroup_root) >= 0 && cg_is_delegated(cgroup_root) && stderr_is_journal()) { + log_debug("Already running as a unit with delegated cgroup, not allocating a cgroup subroot."); + return 0; + } r = sd_bus_default_system(&bus); if (r < 0)