Skip to content

Commit

Permalink
cgroup,setup: set CGROUP_PATH in setup program with full path to curr…
Browse files Browse the repository at this point in the history
…ent cgroup

It is useful for the setup program to be able to change or inspect the
cgroup directory of the spacetime process. The problem is that by the
time the setup program executes, bst will have pivoted into the cgroup
namespace, leaving it with no consistent way to know what the path of
that cgroup is.

This commit arranges for the path of the cgroup to be defined in the
CGROUP_PATH environment variable when the setup program executes.
  • Loading branch information
Snaipe committed Oct 27, 2023
1 parent a9d8455 commit 588d370
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ int enter(struct entry_settings *opts)

outer_helper_sync(&outer_helper);

/* Read the current cgroup before ns_enter_postfork; this allows us
to get the real path to the cgroup */
char cgroup_path[PATH_MAX];
if (!cgroup_read_current(cgroup_path)) {
errx(1, "could not determine current cgroup; are you using cgroups v2?");
}
ns_enter_postfork(namespaces, ns_len);

outer_helper_close(&outer_helper);
Expand Down Expand Up @@ -480,6 +486,7 @@ int enter(struct entry_settings *opts)
/* Set some extra useful environment */
setenv("ROOT", root, 1);
setenv("EXECUTABLE", opts->pathname, 1);
setenv("CGROUP_PATH", cgroup_path, 1);

extern char **environ;

Expand Down
3 changes: 3 additions & 0 deletions man/bst.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ The following environment variables are accessible to the setup program:
*EXECUTABLE*
Set to the executable name that will be executed after the setup is done.

*CGROUP_PATH*
Set to the path of the cgroup of the process that will be executed.

# NETWORKING

## Creating network interfaces
Expand Down

0 comments on commit 588d370

Please sign in to comment.