Skip to content

Commit a985175

Browse files
stanek-michallrishi
authored andcommitted
Be explicit about the dry run option
1 parent 90d5193 commit a985175

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

non-GPL/Events/EventsTrace/EventsTrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ int main(int argc, char **argv)
666666
if (g_features_autodetect)
667667
ebpf_detect_system_features(&opts.features);
668668

669-
err = ebpf_event_ctx__new(&ctx, event_ctx_callback, opts);
669+
err = ebpf_event_ctx__new(&ctx, event_ctx_callback, opts, 0);
670670

671671
if (err < 0) {
672672
fprintf(stderr, "Could not create event context: %d %s\n", err, strerror(-err));

non-GPL/Events/Lib/EbpfEvents.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ int ebpf_set_verbose_logging()
405405

406406
int ebpf_event_ctx__new(struct ebpf_event_ctx **ctx,
407407
ebpf_event_handler_fn cb,
408-
struct ebpf_event_ctx_opts opts)
408+
struct ebpf_event_ctx_opts opts,
409+
bool dry_run)
409410
{
410411
struct EventProbe_bpf *probe = NULL;
411412
struct btf *btf = NULL;
@@ -469,8 +470,15 @@ int ebpf_event_ctx__new(struct ebpf_event_ctx **ctx,
469470
if (err != 0)
470471
goto out_destroy_probe;
471472

472-
if (!ctx)
473+
if (dry_run) {
474+
err = 0;
475+
goto out_destroy_probe;
476+
}
477+
478+
if (!ctx) {
479+
err = -ENOENT;
473480
goto out_destroy_probe;
481+
}
474482

475483
*ctx = calloc(1, sizeof(struct ebpf_event_ctx));
476484
if (*ctx == NULL) {

non-GPL/Events/Lib/EbpfEvents.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ int ebpf_detect_system_features(uint64_t *features);
3636

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

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

0 commit comments

Comments
 (0)