diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-07-27 23:25:26 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-07-28 01:36:19 -0400 |
commit | e87fd8bae44c3eaa6205c9c81419e773896dc157 (patch) | |
tree | e503465a3c5227bc9c1872a16139c396e87801e7 | |
parent | 8160bae21fc29de0ec795abcd209cdd7cc144e8e (diff) |
libbpf: return previous print callback from libbpf_set_print
By returning previously set print callback from libbpf_set_print, it's
possible to restore it, eventually. This is useful when running many
independent test with one default print function, but overriding log
verbosity for particular subset of tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/lib/bpf/libbpf.c | 5 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 8741c39adb1c..ead915aec349 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -74,9 +74,12 @@ static int __base_pr(enum libbpf_print_level level, const char *format, | |||
74 | 74 | ||
75 | static libbpf_print_fn_t __libbpf_pr = __base_pr; | 75 | static libbpf_print_fn_t __libbpf_pr = __base_pr; |
76 | 76 | ||
77 | void libbpf_set_print(libbpf_print_fn_t fn) | 77 | libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn) |
78 | { | 78 | { |
79 | libbpf_print_fn_t old_print_fn = __libbpf_pr; | ||
80 | |||
79 | __libbpf_pr = fn; | 81 | __libbpf_pr = fn; |
82 | return old_print_fn; | ||
80 | } | 83 | } |
81 | 84 | ||
82 | __printf(2, 3) | 85 | __printf(2, 3) |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 5cbf459ece0b..8a9d462a6f6d 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -57,7 +57,7 @@ enum libbpf_print_level { | |||
57 | typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level, | 57 | typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level, |
58 | const char *, va_list ap); | 58 | const char *, va_list ap); |
59 | 59 | ||
60 | LIBBPF_API void libbpf_set_print(libbpf_print_fn_t fn); | 60 | LIBBPF_API libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn); |
61 | 61 | ||
62 | /* Hide internal to user */ | 62 | /* Hide internal to user */ |
63 | struct bpf_object; | 63 | struct bpf_object; |