struct pakfire_log_buffer log_ERROR;
struct pakfire_log_buffer log_DEBUG;
} buffers;
-
- // cgroup
- struct pakfire_cgroup* cgroup;
};
static int clone3(struct clone_args* args, size_t size) {
goto ERROR;
#endif /* ENABLE_DEBUG */
- // Setup a cgroup
- r = pakfire_cgroup_open(&ctx.cgroup, jail->pakfire, "jail/test1",
- PAKFIRE_CGROUP_ENABLE_ACCOUNTING);
- if (r)
- goto ERROR;
-
// Configure child process
struct clone_args args = {
.flags =
CLONE_NEWPID |
CLONE_NEWUSER |
CLONE_NEWUTS |
- CLONE_PIDFD |
- CLONE_INTO_CGROUP,
+ CLONE_PIDFD,
.exit_signal = SIGCHLD,
.pidfd = (long long unsigned int)&ctx.pidfd,
-
- // Clone into the new cgroup
- .cgroup = pakfire_cgroup_fd(ctx.cgroup),
};
+ // Launch the process in a cgroup (if requested)
+ if (jail->cgroup) {
+ args.flags |= CLONE_INTO_CGROUP;
+
+ // Clone into this cgroup
+ args.cgroup = pakfire_cgroup_fd(jail->cgroup);
+ }
+
// Fork this process
ctx.pid = clone3(&args, sizeof(args));
if (ctx.pid < 0) {
pakfire_jail_close_pipe(jail, ctx.pipes.log_ERROR);
pakfire_jail_close_pipe(jail, ctx.pipes.log_DEBUG);
- // Destroy cgroup
- if (ctx.cgroup) {
- pakfire_cgroup_destroy(ctx.cgroup);
- pakfire_cgroup_unref(ctx.cgroup);
- }
-
// Umount everything
if (!pakfire_on_root(jail->pakfire))
pakfire_umount_all(jail->pakfire);