Set CLOEXEC flag when opening files and sockets (#1206)
* configure: check for O_CLOEXEC
* configure: check for SOCK_CLOEXEC
* configure: check whether fopen() supports the "e" flag
Although the "e" fopen() flag (atomic FD_CLOEXEC support) is scheduled
for being added to the next POSIX version, it is not supported by all
platforms.
Check whether it is accepted and working.
Because this flag can be tested at runtime only, configure.ac uses
AC_RUN_IFELSE. Cross compiling fallback assumes that "e" is supported.
* compat-cloexec: initial checkin
* compat-cloexec: implement missing HAVE_DECL_O_CLOEXEC case
Just define 'O_CLOEXEC' as 0; it is used always like in
| f = open(..., flags | O_CLOEXEC);
* compat-cloexec: implement missing HAVE_DECL_SOCK_CLOEXEC case
* compat-cloexec: implement missing RD_HAVE_WORKING_FOPEN_E case
When fopen() does not support the "e" flag, parse the mode string and
run an 'open(..., O_CLOEXEC) + fdopen()' sequence when it is set.
* rrd_open: open file with O_CLOEXEC
Avoid leaking file descriptors by set the O_CLOEXEC flag. This flag is
part of POSIX.1-2008 and there is implemented a fallback for systems
without it.
* open sockets with SOCK_CLOEXEC
* set "e" flag with fopen()
* tests: add test for _rrd_fopen()