-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set CLOEXEC flag when opening files and sockets #1206
Conversation
Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
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. Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
Just define 'O_CLOEXEC' as 0; it is used always like in | f = open(..., flags | O_CLOEXEC); Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
When fopen() does not support the "e" flag, parse the mode string and run an 'open(..., O_CLOEXEC) + fdopen()' sequence when it is set. Signed-off-by: Enrico Scholz <[email protected]>
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. Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
Signed-off-by: Enrico Scholz <[email protected]>
5dd45a2
to
5a117bb
Compare
I do not know why the linux builds in the CI are failing; they succeed locally. Perhaps a problem with the github buildsystem. |
looking into the test issue ... guess this might be unrelated to your changes |
Codecov Report
@@ Coverage Diff @@
## master #1206 +/- ##
==========================================
+ Coverage 50.98% 50.99% +0.01%
==========================================
Files 45 45
Lines 18043 18043
==========================================
+ Hits 9199 9201 +2
+ Misses 8844 8842 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#ifdef _POSIX_C_SOURCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ensc Could you please check:
#ifdef _POSIX_C_SOURCE
# include <fcntl.h>
In msys2 mingw-w64 builds we see these warnings e.g. [1]:
compat-cloexec.c:11: warning: "O_CREAT" redefined
11 | # define O_CREAT 0
|
In file included from ./rrd_config_bottom.h:64,
from ./rrd_config.h:634,
from compat-cloexec.h:4,
from compat-cloexec.c:1:
D:/a/_temp/msys64/mingw64/include/fcntl.h:40: note: this is the location of the previous definition
40 | #define O_CREAT _O_CREAT
|
compat-cloexec.c:12: warning: "O_WRONLY" redefined
12 | # define O_WRONLY 0
|
D:/a/_temp/msys64/mingw64/include/fcntl.h:37: note: this is the location of the previous definition
37 | #define O_WRONLY _O_WRONLY
|
compat-cloexec.c:13: warning: "O_RDONLY" redefined
13 | # define O_RDONLY 0
|
D:/a/_temp/msys64/mingw64/include/fcntl.h:36: note: this is the location of the previous definition
36 | #define O_RDONLY _O_RDONLY
|
compat-cloexec.c:14: warning: "O_APPEND" redefined
14 | # define O_APPEND 0
|
D:/a/_temp/msys64/mingw64/include/fcntl.h:39: note: this is the location of the previous definition
39 | #define O_APPEND _O_APPEND
|
compat-cloexec.c:15: warning: "O_RDWR" redefined
15 | # define O_RDWR 0
|
D:/a/_temp/msys64/mingw64/include/fcntl.h:38: note: this is the location of the previous definition
38 | #define O_RDWR _O_RDWR
|
configure
says:
checking for fcntl.h... yes
So, HAVE_FCNTL_H
is defined.
[1] https://github.com/oetiker/rrdtool-1.x/actions/runs/4740218558/jobs/8415805010#step:5:901
#include <stdlib.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef _POSIX_C_SOURCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ensc Warnings under msys2 mingw-w64 as in compat-cloexec.c
:
CC test_compat-cloexec.o
test_compat-cloexec.c:10: warning: "O_RDONLY" redefined
10 | # define O_RDONLY 0
|
In file included from ../src/rrd_config_bottom.h:64,
from ../src/rrd_config.h:634,
from ../src/compat-cloexec.h:4,
from test_compat-cloexec.c:1:
C:/msys64/mingw64/include/fcntl.h:36: note: this is the location of the previous definition
36 | #define O_RDONLY _O_RDONLY
|
test_compat-cloexec.c:11: warning: "O_RDWR" redefined
11 | # define O_RDWR 0
|
C:/msys64/mingw64/include/fcntl.h:38: note: this is the location of the previous definition
38 | #define O_RDWR _O_RDWR
|
test_compat-cloexec.c:12: warning: "O_APPEND" redefined
12 | # define O_APPEND 0
|
C:/msys64/mingw64/include/fcntl.h:39: note: this is the location of the previous definition
39 | #define O_APPEND _O_APPEND
|
CC compat-cloexec.o
../src/compat-cloexec.c:11: warning: "O_CREAT" redefined
11 | # define O_CREAT 0
|
In file included from ../src/rrd_config_bottom.h:64,
from ../src/rrd_config.h:634,
from ../src/compat-cloexec.h:4,
from ../src/compat-cloexec.c:1:
C:/msys64/mingw64/include/fcntl.h:40: note: this is the location of the previous definition
40 | #define O_CREAT _O_CREAT
|
../src/compat-cloexec.c:12: warning: "O_WRONLY" redefined
12 | # define O_WRONLY 0
|
C:/msys64/mingw64/include/fcntl.h:37: note: this is the location of the previous definition
37 | #define O_WRONLY _O_WRONLY
|
../src/compat-cloexec.c:13: warning: "O_RDONLY" redefined
13 | # define O_RDONLY 0
|
C:/msys64/mingw64/include/fcntl.h:36: note: this is the location of the previous definition
36 | #define O_RDONLY _O_RDONLY
|
../src/compat-cloexec.c:14: warning: "O_APPEND" redefined
14 | # define O_APPEND 0
|
C:/msys64/mingw64/include/fcntl.h:39: note: this is the location of the previous definition
39 | #define O_APPEND _O_APPEND
|
../src/compat-cloexec.c:15: warning: "O_RDWR" redefined
15 | # define O_RDWR 0
|
C:/msys64/mingw64/include/fcntl.h:38: note: this is the location of the previous definition
38 | #define O_RDWR _O_RDWR
|
CCLD compat-cloexec.exe
FILE *f; | ||
|
||
f = _rrd_fopen("/dev/null", "r"); | ||
check_file(f, O_RDONLY, false, __LINE__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test fails under msys2 mingw-w64:
test_compat-cloexec.c:59 fopen() failed
FAIL compat-cloexec.exe (exit status: 3)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we skip it on windows ?
Avoids leaking of file descriptors in multi threaded programs by:
O_CLOEXEC
flag inrrd_open()
fopen()
and providing a fallback implementation for environments without this flagSolves #1202