Use unique_fd for usableProgram

Makes 2 lines out of 4.

Test: TH
Change-Id: I5e2d047105065a189e6393a8f5fcb75ff42922ec
This commit is contained in:
Patrick Rohr 2024-11-22 11:00:50 -08:00
commit c8a9dc2f6e

View file

@ -28,6 +28,7 @@ namespace android {
namespace bpf {
using ::android::base::borrowed_fd;
using ::android::base::unique_fd;
inline uint64_t ptr_to_u64(const void * const x) {
return (uint64_t)(uintptr_t)x;
@ -182,10 +183,8 @@ inline int retrieveProgram(const char* pathname) {
}
inline bool usableProgram(const char* pathname) {
int fd = retrieveProgram(pathname);
bool ok = (fd >= 0);
if (ok) close(fd);
return ok;
unique_fd fd(retrieveProgram(pathname));
return fd.ok();
}
inline int attachProgram(bpf_attach_type type, const borrowed_fd& prog_fd,