3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
10 #include <linux/bpf.h>
14 #include "cgroup_helpers.h"
16 #define CGROUP_PATH "/my-cgroup"
18 int main(int argc, char **argv)
20 pid_t remote_pid, local_pid = getpid();
21 int cg2, idx = 0, rc = 0;
24 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
25 if (load_bpf_file(filename)) {
26 printf("%s", bpf_log_buf);
30 if (setup_cgroup_environment())
33 cg2 = create_and_get_cgroup(CGROUP_PATH);
38 if (bpf_map_update_elem(map_fd[0], &idx, &cg2, BPF_ANY)) {
39 log_err("Adding target cgroup to map");
43 if (join_cgroup(CGROUP_PATH))
47 * The installed helper program catched the sync call, and should
48 * write it to the map.
52 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
54 if (local_pid != remote_pid) {
56 "BPF Helper didn't write correct PID to map, but: %d\n",
61 /* Verify the negative scenario; leave the cgroup */
66 bpf_map_update_elem(map_fd[1], &idx, &remote_pid, BPF_ANY);
69 bpf_map_lookup_elem(map_fd[1], &idx, &remote_pid);
71 if (local_pid == remote_pid) {
72 fprintf(stderr, "BPF cgroup negative test did not work\n");
82 cleanup_cgroup_environment();