1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2016 Sargun Dhillon <sargun@sargun.me>
11 #include "cgroup_helpers.h"
13 #define CGROUP_PATH "/my-cgroup"
15 int main(int argc, char **argv)
17 pid_t remote_pid, local_pid = getpid();
18 int cg2, idx = 0, rc = 0;
21 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
22 if (load_bpf_file(filename)) {
23 printf("%s", bpf_log_buf);
27 if (setup_cgroup_environment())
30 cg2 = create_and_get_cgroup(CGROUP_PATH);
35 if (bpf_map_update_elem(map_fd[0], &idx, &cg2, BPF_ANY)) {
36 log_err("Adding target cgroup to map");
40 if (join_cgroup(CGROUP_PATH))
44 * The installed helper program catched the sync call, and should
45 * write it to the map.
49 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
51 if (local_pid != remote_pid) {
53 "BPF Helper didn't write correct PID to map, but: %d\n",
58 /* Verify the negative scenario; leave the cgroup */
63 bpf_map_update_elem(map_fd[1], &idx, &remote_pid, BPF_ANY);
66 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
68 if (local_pid == remote_pid) {
69 fprintf(stderr, "BPF cgroup negative test did not work\n");
79 cleanup_cgroup_environment();