naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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