1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
Description: Fix FTBFS on kfreebsd due to missing SOCK_CLOEXEC
Work around missing SOCK_CLOEXEC on kfreebsd
by setting FD_CLOEXEC afterwards.
Author: Tino Mettler <tino+debian@tikei.de>
Last-Update: 2021-09-29
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
@@ -285,6 +285,10 @@
true);
}
+#ifndef SOCK_CLOEXEC
+#define SOCK_CLOEXEC 0
+#endif
+
std::shared_ptr<DBusServerCXX> DBusServerCXX::listen(const NewConnection_t &newConnection, DBusErrorCXX *)
{
// Create two fds connected via a two-way stream. The parent
@@ -295,6 +299,21 @@
if (retval) {
SE_THROW(StringPrintf("socketpair: %s", strerror(errno)));
}
+
+ if(SOCK_CLOEXEC == 0) {
+ int flags;
+ int i;
+ for(i = 0; i < 2; i++) {
+ flags = fcntl(fds[i], F_GETFD);
+ if (flags == -1){
+ SE_THROW(StringPrintf("fcntl: %s", strerror(errno)));
+ }
+ flags |= FD_CLOEXEC;
+ if (fcntl(fds[i], F_SETFD, flags) == -1){
+ SE_THROW(StringPrintf("fcntl: %s", strerror(errno)));
+ }
+ }
+ }
GuardFD parentfd(fds[0]);
GuardFD childfd(fds[1]);
|