# fcntl-intercept.diff -rw-r--r-- 980 bytes View raw
                                                                                
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
43
44
diff --git a/src/wayland-os.c b/src/wayland-os.c
index a9066cae9c93..8bf13bf37544 100644
--- a/src/wayland-os.c
+++ b/src/wayland-os.c
@@ -42,6 +42,9 @@
 
 #include "wayland-os.h"
 
+/* used by tests */
+int (*wl_fcntl)(int fildes, int cmd, ...) = fcntl;
+
 static int
 set_cloexec_or_close(int fd)
 {
@@ -50,11 +53,11 @@ set_cloexec_or_close(int fd)
 	if (fd == -1)
 		return -1;
 
-	flags = fcntl(fd, F_GETFD);
+	flags = wl_fcntl(fd, F_GETFD);
 	if (flags == -1)
 		goto err;
 
-	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+	if (wl_fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
 		goto err;
 
 	return fd;
@@ -124,13 +127,13 @@ wl_os_dupfd_cloexec(int fd, int minfd)
 {
 	int newfd;
 
-	newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
+	newfd = wl_fcntl(fd, F_DUPFD_CLOEXEC, minfd);
 	if (newfd >= 0)
 		return newfd;
 	if (errno != EINVAL)
 		return -1;
 
-	newfd = fcntl(fd, F_DUPFD, minfd);
+	newfd = wl_fcntl(fd, F_DUPFD, minfd);
 	return set_cloexec_or_close(newfd);
 }