Skip to content

Commit

Permalink
Set errno for bpf_object__find_map_by_name (#3712)
Browse files Browse the repository at this point in the history
* Initial Commit

* Initialize errno

* Set errno for bpf_object__find_map_by_name

* Added Doxygen comment
  • Loading branch information
shpalani authored Jul 23, 2024
1 parent 2448139 commit 54632eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/bpf/libbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ bpf_object__close(struct bpf_object* object);
* @param[in] name The name to look for.
*
* @returns The map found, or NULL if none.
*
* @exception ENOENT The map was not found.
*/
struct bpf_map*
bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);
Expand Down
2 changes: 1 addition & 1 deletion libs/api/libbpf_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name)
return pos;
}
}
return NULL;
return (struct bpf_map*)libbpf_err_ptr(-ENOENT);
}

int
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/libbpf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,15 @@ TEST_CASE("libbpf program", "[libbpf]")
struct bpf_program* program = bpf_object__find_program_by_name(object, "test_program_entry");
REQUIRE(program != nullptr);

errno = 0;
REQUIRE(bpf_object__find_program_by_name(object, "not_a_valid_name") == NULL);
REQUIRE(errno == ENOENT);

// Testing invalid map name.
errno = 0;
REQUIRE(bpf_object__find_map_by_name(object, "not_a_valid_map") == NULL);
REQUIRE(errno == ENOENT);

name = bpf_program__section_name(program);
REQUIRE(strcmp(name, "sample_ext") == 0);

Expand Down

0 comments on commit 54632eb

Please sign in to comment.