trafgen: parser: Check read access to file before invoking cpp
commit4e47fd021a6945aa626eaef4446c5b547d8c2a85
authorTobias Klauser <tklauser@distanz.ch>
Tue, 9 Aug 2016 10:28:15 +0000 (9 12:28 +0200)
committerTobias Klauser <tklauser@distanz.ch>
Tue, 9 Aug 2016 11:56:59 +0000 (9 13:56 +0200)
treebd77315e8eef043cd8e53699fa7125390418f9d8
parent48178cd649b48196e16e0481ca44dea206fe04d4
trafgen: parser: Check read access to file before invoking cpp

If a non-accessible (or non-existing) file is passed to trafgen and the
-p/--cpp option is used, the preprocessor will fail but trafgen will
continue running and producing follow-up errors messages:

cpp: error: foo.conf: No such file or directory
cpp: warning: ā€˜-x cā€™ after last input file has no effect
cpp: fatal error: no input files
compilation terminated.
     0 packets to schedule
Enabled kernel qdisc bypass
     0 bytes in total
Running! Hang up with ^C!

Enabled kernel qdisc bypass
TX,V2: 0.50 MiB, 256 Frames, each 2048 Byte allocated
TX,V2: 0.50 MiB, 256 Frames, each 2048 Byte allocated

   0 packets outgoing
   0 bytes outgoing
   0 sec, 0 usec on CPU0 (0 packets)
   0 sec, 0 usec on CPU1 (0 packets)

To avoid this, check that the file is readable before passing it to the
preprocessor and error out if is not readable.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
trafgen_parser.y