diff options
author | Phil Sutter <phil@nwl.cc> | 2018-04-13 16:52:24 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-04-14 13:53:02 +0200 |
commit | 2f86dd5a43baf22a6d27fd74f38da37aa28bbaf8 (patch) | |
tree | a78f5fd309f01572c381eed48d19d18911d580a5 /include | |
parent | 3e4d73cf00d919422e31037c967371e2563801bc (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 <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/nftables.h | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/include/nftables.h b/include/nftables.h index 75134def..5f2da8b0 100644 --- a/include/nftables.h +++ b/include/nftables.h @@ -114,10 +114,7 @@ struct input_descriptor { struct location location; enum input_descriptor_types type; const char *name; - union { - const char *data; - FILE *fp; - }; + const char *data; unsigned int lineno; unsigned int column; off_t token_offset; |