naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0127-bpf-minor-cleanups-for-bpf_trace_pipe.patch

36cfb7
From edf0ae950c5b9d3c5eed29a40f5669cf657995e6 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Tue, 30 Apr 2019 15:43:03 +0200
36cfb7
Subject: [PATCH] bpf: minor cleanups for bpf_trace_pipe
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 1b736dc469dca
36cfb7
36cfb7
commit 1b736dc469dcabd4180848a1f1b3d1fef2b84dbc
36cfb7
Author: Daniel Borkmann <daniel@iogearbox.net>
36cfb7
Date:   Tue Sep 5 02:24:31 2017 +0200
36cfb7
36cfb7
    bpf: minor cleanups for bpf_trace_pipe
36cfb7
36cfb7
    Just minor nits, e.g. no need to fflush() and instead of returning
36cfb7
    right away, just break and close the fd.
36cfb7
36cfb7
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
36cfb7
---
36cfb7
 lib/bpf.c | 19 +++++++++----------
36cfb7
 1 file changed, 9 insertions(+), 10 deletions(-)
36cfb7
36cfb7
diff --git a/lib/bpf.c b/lib/bpf.c
36cfb7
index e072cba214067..f0e6c6fb732ee 100644
36cfb7
--- a/lib/bpf.c
36cfb7
+++ b/lib/bpf.c
36cfb7
@@ -461,9 +461,9 @@ int bpf_trace_pipe(void)
36cfb7
 		"/trace",
36cfb7
 		0,
36cfb7
 	};
36cfb7
+	int fd_in, fd_out = STDERR_FILENO;
36cfb7
 	char tpipe[PATH_MAX];
36cfb7
 	const char *mnt;
36cfb7
-	int fd;
36cfb7
 
36cfb7
 	mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt,
36cfb7
 			     sizeof(tracefs_mnt), tracefs_known_mnts);
36cfb7
@@ -474,8 +474,8 @@ int bpf_trace_pipe(void)
36cfb7
 
36cfb7
 	snprintf(tpipe, sizeof(tpipe), "%s/trace_pipe", mnt);
36cfb7
 
36cfb7
-	fd = open(tpipe, O_RDONLY);
36cfb7
-	if (fd < 0)
36cfb7
+	fd_in = open(tpipe, O_RDONLY);
36cfb7
+	if (fd_in < 0)
36cfb7
 		return -1;
36cfb7
 
36cfb7
 	fprintf(stderr, "Running! Hang up with ^C!\n\n");
36cfb7
@@ -483,15 +483,14 @@ int bpf_trace_pipe(void)
36cfb7
 		static char buff[4096];
36cfb7
 		ssize_t ret;
36cfb7
 
36cfb7
-		ret = read(fd, buff, sizeof(buff) - 1);
36cfb7
-		if (ret > 0) {
36cfb7
-			if (write(STDERR_FILENO, buff, ret) != ret)
36cfb7
-				return -1;
36cfb7
-			fflush(stderr);
36cfb7
-		}
36cfb7
+		ret = read(fd_in, buff, sizeof(buff));
36cfb7
+		if (ret > 0 && write(fd_out, buff, ret) == ret)
36cfb7
+			continue;
36cfb7
+		break;
36cfb7
 	}
36cfb7
 
36cfb7
-	return 0;
36cfb7
+	close(fd_in);
36cfb7
+	return -1;
36cfb7
 }
36cfb7
 
36cfb7
 static int bpf_gen_global(const char *bpf_sub_dir)
36cfb7
-- 
e138d9
2.21.0
36cfb7