return NULL;
}
+// Open a child cgroup
+int pakfire_cgroup_child(struct pakfire_cgroup** child,
+ struct pakfire_cgroup* cgroup, const char* name, int flags) {
+ char path[PATH_MAX];
+ int r;
+
+ // Join paths
+ r = pakfire_path_join(path, cgroup->path, name);
+ if (r < 0)
+ return 1;
+
+ // Open the child group
+ return pakfire_cgroup_open(child, cgroup->pakfire, path, flags);
+}
+
static int pakfire_cgroup_procs_callback(struct pakfire_cgroup* cgroup,
int (*callback)(struct pakfire_cgroup* cgroup, pid_t pid, void* data), void* data) {
int r = 0;
struct pakfire_cgroup* pakfire_cgroup_ref(struct pakfire_cgroup* cgroup);
struct pakfire_cgroup* pakfire_cgroup_unref(struct pakfire_cgroup* cgroup);
+int pakfire_cgroup_child(struct pakfire_cgroup** child,
+ struct pakfire_cgroup* cgroup, const char* name, int flags);
+
int pakfire_cgroup_enable_default_controllers(struct pakfire_cgroup* cgroup);
int pakfire_cgroup_destroy(struct pakfire_cgroup* cgroup);
struct pakfire_log_buffer log_ERROR;
struct pakfire_log_buffer log_DEBUG;
} buffers;
+
+ struct pakfire_cgroup* cgroup;
};
static int clone3(struct clone_args* args, size_t size) {
.pidfd = (long long unsigned int)&ctx.pidfd,
};
- // Launch the process in a cgroup (if requested)
+ // Launch the process in a cgroup that is a leaf of the configured cgroup
if (jail->cgroup) {
args.flags |= CLONE_INTO_CGROUP;
+#warning TODO randomize the name
+
+ // Create a temporary cgroup
+ r = pakfire_cgroup_child(&ctx.cgroup, jail->cgroup, "jail", 0);
+ if (r) {
+ ERROR(jail->pakfire, "Could not create cgroup for jail: %m\n");
+ goto ERROR;
+ }
+
// Clone into this cgroup
- args.cgroup = pakfire_cgroup_fd(jail->cgroup);
+ args.cgroup = pakfire_cgroup_fd(ctx.cgroup);
}
// Fork this process
}
ERROR:
+ // Destroy the temporary cgroup (if any)
+ if (ctx.cgroup) {
+ pakfire_cgroup_destroy(ctx.cgroup);
+ pakfire_cgroup_unref(ctx.cgroup);
+ }
+
// Close any file descriptors
pakfire_jail_close_pipe(jail, ctx.pipes.stdout);
pakfire_jail_close_pipe(jail, ctx.pipes.stderr);