Skip to content

Commit

Permalink
sync with bpf-next
Browse files Browse the repository at this point in the history
Sync with the following bug fix:
  commit a8a1f7d09cfc7e18874786c7634c9e71384fcd4e (HEAD -> bpf-next2, bpf-next/master)
  Author: Stanislav Fomichev <sdf@google.com>
  Date:   Mon Feb 4 16:20:55 2019 -0800

    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).

    ......

    Signed-off-by: Stanislav Fomichev <sdf@google.com>

Signed-off-by: Yonghong Song <yhs@fb.com>
  • Loading branch information
yonghong-song committed Feb 5, 2019
1 parent 30388a7 commit b19c6dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,16 @@

#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)
return 0;

va_start(args, format);
err = vfprintf(stderr, format, args);
va_end(args);
return err;
return vfprintf(stderr, format, args);
}

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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/libbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ enum libbpf_print_level {
};

typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
const char *, ...)
__attribute__((format(printf, 2, 3)));
const char *, va_list ap);

LIBBPF_API void libbpf_set_print(libbpf_print_fn_t fn);

Expand Down

0 comments on commit b19c6dc

Please sign in to comment.