From 2c3721379641ed798f4f47e6b0cf473d9cc1b4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 1 Mar 2021 23:09:54 -0800 Subject: make failure on map creation returns -errno MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This slightly improves error logging. (also fd == 0 is not an error condition) Test: atest, TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I135e7405c508951fba632c634bc4e2d2161fc940 --- libbpf_android/Loader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libbpf_android/Loader.cpp') diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp index 01f8964..e0d56e4 100644 --- a/libbpf_android/Loader.cpp +++ b/libbpf_android/Loader.cpp @@ -434,6 +434,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& for (int i = 0; i < (int)mapNames.size(); i++) { unique_fd fd; + int saved_errno; // Format of pin location is /sys/fs/bpf/map__ string mapPinLoc; bool reuse = false; @@ -441,16 +442,17 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& mapPinLoc = string(BPF_FS_PATH) + prefix + "map_" + fname + "_" + string(mapNames[i]); if (access(mapPinLoc.c_str(), F_OK) == 0) { fd.reset(bpf_obj_get(mapPinLoc.c_str())); + saved_errno = errno; ALOGD("bpf_create_map reusing map %s, ret: %d\n", mapNames[i].c_str(), fd.get()); reuse = true; } else { fd.reset(bpf_create_map(md[i].type, mapNames[i].c_str(), md[i].key_size, md[i].value_size, md[i].max_entries, md[i].map_flags)); + saved_errno = errno; ALOGD("bpf_create_map name %s, ret: %d\n", mapNames[i].c_str(), fd.get()); } - if (fd < 0) return fd; - if (fd == 0) return -EINVAL; + if (fd < 0) return -saved_errno; if (!reuse) { ret = bpf_obj_pin(fd, mapPinLoc.c_str()); -- cgit v1.2.3