Skip to content

Commit

Permalink
Fix cgroup bug, always print in ratemon_main
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanel committed May 8, 2024
1 parent 2e90fb6 commit a4d7aac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ratemon/runtime/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CFLAGS := -g -std=c17 -Wall -Wextra
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
# If this is not set with an environment variable, then hardcode it.
RM_IFACE ?= eno4
RM_CGROUP ?= /test_cg

CXX := g++
CXXFLAGS := -g -std=c++20 -Wall -Wextra
Expand Down Expand Up @@ -149,7 +150,7 @@ attach_tc_and_run: ratemon_main $(OUTPUT)/ratemon_tc.bpf.o
sudo tc filter add dev $(RM_IFACE) egress bpf direct-action obj $(OUTPUT)/ratemon_tc.bpf.o sec tc/egress
sudo bpftool map pin name flow_to_rwnd /sys/fs/bpf/flow_to_rwnd
sudo bpftool map pin name flow_to_win_sca /sys/fs/bpf/flow_to_win_scale
sudo ./ratemon_main || true
sudo RM_CGROUP=$(RM_CGROUP) ./ratemon_main || true
for id in `sudo bpftool struct_ops list | cut -d":" -f1`; do sudo bpftool struct_ops unregister id $$id; done
sudo tc filter del dev $(RM_IFACE) egress
sudo rm -f /sys/fs/bpf/flow_to_rwnd
Expand Down
25 changes: 13 additions & 12 deletions ratemon/runtime/c/ratemon_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <net/if.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "ratemon.h"
Expand All @@ -35,16 +36,16 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format,
void sigint_handler(int signum) {
switch (signum) {
case SIGINT:
RM_PRINTF("INFO: caught SIGINT\n");
printf("INFO: caught SIGINT\n");
run = false;
RM_PRINTF("Resetting old SIGINT handler\n");
printf("Resetting old SIGINT handler\n");
sigaction(SIGINT, &oldact, NULL);
break;
default:
RM_PRINTF("ERROR: caught signal %d\n", signum);
printf("ERROR: caught signal %d\n", signum);
break;
}
RM_PRINTF("INFO: re-raising signal %d\n", signum);
printf("INFO: re-raising signal %d\n", signum);
raise(signum);
}

Expand Down Expand Up @@ -120,14 +121,14 @@ int prepare_structops() {
return 0;
}

bool read_env_str(const char *key, char **dest) {
bool read_env_str(const char *key, char *dest) {
// Read an environment variable a char *.
char *val_str = getenv(key);
if (val_str == NULL) {
RM_PRINTF("ERROR: failed to query environment variable '%s'\n", key);
printf("ERROR: failed to query environment variable '%s'\n", key);
return false;
}
*dest = val_str;
strcpy(dest, val_str);
return true;
}

Expand All @@ -143,17 +144,17 @@ int main(int argc, char **argv) {
libbpf_set_print(libbpf_print_fn);

char cg_path[1024];
if (!read_env_str(RM_CGROUP_KEY, &cg_path)) {
RM_PRINTF("ERROR: failed to read cgroup path\n");
if (!read_env_str(RM_CGROUP_KEY, cg_path)) {
printf("ERROR: failed to read cgroup path\n");
goto cleanup;
}

if (prepare_sockops(cg_path)) {
RM_PRINTF("ERROR: failed to set up sockops\n");
printf("ERROR: failed to set up sockops\n");
goto cleanup;
}
if (prepare_structops()) {
RM_PRINTF("ERROR: failed to set up structops\n");
printf("ERROR: failed to set up structops\n");
goto cleanup;
}

Expand All @@ -174,5 +175,5 @@ int main(int argc, char **argv) {
bpf_link__destroy(structops_link);
ratemon_sockops_bpf__destroy(sockops_skel);
ratemon_structops_bpf__destroy(structops_skel);
return 1;
return 0;
}

0 comments on commit a4d7aac

Please sign in to comment.