Commit a8a1f7d0 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Alexei Starovoitov

libbpf: fix libbpf_print

With the recent print rework we now have the following problem:
pr_{warning,info,debug} expand to __pr which calls libbpf_print.
libbpf_print does va_start and calls __libbpf_pr with va_list argument.
In __base_pr we again do va_start. Because the next argument is a
va_list, we don't get correct pointer to the argument (and print noting
in my case, I don't know why it doesn't crash tbh).

Fix this by changing libbpf_print_fn_t signature to accept va_list and
remove unneeded calls to va_start in the existing users.

Alternatively, this can we solved by exporting __libbpf_pr and
changing __pr macro to (and killing libbpf_print):
{
	if (__libbpf_pr)
		__libbpf_pr(level, "libbpf: " fmt, ##__VA_ARGS__)
}
Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 1728b111
...@@ -54,22 +54,16 @@ ...@@ -54,22 +54,16 @@
#define __printf(a, b) __attribute__((format(printf, a, b))) #define __printf(a, b) __attribute__((format(printf, a, b)))
__printf(2, 3) static int __base_pr(enum libbpf_print_level level, const char *format,
static int __base_pr(enum libbpf_print_level level, const char *format, ...) va_list args)
{ {
va_list args;
int err;
if (level == LIBBPF_DEBUG) if (level == LIBBPF_DEBUG)
return 0; return 0;
va_start(args, format); return vfprintf(stderr, format, args);
err = vfprintf(stderr, format, args);
va_end(args);
return err;
} }
static __printf(2, 3) libbpf_print_fn_t __libbpf_pr = __base_pr; static libbpf_print_fn_t __libbpf_pr = __base_pr;
void libbpf_set_print(libbpf_print_fn_t fn) void libbpf_set_print(libbpf_print_fn_t fn)
{ {
......
...@@ -54,8 +54,7 @@ enum libbpf_print_level { ...@@ -54,8 +54,7 @@ enum libbpf_print_level {
}; };
typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level, typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
const char *, ...) const char *, va_list ap);
__attribute__((format(printf, 2, 3)));
LIBBPF_API void libbpf_set_print(libbpf_print_fn_t fn); LIBBPF_API void libbpf_set_print(libbpf_print_fn_t fn);
......
...@@ -25,15 +25,9 @@ ...@@ -25,15 +25,9 @@
#include "c++/clang-c.h" #include "c++/clang-c.h"
static int libbpf_perf_print(enum libbpf_print_level level __attribute__((unused)), static int libbpf_perf_print(enum libbpf_print_level level __attribute__((unused)),
const char *fmt, ...) const char *fmt, va_list args)
{ {
va_list args; return veprintf(1, verbose, pr_fmt(fmt), args);
int ret;
va_start(args, fmt);
ret = veprintf(1, verbose, pr_fmt(fmt), args);
va_end(args);
return ret;
} }
struct bpf_prog_priv { struct bpf_prog_priv {
......
...@@ -52,19 +52,10 @@ static int count_result(int err) ...@@ -52,19 +52,10 @@ static int count_result(int err)
return err; return err;
} }
#define __printf(a, b) __attribute__((format(printf, a, b)))
__printf(2, 3)
static int __base_pr(enum libbpf_print_level level __attribute__((unused)), static int __base_pr(enum libbpf_print_level level __attribute__((unused)),
const char *format, ...) const char *format, va_list args)
{ {
va_list args; return vfprintf(stderr, format, args);
int err;
va_start(args, format);
err = vfprintf(stderr, format, args);
va_end(args);
return err;
} }
#define BTF_INFO_ENC(kind, kind_flag, vlen) \ #define BTF_INFO_ENC(kind, kind_flag, vlen) \
......
...@@ -36,19 +36,13 @@ static void usage(char *argv[]) ...@@ -36,19 +36,13 @@ static void usage(char *argv[])
static bool debug = 0; static bool debug = 0;
static int libbpf_debug_print(enum libbpf_print_level level, static int libbpf_debug_print(enum libbpf_print_level level,
const char *fmt, ...) const char *fmt, va_list args)
{ {
va_list args;
int ret;
if (level == LIBBPF_DEBUG && !debug) if (level == LIBBPF_DEBUG && !debug)
return 0; return 0;
va_start(args, fmt);
fprintf(stderr, "[%d] ", level); fprintf(stderr, "[%d] ", level);
ret = vfprintf(stderr, fmt, args); return vfprintf(stderr, fmt, args);
va_end(args);
return ret;
} }
#define EXIT_FAIL_LIBBPF EXIT_FAILURE #define EXIT_FAIL_LIBBPF EXIT_FAILURE
......
...@@ -1785,18 +1785,12 @@ static void test_task_fd_query_tp(void) ...@@ -1785,18 +1785,12 @@ static void test_task_fd_query_tp(void)
} }
static int libbpf_debug_print(enum libbpf_print_level level, static int libbpf_debug_print(enum libbpf_print_level level,
const char *format, ...) const char *format, va_list args)
{ {
va_list args;
int ret;
if (level == LIBBPF_DEBUG) if (level == LIBBPF_DEBUG)
return 0; return 0;
va_start(args, format); return vfprintf(stderr, format, args);
ret = vfprintf(stderr, format, args);
va_end(args);
return ret;
} }
static void test_reference_tracking() static void test_reference_tracking()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment