Skip to content

Commit 01dc26c

Browse files
Hackerlanakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bb4a6a9 commit 01dc26c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9918,16 +9918,20 @@ static int append_to_file(const char *file, const char *fmt, ...)
99189918
{
99199919
int fd, n, err = 0;
99209920
va_list ap;
9921+
char buf[1024];
9922+
9923+
va_start(ap, fmt);
9924+
n = vsnprintf(buf, sizeof(buf), fmt, ap);
9925+
va_end(ap);
9926+
9927+
if (n < 0 || n >= sizeof(buf))
9928+
return -EINVAL;
99219929

99229930
fd = open(file, O_WRONLY | O_APPEND | O_CLOEXEC, 0);
99239931
if (fd < 0)
99249932
return -errno;
99259933

9926-
va_start(ap, fmt);
9927-
n = vdprintf(fd, fmt, ap);
9928-
va_end(ap);
9929-
9930-
if (n < 0)
9934+
if (write(fd, buf, n) < 0)
99319935
err = -errno;
99329936

99339937
close(fd);

0 commit comments

Comments
 (0)