Skip to content

Commit

Permalink
Be explicit about the dry run option
Browse files Browse the repository at this point in the history
  • Loading branch information
stanek-michal committed Aug 25, 2022
1 parent e1b80ff commit 0fddd9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion non-GPL/Events/EventsTrace/EventsTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ int main(int argc, char **argv)
if (g_features_autodetect)
ebpf_detect_system_features(&opts.features);

err = ebpf_event_ctx__new(&ctx, event_ctx_callback, opts);
err = ebpf_event_ctx__new(&ctx, event_ctx_callback, opts, 0);

if (err < 0) {
fprintf(stderr, "Could not create event context: %d %s\n", err, strerror(-err));
Expand Down
12 changes: 10 additions & 2 deletions non-GPL/Events/Lib/EbpfEvents.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ int ebpf_set_verbose_logging()

int ebpf_event_ctx__new(struct ebpf_event_ctx **ctx,
ebpf_event_handler_fn cb,
struct ebpf_event_ctx_opts opts)
struct ebpf_event_ctx_opts opts,
bool dry_run)
{
struct EventProbe_bpf *probe = NULL;
struct btf *btf = NULL;
Expand Down Expand Up @@ -469,8 +470,15 @@ int ebpf_event_ctx__new(struct ebpf_event_ctx **ctx,
if (err != 0)
goto out_destroy_probe;

if (!ctx)
if (dry_run) {
err = 0;
goto out_destroy_probe;
}

if (!ctx) {
err = -ENOENT;
goto out_destroy_probe;
}

*ctx = calloc(1, sizeof(struct ebpf_event_ctx));
if (*ctx == NULL) {
Expand Down
9 changes: 5 additions & 4 deletions non-GPL/Events/Lib/EbpfEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ int ebpf_detect_system_features(uint64_t *features);

/* Allocates a new context based on requested events and capabilities.
*
* If ctx is NULL, the function returns right after loading and attaching the
* libbpf skeleton.
* If dry_run is true, the function only tests load and attach to
* verify host compatibility.
*
* Returns a positive int that represents an fd, which can be used with epoll
* on success. Returns an error on failure. If ctx is NULL,
* on success. Returns an error on failure. If dry_run is true,
* returns 0 on success or less than 0 on failure.
*/
int ebpf_event_ctx__new(struct ebpf_event_ctx **ctx,
ebpf_event_handler_fn cb,
struct ebpf_event_ctx_opts opts);
struct ebpf_event_ctx_opts opts,
bool dry_run);

/* Consumes as many events as possible from the event context and returns the
* number consumed.
Expand Down

0 comments on commit 0fddd9b

Please sign in to comment.