Commit Diff
Diff:
d3f073c9ede8d420b06fe8afe6fa8fa12c7b8185
002a84a1237d72a9e0ec824f05657a395469a38b
Commit:
002a84a1237d72a9e0ec824f05657a395469a38b
Tree:
a5c411f2a6e0dbde4e440a3e3188c3aed7e6ab61
Author:
Omar Polo <op@omarpolo.com>
Date:
Wed Feb 10 11:53:05 2021 UTC
Message:
improve errors during config parsing
commit - d3f073c9ede8d420b06fe8afe6fa8fa12c7b8185
commit + 002a84a1237d72a9e0ec824f05657a395469a38b
blob - 5c1d60c7572f4736c33ccc7a412ba5bf2390ba41
blob + 41fab03a93eb41ec5e8e41deed6da074dc8bdf5d
--- lex.l
+++ 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);
%%
blob - 23a9225002b52fb4f71991afcc6d22ca016d9f5c
blob + 85bb1485d0593fe6dbdf35b1a5dd57b2b14f88b5
--- parse.y
+++ parse.y
@@ -17,7 +17,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <err.h>
+#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@@ -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);
Omar Polo