diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2024-11-04 10:44:12 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2024-11-04 10:44:12 +0100 |
commit | b0b0cbcf430b0cfe54350dd09b08ef6a6c80c4e4 (patch) | |
tree | 29020a65adc93921e124e6a97cf4f18348b1f003 | |
parent | 0a6566f10458145b11969faaa937be5c3d68cca8 (diff) | |
download | gnunet-b0b0cbcf430b0cfe54350dd09b08ef6a6c80c4e4.tar.gz gnunet-b0b0cbcf430b0cfe54350dd09b08ef6a6c80c4e4.zip |
util: use pipe2 if available. Fixes #9311
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/lib/util/disk.c | 7 |
3 files changed, 9 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index b9313875e..605b0a6c4 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1058,7 +1058,7 @@ AC_TYPE_UID_T | |||
1058 | # check for library functions | 1058 | # check for library functions |
1059 | AC_FUNC_FORK | 1059 | AC_FUNC_FORK |
1060 | AC_FUNC_CHOWN | 1060 | AC_FUNC_CHOWN |
1061 | AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid getifaddrs freeifaddrs getresgid mallinfo2 malloc_size malloc_usable_size getrusage random srandom stat statfs statvfs wait4 timegm]) | 1061 | AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid getifaddrs freeifaddrs getresgid mallinfo2 malloc_size malloc_usable_size getrusage random srandom stat statfs statvfs wait4 timegm pipe2]) |
1062 | 1062 | ||
1063 | GN_INTLINCL="" | 1063 | GN_INTLINCL="" |
1064 | GN_LIBINTL="$LTLIBINTL" | 1064 | GN_LIBINTL="$LTLIBINTL" |
diff --git a/meson.build b/meson.build index 071795337..f92ff946f 100644 --- a/meson.build +++ b/meson.build | |||
@@ -440,7 +440,7 @@ syscalls = [ | |||
440 | 'getpeerucred', 'getpeereid', 'setresuid', 'getifaddrs', 'freeifaddrs', | 440 | 'getpeerucred', 'getpeereid', 'setresuid', 'getifaddrs', 'freeifaddrs', |
441 | 'getresgid', 'mallinfo2', 'malloc_size', 'malloc_usable_size', 'getrusage', | 441 | 'getresgid', 'mallinfo2', 'malloc_size', 'malloc_usable_size', 'getrusage', |
442 | 'random', 'srandom', 'stat', 'statfs', 'statvfs', 'wait4', 'timegm', | 442 | 'random', 'srandom', 'stat', 'statfs', 'statvfs', 'wait4', 'timegm', |
443 | 'getaddrinfo', 'initgroups', 'gethostbyname' | 443 | 'getaddrinfo', 'initgroups', 'gethostbyname', 'pipe2' |
444 | ] | 444 | ] |
445 | 445 | ||
446 | str_syscalls = [ | 446 | str_syscalls = [ |
diff --git a/src/lib/util/disk.c b/src/lib/util/disk.c index 5dd06fdfb..3ff67c090 100644 --- a/src/lib/util/disk.c +++ b/src/lib/util/disk.c | |||
@@ -1250,6 +1250,9 @@ GNUNET_DISK_file_open (const char *fn, | |||
1250 | } | 1250 | } |
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | // Setting O_CLOEXEC after pipe() may introduce | ||
1254 | // race conditions: https://bugs.gnunet.org/view.php?id=9311 | ||
1255 | // This is no problem if the platform supports pipe2 | ||
1253 | fd = open (expfn, | 1256 | fd = open (expfn, |
1254 | oflags | 1257 | oflags |
1255 | #if O_CLOEXEC | 1258 | #if O_CLOEXEC |
@@ -1417,7 +1420,11 @@ GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) | |||
1417 | { | 1420 | { |
1418 | int fd[2]; | 1421 | int fd[2]; |
1419 | 1422 | ||
1423 | #if HAVE_PIPE2 && O_CLOEXEC | ||
1424 | if (-1 == pipe2 (fd, O_CLOEXEC)) | ||
1425 | #else | ||
1420 | if (-1 == pipe (fd)) | 1426 | if (-1 == pipe (fd)) |
1427 | #endif | ||
1421 | { | 1428 | { |
1422 | int eno = errno; | 1429 | int eno = errno; |
1423 | 1430 | ||