File: 1001_SOCK_CLOEXEC.patch

package info (click to toggle)
syncevolution 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,712 kB
  • sloc: cpp: 63,872; ansic: 14,604; python: 11,373; xml: 9,152; perl: 1,452; sh: 841; makefile: 318
file content (42 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download | duplicates (2)
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/
--- a/src/gdbusxx/gdbus-cxx-bridge.cpp
+++ b/src/gdbusxx/gdbus-cxx-bridge.cpp
@@ -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]);