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.
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+5
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user