summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorLiu Pan <patteliu@gmail.com>2023-03-20 11:07:20 +0800
committerAndrii Nakryiko <andrii@kernel.org>2023-03-20 11:59:45 -0700
commit01dc26c980b0a92d9ba94c28652b2675968727b6 (patch)
tree7388951da70b69cc950d92679cc7667594784456 /tools/lib
parentbb4a6a9237293346cf1b3b7bc4ff4dfc1977a103 (diff)
downloadlinux-01dc26c980b0a92d9ba94c28652b2675968727b6.tar.gz
libbpf: Explicitly call write to append content to file
Write data to fd by calling "vdprintf", in most implementations of the standard library, the data is finally written by the writev syscall. But "uprobe_events/kprobe_events" does not allow segmented writes, so switch the "append_to_file" function to explicit write() call. Signed-off-by: Liu Pan <patteliu@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20230320030720.650-1-patteliu@gmail.com
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 4c34fbd7b5be..149864ea88d1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9918,16 +9918,20 @@ static int append_to_file(const char *file, const char *fmt, ...)
{
int fd, n, err = 0;
va_list ap;
+ char buf[1024];
+
+ va_start(ap, fmt);
+ n = vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+ if (n < 0 || n >= sizeof(buf))
+ return -EINVAL;
fd = open(file, O_WRONLY | O_APPEND | O_CLOEXEC, 0);
if (fd < 0)
return -errno;
- va_start(ap, fmt);
- n = vdprintf(fd, fmt, ap);
- va_end(ap);
-
- if (n < 0)
+ if (write(fd, buf, n) < 0)
err = -errno;
close(fd);