libbpf: Explicitly call write to append content to file
PATCH 1/1 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.
--- tools/lib/bpf/libbpf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/lib/bpf/libbpf.c +9 -5
@@ -9912,16 +9912,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);
Signature · 1 line
2.20.1
Quoted 7 lines · liupan
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 explicitwrite()call.Signed-off-by liupan <[email protected]>
please specify your real full name in Signed-off-by tag
Quoted 10 lines
--- tools/lib/bpf/libbpf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)tools/lib/bpf/libbpf.c +0
-0@@ -9912,16 +9912,20 @@ static int append_to_file(const char *file, const char *fmt, ...) {
tools/lib/bpf/libbpf.c static int append_to_file(const char *file, const char *fmt, ...) · line 9922
Quoted 10 lines
tools/lib/bpf/libbpf.c +8
-0int 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 ;
if n < 0 we should return -errno here
and if n >= sizeof(buf) let's return -E2BIG
Quoted 17 lines
tools/lib/bpf/libbpf.c +1
-6fd =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); --2.20.1