Re: [PATCH 1/1] libbpf: Define MFD_CLOEXEC if not available

From: Arnaldo Carvalho de Melo
Date: Thu Mar 21 2024 - 12:16:58 EST


On Thu, Mar 21, 2024 at 09:13:35AM -0700, Andrii Nakryiko wrote:
> On Thu, Mar 21, 2024 at 9:02 AM Arnaldo Carvalho de Melo
> <acme@xxxxxxxxxx> wrote:
> >
> > Since its going directly to the syscall to avoid not having
> > memfd_create() available in some systems, do the same for its
> > MFD_CLOEXEC flags, defining it if not available.
> >
> > This fixes the build in those systems, noticed while building perf on a
> > set of build containers.
> >
> > Fixes: 9fa5e1a180aa639f ("libbpf: Call memfd_create() syscall directly")
> > Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
> > Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> > ---
> > tools/lib/bpf/libbpf.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index efab29b8935bd9f7..635a38c6f947a34d 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -1650,6 +1650,10 @@ static int sys_memfd_create(const char *name, unsigned flags)
> > return syscall(__NR_memfd_create, name, flags);
> > }
> >
> > +#ifndef MFD_CLOEXEC
> > +#define MFD_CLOEXEC 0x0001U
> > +#endif
> > +
>
> makes sense, and lgtm. Do you need it in the bpf or bpf-next tree the
> most? your patch header doesn't specify this

Modern distros don't have this problem, so its not urgent, if bpf-next
is more convenient for you, so be it.

- Arnaldo

>
> > static int create_placeholder_fd(void)
> > {
> > int fd;
> > --
> > 2.44.0
> >