Re: [PATCH bpf-next] libbpf: Error out when missing binary_path for USDT attach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 4, 2022 at 7:09 AM Hengqi Chen <hengqi.chen@xxxxxxxxx> wrote:
>
> The binary_path parameter is required for bpf_program__attach_usdt().
> Error out when user attach USDT probe without specifying a binary_path.
>

This is a required parameter, libbpf doesn't add pr_warn() for every
`const char *` parameter that the user incorrectly passes NULL for
(e.g., bpf_program__attach_kprobe's func_name). If you think
bpf_program__attach_usdt() doc comment about this is not clear enough,
let's improve the documentation instead of littering libbpf source
code with Java-like NULL checks everywhere.

> Signed-off-by: Hengqi Chen <hengqi.chen@xxxxxxxxx>
> ---
>  tools/lib/bpf/libbpf.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 8a45a84eb9b2..5e4153c5b0a6 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -10686,6 +10686,12 @@ struct bpf_link *bpf_program__attach_usdt(const struct bpf_program *prog,
>                 return libbpf_err_ptr(-EINVAL);
>         }
>
> +       if (!binary_path) {
> +               pr_warn("prog '%s': USDT attach requires binary_path\n",
> +                       prog->name);
> +               return libbpf_err_ptr(-EINVAL);
> +       }
> +
>         if (!strchr(binary_path, '/')) {
>                 err = resolve_full_path(binary_path, resolved_path, sizeof(resolved_path));
>                 if (err) {
> --
> 2.30.2



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux