Re: [PATCH bpf-next 1/2] libbpf: ensure libbpf always opens files with O_CLOEXEC

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

 



On 5/26/23 10:19 AM, Lennart Poettering wrote:
On Do, 25.05.23 15:13, Andrii Nakryiko (andrii@xxxxxxxxxx) wrote:

Make sure that libbpf code always gets FD with O_CLOEXEC flag set,
regardless if file is open through open() or fopen(). For the latter
this means to add "e" to mode string, which is supported since pretty
ancient glibc v2.7.

I also dropped outdated TODO comment in usdt.c, which was already completed.

Suggested-by: Lennart Poettering <lennart@xxxxxxxxxxxxxx>
Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
---
  tools/lib/bpf/btf.c           | 2 +-
  tools/lib/bpf/libbpf.c        | 6 +++---
  tools/lib/bpf/libbpf_probes.c | 2 +-
  tools/lib/bpf/usdt.c          | 5 ++---
  4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 0a2c079244b6..8484b563b53d 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1064,7 +1064,7 @@ static struct btf *btf_parse_raw(const char *path, struct btf *base_btf)
  	int err = 0;
  	long sz;

-	f = fopen(path, "rb");
+	f = fopen(path, "rbe");

You might as well drop the "b". That's a thing only on non-POSIX
systems. So unless you want to support windows with this, you can drop
it with zero effect.

Iiuc, the library is also imported by the 'ebpf for windows' project [0],
so we might need to keep the 'b' intact in that case.

Thanks,
Daniel

  [0] https://github.com/microsoft/ebpf-for-windows/#architectural-overview




[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