[Libguestfs] [nbdkit PATCH v2 04/17] Revert "RHEL 5: Define O_CLOEXEC and SOCK_CLOEXEC."

Eric Blake eblake at redhat.com
Fri Aug 2 19:26:05 UTC 2019


This reverts commit 25206df20275aeff346d9b86adf5e9be99cc9e43, and
temporarily breaks compilation on Haiku which has O_CLOEXEC but lacks
SOCK_CLOEXEC [1].

An upcoming patch wants to ensure no leaked fds from the server to a
child process.  POSIX has required O_CLOEXEC since 2008, and that is
long enough that we should start blindly relying on it.  Meanwhile,
POSIX doesn't yet specify full atomic interfaces everywhere
(SOCK_CLOEXEC and accept4 when dealing with sockets, pipe2 when
dealing with pipes, mkostemp and fopen("re") when dealing with stdio,
etc.), but there has been an open bug since 2014 [2] recommending the
full set of interfaces that will be mandatory in the next revision of
POSIX.  Most modern OS have caught up to that (RHEL 6 and FreeBSD 10
support SOCK_CLOEXEC, for example), and we're doing ourselves a
disservice by using a globally-silent and leaky fallback instead of
actively documenting at each site that prefers to use the new
interfaces whether the use is essential or merely reducing lines of
code, for the sake of systems that are behind in atomic support.

[1] https://dev.haiku-os.org/ticket/15219
[2] http://austingroupbugs.net/view.php?id=411

Conflicts:
 filters/xz/xzfile.c - The fallback moved from plugins/xz/xzfile.c (and
in fact has been dead code since commit c879d310 made it a filter)
 plugins/file/file.c - context changes in the meantime
 src/internal.h - Moved to server/internal.h
 plugins/split/split.c - Not in the original patch; copied in 9ad64ba5
---
 server/internal.h             | 8 --------
 common/utils/utils.c          | 1 +
 filters/xz/xzfile.c           | 4 ----
 plugins/example2/example2.c   | 4 ----
 plugins/file/file.c           | 4 ----
 plugins/split/split.c         | 4 ----
 plugins/streaming/streaming.c | 4 ----
 7 files changed, 1 insertion(+), 28 deletions(-)

diff --git a/server/internal.h b/server/internal.h
index 80ab879c..6207f0cf 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -50,14 +50,6 @@
 #define UNIX_PATH_MAX 108
 #endif

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
-#ifndef SOCK_CLOEXEC
-#define SOCK_CLOEXEC 0
-#endif
-
 #if HAVE_VALGRIND
 # include <valgrind.h>
 /* http://valgrind.org/docs/manual/faq.html#faq.unhelpful */
diff --git a/common/utils/utils.c b/common/utils/utils.c
index 37c81871..f81a8433 100644
--- a/common/utils/utils.c
+++ b/common/utils/utils.c
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
diff --git a/filters/xz/xzfile.c b/filters/xz/xzfile.c
index ebe7f29c..ee4af713 100644
--- a/filters/xz/xzfile.c
+++ b/filters/xz/xzfile.c
@@ -52,10 +52,6 @@

 #include "xzfile.h"

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
 #define XZ_HEADER_MAGIC     "\xfd" "7zXZ\0"
 #define XZ_HEADER_MAGIC_LEN 6
 #define XZ_FOOTER_MAGIC     "YZ"
diff --git a/plugins/example2/example2.c b/plugins/example2/example2.c
index d0bce155..6adc100a 100644
--- a/plugins/example2/example2.c
+++ b/plugins/example2/example2.c
@@ -48,10 +48,6 @@

 #include <nbdkit-plugin.h>

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
 static char *filename = NULL;

 /* A debug flag which can be set on the command line using
diff --git a/plugins/file/file.c b/plugins/file/file.c
index 52d330f7..9df5001d 100644
--- a/plugins/file/file.c
+++ b/plugins/file/file.c
@@ -61,10 +61,6 @@
 #include "cleanup.h"
 #include "isaligned.h"

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
 #ifndef HAVE_FDATASYNC
 #define fdatasync fsync
 #endif
diff --git a/plugins/split/split.c b/plugins/split/split.c
index 1b8e69a2..68682b29 100644
--- a/plugins/split/split.c
+++ b/plugins/split/split.c
@@ -45,10 +45,6 @@

 #include <nbdkit-plugin.h>

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
 /* The files. */
 static char **filenames = NULL;
 static size_t nr_files = 0;
diff --git a/plugins/streaming/streaming.c b/plugins/streaming/streaming.c
index 4ca3e765..4ab73b8b 100644
--- a/plugins/streaming/streaming.c
+++ b/plugins/streaming/streaming.c
@@ -43,10 +43,6 @@

 #include <nbdkit-plugin.h>

-#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
-#endif
-
 static char *filename = NULL;
 static int fd = -1;

-- 
2.20.1




More information about the Libguestfs mailing list