terminate config reading on EOT/Ctl-D instead of just on pipe close
commit935e58cb84aa52eaf4525c2b3424446f4cf0c2e2
authorAntonio Borneo <Antonio Borneo@315857ad-0bdb-0310-b42e-dec37551a5f0>
Tue, 18 Feb 2014 05:09:33 +0000 (18 05:09 +0000)
committerAntonio Borneo <Antonio Borneo@315857ad-0bdb-0310-b42e-dec37551a5f0>
Tue, 18 Feb 2014 05:09:33 +0000 (18 05:09 +0000)
tree50cb6fc60b0e670d9f546fcf32d6e33dd905b8f2
parenta8c7a36f6b6ee31a7a76a51cd789928921dd60e2
terminate config reading on EOT/Ctl-D instead of just on pipe close

based on original patch from Dan Williams <dcbw@redhat.com>
http://lists.unix-ag.uni-kl.de/pipermail/vpnc-devel/2013-December/004043.html

vpnc's config file processing logic uses EOF to determine when to stop
processing the config input, but if stdin is actually a pipe from a
controlling process, EOF only happens if the pipe is closed. Which
means the controlling process can't respond to any interactive requests
for information. So we need to add some other mechanism to indicate
that config processing is done that does not rely on closing stdin to
indicate this.

Also, getline() only returns on EOF (which has the problems described
above) or when it encounters sufficient newline characters;
unfortunately this precludes using getline() to handle single bytes.
Switch to fgetc() and build up the line ourselves so that we can
recognize a custom CEOT character (0x04/Ctl-D) which also terminates
reading configuration without requiring the pipe to be closed.

Modification wrt Dan's proposal:
- use same prototype as getline();
- remove trailing newline. Avoids code duplication;
- allocate buffer only if required (as getline());
- pass error through errno since feof() is not valid on CEOT;
- remove getline() from sysdep.[ch].

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
git-svn-id: https://svn.unix-ag.uni-kl.de/vpnc/trunk@541 315857ad-0bdb-0310-b42e-dec37551a5f0
config.c
sysdep.c
sysdep.h
vpnc.8.template