Skip to content

Commit

Permalink
fix: race condition in EventsTrace ctx init
Browse files Browse the repository at this point in the history
  • Loading branch information
mmat11 committed Jan 11, 2024
1 parent a0d0a8f commit 83d2841
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion non-GPL/Events/EventsTrace/EventsTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>

#include <arpa/inet.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -109,6 +110,7 @@ uint64_t g_events_env = 0;
uint64_t g_features_env = 0;

bool g_print_features_init = 0;
bool g_features_printed = 0;
bool g_unbuffer_stdout = 0;
bool g_libbpf_verbose = 0;

Expand Down Expand Up @@ -859,6 +861,10 @@ static void out_network_connection_closed_event(struct ebpf_net_event *evt)

static int event_ctx_callback(struct ebpf_event_header *evt_hdr)
{
if (g_print_features_init)
while (!g_features_printed)
usleep(100000);

switch (evt_hdr->type) {
case EBPF_EVENT_PROCESS_FORK:
out_process_fork((struct ebpf_process_fork_event *)evt_hdr);
Expand Down Expand Up @@ -945,8 +951,10 @@ int main(int argc, char **argv)
goto out;
}

if (g_print_features_init)
if (g_print_features_init) {
print_init_msg(ebpf_event_ctx__get_features(ctx));
g_features_printed = 1;
}

while (!exiting) {
err = ebpf_event_ctx__next(ctx, 10);
Expand Down

0 comments on commit 83d2841

Please sign in to comment.