| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <fcntl.h> |
| 4 |
|
| 5 |
#include "bpf-util.h" |
| 6 |
#include "fd-util.h" |
| 7 |
#include "main-func.h" |
| 8 |
#include "tests.h" |
| 9 |
|
| 10 |
static int run(int argc, char *argv[]) { |
| 11 |
#if HAVE_LIBBPF |
| 12 |
int r; |
| 13 |
|
| 14 |
r = DLOPEN_BPF(LOG_ERR, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); |
| 15 |
if (r < 0) |
| 16 |
return r; |
| 17 |
|
| 18 |
_cleanup_close_ int bpffs_fd = open("/sys/fs/bpf", O_CLOEXEC|O_RDONLY); |
| 19 |
if (bpffs_fd < 0) |
| 20 |
return log_error_errno(errno, "Failed to open '/sys/fs/bpf': %m"); |
| 21 |
|
| 22 |
_cleanup_close_ int token_fd = sym_bpf_token_create(bpffs_fd, /* opts= */ NULL); |
| 23 |
if (token_fd == -ENOSYS) |
| 24 |
return log_tests_skipped("bpf_token_create() unavailable (libbpf too old or kernel lacks BPF_TOKEN_CREATE support)"); |
| 25 |
if (token_fd < 0) |
| 26 |
return log_error_errno(token_fd, "Failed to create bpf token: %m"); |
| 27 |
|
| 28 |
log_info("Successfully created token fd."); |
| 29 |
return 0; |
| 30 |
#else |
| 31 |
return log_tests_skipped("BPF framework support is disabled"); |
| 32 |
#endif |
| 33 |
} |
| 34 |
|
| 35 |
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); |