path: root/src/scanner.l
diff options
authorPhil Sutter <>2018-04-13 16:52:24 +0200
committerPablo Neira Ayuso <>2018-04-14 13:53:02 +0200
commit2f86dd5a43baf22a6d27fd74f38da37aa28bbaf8 (patch)
treea78f5fd309f01572c381eed48d19d18911d580a5 /src/scanner.l
parent3e4d73cf00d919422e31037c967371e2563801bc (diff)
erec: Review erec_print()
A new requirement to erec for the upcoming JSON support is printing records with file input descriptors without open stream. The approach is to treat 'name' field as file name, open it, extract the offending line and close it again. Further changes to libnftables input parsing routines though have shown that the whole concept of file pointer reuse in erec is tedious and not worth keeping: * Closed files are to be supported as well, so there needs to be fallback code for opening the file anyway. * When input descriptor is duplicated from parser state into an error record, the file pointer is copied as well. Therefore care has to be taken to not free the parser state before any error records have been printed. This is the only point where old and duplicated input descriptors are connected. Therefore drop struct input_descriptor's 'fp' field and just always open the file by name. This way also the old stream offset doesn't have to be restored after reading. While being at it, this patch fixes two other (potential) problems: * If the offending line from input contains tabs, add them at the right position in the marker buffer as well to avoid misalignment. * The input file may not be seekable (/dev/stdin for instance), so skip printing of offending line and markers if it couldn't be read properly. Signed-off-by: Phil Sutter <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src/scanner.l')
1 files changed, 0 insertions, 2 deletions
diff --git a/src/scanner.l b/src/scanner.l
index d908a8fe..ba60ec17 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -662,7 +662,6 @@ static struct error_record *scanner_push_file(void *scanner, const char *filenam
state->indesc->location = *loc;
state->indesc->type = INDESC_FILE;
state->indesc->name = xstrdup(filename);
- state->indesc->fp = f;
return NULL;
@@ -891,7 +890,6 @@ void scanner_destroy(void *scanner)
if (inpdesc && inpdesc->name) {
inpdesc->name = NULL;
- fclose(inpdesc->fp);
} while (state->indesc_idx--);