summaryrefslogtreecommitdiff
path: root/bpf_parser.y
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-11-22 21:09:37 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-11-24 10:24:01 +0100
commit8a8fd13d6dc2f99cc731657aaffcc1c7dcd975b3 (patch)
treeb62c2d62ed578106bfdfd335b5e64bfa621dccf5 /bpf_parser.y
parentab2bb70f5044e6e784071cf036a8d3db63d3e6eb (diff)
bpfc: Invoke C preprocessor from cpp.c module
Use cpp_exec func from cpp.c module to invoke C preprocessor. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'bpf_parser.y')
-rw-r--r--bpf_parser.y18
1 files changed, 6 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("-")))