]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commit
Set CLOEXEC flag when opening files and sockets (#1206)
authorEnrico Scholz <github@ensc.de>
Fri, 6 Jan 2023 11:02:12 +0000 (12:02 +0100)
committerGitHub <noreply@github.com>
Fri, 6 Jan 2023 11:02:12 +0000 (12:02 +0100)
commit6d158d14fa8843152608696b69d1ecf38bd012fe
tree3c0e4ed5bb4bbda8ddcea46507215f8090e5d64e
parentf0b2954ec7de34580911bc5994a0afc44980371f
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()

Signed-off-by: Enrico Scholz <enrico.scholz@ensc.de>
19 files changed:
CHANGES
configure.ac
src/Makefile.am
src/compat-cloexec.c [new file with mode: 0644]
src/compat-cloexec.h [new file with mode: 0644]
src/rrd_cgi.c
src/rrd_client.c
src/rrd_daemon.c
src/rrd_dump.c
src/rrd_graph.c
src/rrd_open.c
src/rrd_xport.c
tests/.gitignore
tests/Makefile.am
tests/test_compat-cloexec.c [new file with mode: 0644]
win32/Makefile.msc
win32/Makefile_vcpkg.msc
win32/librrd-8.def
win32/librrd-8.vcxproj