[netsniff-ng] Re: [PATCH 3/4] trafgen: Invoke C preprocessor from cpp.c module

2015-11-19 Thread Tobias Klauser
On 2015-11-19 at 05:07:48 +0100, Vadim Kochan  wrote:
> Use cpp_process func to invoke C preprocesor.
> 
> Signed-off-by: Vadim Kochan 

LGTM, please resend along with adjustments v2 of patch 1/4.

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] Re: [PATCH 4/4] cpp: Use /tmp folder for output files

2015-11-19 Thread Tobias Klauser
On 2015-11-19 at 05:07:49 +0100, Vadim Kochan  wrote:
> There might be a case when input file is located
> in read-only directory and cpp fails when it tries to
> create output file there, so use /tmp folder for that
> as usually it should be writeable for any user.
> 
> Signed-off-by: Vadim Kochan 

LGTM, please adjust to the requested changes in patch 1/4 and resend.

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] Re: [PATCH 1/4] cpp: Add cpp.c module to invoke C preprocessor

2015-11-19 Thread Tobias Klauser
On 2015-11-19 at 05:07:46 +0100, Vadim Kochan  wrote:
> Add cpp_process func to invoke C preprocessor
> which allow to change the logic in one place only.
> 
> Signed-off-by: Vadim Kochan 
> ---
>  cpp.c | 28 
>  cpp.h |  6 ++
>  2 files changed, 34 insertions(+)
>  create mode 100644 cpp.c
>  create mode 100644 cpp.h
> 
> diff --git a/cpp.c b/cpp.c
> new file mode 100644
> index 000..66603f7
> --- /dev/null
> +++ b/cpp.c
> @@ -0,0 +1,28 @@
> +#include 
> +#include 
> +
> +#include "str.h"
> +#include "xmalloc.h"
> +
> +int cpp_process(char *in_file, char *out_file, size_t out_len)

C preprocessor process :) I'd rather call this cpp_invoke or cpp_call.

> +{
> + char cmd[256], *dir, *base, *a = NULL, *b = NULL;

Please do the xstrdup on initialization up here. This makes the
initialization with NULL unnecessary and the whole code nicer to read.

> + int ret = 0;
> +
> + dir = dirname((a = xstrdup(in_file)));
> + base = basename((b = xstrdup(in_file)));
> +
> + slprintf(out_file, out_len, "%s/.tmp-%u-%s", dir, rand(), base);
> + slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
> +  in_file, out_file);
> +
> + if (system(cmd) != 0) {
> + ret = -1;
> + goto exit;

No need for a goto here.

> + }
> +
> +exit:
> + xfree(a);
> + xfree(b);
> + return ret;
> +}
> diff --git a/cpp.h b/cpp.h
> new file mode 100644
> index 000..2d77000
> --- /dev/null
> +++ b/cpp.h
> @@ -0,0 +1,6 @@
> +#ifndef CPP_H
> +#define CPP_H
> +
> +int cpp_process(char *in_file, char *out_file, size_t out_len);

Please add an 'extern' in front of function declarations as with the
other modules.

> +
> +#endif
> -- 
> 2.6.2
> 

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] Re: [PATCH 2/4] bpfc: Invoke C preprocessor from cpp.c module

2015-11-19 Thread Tobias Klauser
On 2015-11-19 at 05:07:47 +0100, Vadim Kochan  wrote:
> Use cpp_process func from cpp.c module to invoke
> C preprocessor.
> 
> Signed-off-by: Vadim Kochan 

LGTM, please resend along with adjustments v2 of patch 1/4.

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH v2 1/4] cpp: Add cpp.c module to invoke C preprocessor

2015-11-19 Thread Vadim Kochan
Add cpp_exec func to invoke C preprocessor
which allow to change the logic in one place only.

Signed-off-by: Vadim Kochan 
---
 cpp.c | 27 +++
 cpp.h |  6 ++
 2 files changed, 33 insertions(+)
 create mode 100644 cpp.c
 create mode 100644 cpp.h

diff --git a/cpp.c b/cpp.c
new file mode 100644
index 000..8448252
--- /dev/null
+++ b/cpp.c
@@ -0,0 +1,27 @@
+#include 
+#include 
+
+#include "str.h"
+#include "xmalloc.h"
+
+int cpp_exec(char *in_file, char *out_file, size_t out_len)
+{
+   char cmd[256], *dir, *base;
+   char *a = xstrdup(in_file);
+   char *b = xstrdup(in_file);
+   int ret = 0;
+
+   dir = dirname(a);
+   base = basename(b);
+
+   slprintf(out_file, out_len, "%s/.tmp-%u-%s", dir, rand(), base);
+   slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
+in_file, out_file);
+
+   if (system(cmd) != 0)
+   ret = -1;
+
+   xfree(a);
+   xfree(b);
+   return ret;
+}
diff --git a/cpp.h b/cpp.h
new file mode 100644
index 000..ace1024
--- /dev/null
+++ b/cpp.h
@@ -0,0 +1,6 @@
+#ifndef CPP_H
+#define CPP_H
+
+int cpp_exec(char *in_file, char *out_file, size_t out_len);
+
+#endif
-- 
2.6.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH v2 2/4] bpfc: Invoke C preprocessor from cpp.c module

2015-11-19 Thread Vadim Kochan
Use cpp_exec func from cpp.c module to invoke C preprocessor.

