From 002a84a1237d72a9e0ec824f05657a395469a38b Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Wed, 10 Feb 2021 11:53:05 +0000 Subject: [PATCH] improve errors during config parsing --- lex.l | 4 ++-- parse.y | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lex.l b/lex.l index 5c1d60c..41fab03 100644 --- a/lex.l +++ b/lex.l @@ -81,9 +81,9 @@ user return TUSER; \n yylineno++; -[ \t]+ ; +[ \f\r\t\v]+ ; -. yyerror("unexpected character"); exit(1); +. yyerror("unexpected character: %c", *yytext); exit(1); %% diff --git a/parse.y b/parse.y index 23a9225..85bb148 100644 --- a/parse.y +++ b/parse.y @@ -17,7 +17,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include #include #include #include @@ -80,7 +80,7 @@ option : TCHROOT TSTRING { conf.chroot = $2; } | TPREFORK TNUM { conf.prefork = check_prefork_num($2); } | TPROTOCOLS TSTRING { if (tls_config_parse_protocols(&conf.protos, $2) == -1) - errx(1, "invalid protocols string \"%s\"", $2); + yyerror("invalid protocols string \"%s\"", $2); } | TUSER TSTRING { conf.user = $2; } ; @@ -101,7 +101,7 @@ vhost : TSERVER TSTRING '{' servopts locations '}' { if (host->cert == NULL || host->key == NULL || host->dir == NULL) - errx(1, "invalid vhost definition: %s", $2); + yyerror("invalid vhost definition: %s", $2); if (++ihost == HOSTSLEN) errx(1, "too much vhosts defined"); @@ -225,7 +225,7 @@ parse_portno(const char *p) n = strtonum(p, 0, UINT16_MAX, &errstr); if (errstr != NULL) - errx(1, "port number is %s: %s", errstr, p); + yylineno("port number is %s: %s", errstr, p); return n; } @@ -239,7 +239,7 @@ parse_conf(const char *path) config_path = path; if ((yyin = fopen(path, "r")) == NULL) - fatal("cannot open config %s", path); + fatal("cannot open config: %s: %s", path, strerror(errno)); yyparse(); fclose(yyin);