summaryrefslogtreecommitdiff
path: root/trafgen_parser.y
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-10-13 17:16:43 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-10-13 17:22:08 +0200
commit895377c6e96ec8ac853568eb275043741a7621cd (patch)
tree91a6d5ce3b11ec555d427cdb6d784bfcd78e80e6 /trafgen_parser.y
parentdaac1198c011aa122cf52004629dd77b4e99ae7d (diff)
trafgen: Don't panic() on parser errors
If the C preprocessor is used to parse the packet description, a temporary file is created which is not deleted if an error occurs during parsing in compile_packets(). Instead, don't panic() on errors and only print a message, and only die() once we cleaned up after us. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_parser.y')
-rw-r--r--trafgen_parser.y27
1 files changed, 18 insertions, 9 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index f934baa..126a819 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -592,9 +592,10 @@ void cleanup_packets(void)
free(packet_dyn);
}
-int compile_packets(char *file, int verbose, int cpu, bool invoke_cpp)
+void compile_packets(char *file, int verbose, int cpu, bool invoke_cpp)
{
char tmp_file[128];
+ int ret = -1;
memset(tmp_file, 0, sizeof(tmp_file));
our_cpu = cpu;
@@ -608,8 +609,10 @@ int compile_packets(char *file, int verbose, int cpu, bool invoke_cpp)
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");
+ if (system(cmd) != 0) {
+ fprintf(stderr, "Failed to invoke C preprocessor!\n");
+ goto err;
+ }
file = tmp_file;
xfree(a);
@@ -620,24 +623,30 @@ int compile_packets(char *file, int verbose, int cpu, bool invoke_cpp)
yyin = stdin;
else
yyin = fopen(file, "r");
- if (!yyin)
- panic("Cannot open %s: %s!\n", file, strerror(errno));
+ if (!yyin) {
+ fprintf(stderr, "Cannot open %s: %s!\n", file, strerror(errno));
+ goto err;
+ }
realloc_packet();
- yyparse();
+ if (yyparse() != 0)
+ goto err;
finalize_packet();
if (our_cpu == 0 && verbose)
dump_conf();
+ ret = 0;
+err:
fclose(yyin);
+
if (invoke_cpp)
unlink(tmp_file);
-
- return 0;
+ if (ret)
+ die();
}
void yyerror(const char *err)
{
- panic("Syntax error at line %d, char '%s': %s\n", yylineno, yytext, err);
+ fprintf(stderr, "Syntax error at line %d, char '%s': %s\n", yylineno, yytext, err);
}