From 932332e660a458e51068937130d557fb4acc6630 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 16 Apr 2023 13:15:03 +0200 Subject: [PATCH] Use pipe in vgdb if system doesn't have pipe2 Add a configure check for pipe2. If it isn't available use pipe and fcntl F_SETFD FD_CLOEXEC in vgdb.c. https://bugs.kde.org/show_bug.cgi?id=468556 --- NEWS | 1 + configure.ac | 1 + coregrind/vgdb.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/NEWS b/NEWS index a8ab817e17..6af3169d5a 100644 --- a/NEWS +++ b/NEWS @@ -151,6 +151,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 467714 fdleak_* and rlimit tests fail when parent process has more than 64 descriptors opened 467839 Gdbserver: Improve compatibility of library directory name +468556 Build failure for vgdb n-i-bz FreeBSD rfork syscall fail with EINVAL or ENOSYS rather than VG_(unimplemented) To see details of a given bug, visit diff --git a/configure.ac b/configure.ac index 66437a8000..a886d0deaa 100755 --- a/configure.ac +++ b/configure.ac @@ -4820,6 +4820,7 @@ AC_CHECK_FUNCS([ \ memset \ mkdir \ mremap \ + pipe2 \ ppoll \ preadv \ preadv2 \ diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index c4a7042984..7ed9a8b2e9 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -1142,11 +1142,28 @@ int fork_and_exec_valgrind (int argc, char **argv, const char *working_dir, // We will use a pipe to track what the child does, // so we can report failure. int pipefd[2]; +#ifdef HAVE_PIPE2 if (pipe2 (pipefd, O_CLOEXEC) == -1) { err = errno; perror ("pipe2 failed"); return err; } +#else + if (pipe (pipefd) == -1) { + err = errno; + perror ("pipe failed"); + return err; + } else { + if (fcntl (pipefd[0], F_SETFD, FD_CLOEXEC) == -1 + || fcntl (pipefd[1], F_SETFD, FD_CLOEXEC) == -1) { + err = errno; + perror ("fcntl failed"); + close (pipefd[0]); + close (pipefd[1]); + return err; + } + } +#endif pid_t p = fork (); if (p < 0) { -- 2.43.5