Signed-off-by: Vadim Kochan 
---
 bpf_parser.y  | 18 ++
 bpfc/Makefile |  1 +
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/bpf_parser.y b/bpf_parser.y
index 8c09639..8aed9dc 100644
--- a/bpf_parser.y
+++ b/bpf_parser.y
@@ -25,6 +25,7 @@
 #include "bpf_parser.tab.h"
 #include "built_in.h"
 #include "die.h"
+#include "cpp.h"
 
 int compile_filter(char *file, int verbose, int bypass, int format,
   bool invoke_cpp);
@@ -744,20 +745,13 @@ int compile_filter(char *file, int verbose, int bypass, 
int format,
memset(tmp_file, 0, sizeof(tmp_file));
 
if (invoke_cpp) {
-   char cmd[256], *dir, *base, *a, *b;
-
-   dir = dirname((a = xstrdup(file)));
-   base = basename((b = xstrdup(file)));
-
-   slprintf(tmp_file, sizeof(tmp_file), "%s/.tmp-%u-%s", dir, 
rand(), base);
-   slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
-file, tmp_file);
-   if (system(cmd) != 0)
-   panic("Failed to invoke C preprocessor!\n");
+   ret = cpp_exec(file, tmp_file, sizeof(tmp_file));
+   if (ret) {
+   fprintf(stderr, "Failed to invoke C preprocessor!\n");
+   goto exit;
+   }
 
file = tmp_file;
-   xfree(a);
-   xfree(b);
}
 
if (!strncmp("-", file, strlen("-")))
diff --git a/bpfc/Makefile b/bpfc/Makefile
index b687bd1..f011706 100644
--- a/bpfc/Makefile
+++ b/bpfc/Makefile
@@ -7,6 +7,7 @@ bpfc-objs = xmalloc.o \
bpf_parser.tab.o \
die.o \
sysctl.o \
+   cpp.o \
bpfc.o
 
 bpfc-lex = bpf_lexer.yy.o
-- 
2.6.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH v2 4/4] cpp: Use /tmp folder for output files

2015-11-19 Thread Vadim Kochan
There might be a case when input file is located
in read-only directory and cpp fails when it tries to
create output file there, so use /tmp folder for that
as usually it should be writeable for any user.

Signed-off-by: Vadim Kochan 
---
 cpp.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/cpp.c b/cpp.c
index 8448252..6734eac 100644
--- a/cpp.c
+++ b/cpp.c
@@ -6,22 +6,19 @@
 
 int cpp_exec(char *in_file, char *out_file, size_t out_len)
 {
-   char cmd[256], *dir, *base;
-   char *a = xstrdup(in_file);
-   char *b = xstrdup(in_file);
+   char *tmp = xstrdup(in_file);
+   char cmd[256], *base;
int ret = 0;
 
-   dir = dirname(a);
-   base = basename(b);
+   base = basename(tmp);
 
-   slprintf(out_file, out_len, "%s/.tmp-%u-%s", dir, rand(), base);
+   slprintf(out_file, out_len, "/tmp/.tmp-%u-%s", rand(), base);
slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
 in_file, out_file);
 
if (system(cmd) != 0)
ret = -1;
 
-   xfree(a);
-   xfree(b);
+   xfree(tmp);
return ret;
 }
-- 
2.6.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH v2 3/4] trafgen: Invoke C preprocessor from cpp.c module

2015-11-19 Thread Vadim Kochan
Use cpp_exec func to invoke C preprocesor.

Signed-off-by: Vadim Kochan 
---
 trafgen/Makefile |  1 +
 trafgen_parser.y | 14 ++
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/trafgen/Makefile b/trafgen/Makefile
index 9777485..bc256b2 100644
--- a/trafgen/Makefile
+++ b/trafgen/Makefile
@@ -18,6 +18,7 @@ trafgen-objs =xmalloc.o \
ring.o \
timer.o \
sysctl.o \
+   cpp.o \
trafgen_lexer.yy.o \
trafgen_parser.tab.o \
trafgen.o
diff --git a/trafgen_parser.y b/trafgen_parser.y
index a05b7e8..afcb3e2 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -25,6 +25,7 @@
 #include "die.h"
 #include "str.h"
 #include "csum.h"
+#include "cpp.h"
 
 #define YYERROR_VERBOSE0
 #define YYDEBUG0
@@ -598,22 +599,11 @@ void compile_packets(char *file, bool verbose, unsigned 
int cpu, bool invoke_cpp
our_cpu = cpu;
 
if (invoke_cpp) {
-   char cmd[256], *dir, *base, *a, *b;
-
-   dir = dirname((a = xstrdup(file)));
-   base = basename((b = xstrdup(file)));
-
-   slprintf(tmp_file, sizeof(tmp_file), "%s/.tmp-%u-%s", dir, 
rand(), base);
-   slprintf(cmd, sizeof(cmd), "cpp -I" ETCDIRE_STRING " %s > %s",
-file, tmp_file);
-   if (system(cmd) != 0) {
+   if (cpp_exec(file, tmp_file, sizeof(tmp_file))) {
fprintf(stderr, "Failed to invoke C preprocessor!\n");
goto err;
}
-
file = tmp_file;
-   xfree(a);
-   xfree(b);
}
 
if (!strncmp("-", file, strlen("-")))
-- 
2.6.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.