Skip to content

Commit e87fd8b

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 8160bae commit e87fd8b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ static int __base_pr(enum libbpf_print_level level, const char *format,
7474

7575
static libbpf_print_fn_t __libbpf_pr = __base_pr;
7676

77-
void libbpf_set_print(libbpf_print_fn_t fn)
77+
libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn)
7878
{
79+
libbpf_print_fn_t old_print_fn = __libbpf_pr;
80+
7981
__libbpf_pr = fn;
82+
return old_print_fn;
8083
}
8184

8285
__printf(2, 3)

tools/lib/bpf/libbpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum libbpf_print_level {
5757
typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
5858
const char *, va_list ap);
5959

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);
6161

6262
/* Hide internal to user */
6363
struct bpf_object;

0 commit comments

Comments
 (0)