summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2018-03-01 20:20:08 -0800
committerDaniel Borkmann <daniel@iogearbox.net>2018-03-02 09:46:41 +0100
commit06cc7fe7c2951e64cd5e73ea447791c7e6bc3852 (patch)
tree9f1d8bcd57bca29769ed9441fbcbdbf409d3cdff
parent56b112f17e8ab1ded40d00ed9a0af63b69b021ef (diff)
downloadlinux-06cc7fe7c2951e64cd5e73ea447791c7e6bc3852.tar.bz2
tools: bpftool: support comments in batch files
Replace '#' by '\0' in commands read from batch files in order to avoid processing the remaining part of the line, thus allowing users to use comments in the files. Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--tools/bpf/bpftool/main.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 185acfa229b5..79587e6decae 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -176,6 +176,7 @@ static int do_batch(int argc, char **argv)
char buf[65536];
int n_argc;
FILE *fp;
+ char *cp;
int err;
int i;
@@ -200,6 +201,10 @@ static int do_batch(int argc, char **argv)
if (json_output)
jsonw_start_array(json_wtr);
while (fgets(buf, sizeof(buf), fp)) {
+ cp = strchr(buf, '#');
+ if (cp)
+ *cp = '\0';
+
if (strlen(buf) == sizeof(buf) - 1) {
errno = E2BIG;
break;