Skip to content

Commit

Permalink
tools: bpftool: open pinned object without type check
Browse files Browse the repository at this point in the history
This was needed for opening any file in bpf-fs without knowing
its object type

Signed-off-by: Prashant Bhole <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
pbhole authored and davem330 committed Nov 11, 2017
1 parent 329fca6 commit 1852719
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/bpf/bpftool/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ static int mnt_bpffs(const char *target, char *buff, size_t bufflen)
return 0;
}

int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
int open_obj_pinned(char *path)
{
enum bpf_obj_type type;
int fd;

fd = bpf_obj_get(path);
Expand All @@ -136,6 +135,18 @@ int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
return -1;
}

return fd;
}

int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
{
enum bpf_obj_type type;
int fd;

fd = open_obj_pinned(path);
if (fd < 0)
return -1;

type = get_fd_type(fd);
if (type < 0) {
close(fd);
Expand Down
1 change: 1 addition & 0 deletions tools/bpf/bpftool/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv,
int get_fd_type(int fd);
const char *get_fd_type_name(enum bpf_obj_type type);
char *get_fdinfo(int fd, const char *key);
int open_obj_pinned(char *path);
int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type);
int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32));

Expand Down

0 comments on commit 1852719

Please sign in to comment.