summaryrefslogtreecommitdiff
path: root/cpp.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-12-15 23:09:11 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-12-17 09:42:00 +0100
commit52726714c29c3442d3675da4fe888d565988d5db (patch)
treecf802c3dd4e64574ddadfa692246b26f49aff3a6 /cpp.c
parent1e3a2970549d294a1ab31f3088cbdcc2affbba42 (diff)
cpp: Use new proc_exec function to invoke cpp
Replace 'system' call by proc_exec function from proc.c module. It allows to easy extend cpp invoking with additional options (like -D) in more secure way. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'cpp.c')
-rw-r--r--cpp.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/cpp.c b/cpp.c
index 6734eac..d4ec2a6 100644
--- a/cpp.c
+++ b/cpp.c
@@ -2,21 +2,26 @@
#include <libgen.h>
#include "str.h"
+#include "proc.h"
#include "xmalloc.h"
int cpp_exec(char *in_file, char *out_file, size_t out_len)
{
char *tmp = xstrdup(in_file);
- char cmd[256], *base;
+ char *argv[7] = {
+ "cpp",
+ "-I", ETCDIRE_STRING,
+ "-o", out_file,
+ in_file,
+ NULL,
+ };
int ret = 0;
+ char *base;
base = basename(tmp);
-
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)
+ if (proc_exec("cpp", argv))
ret = -1;
xfree(tmp);