1From 5a43d0f724c56f8836f3f92411e0de1b5f82db32 Mon Sep 17 00:00:00 2001
2From: Sam James <sam@gentoo.org>
3Date: Sat, 24 Jul 2021 22:02:45 +0100
4Subject: [PATCH] util/ulockmgr_server.c: conditionally define closefrom (fix
5 glibc-2.34+)
6
7closefrom(3) has joined us in glibc-land from *BSD and Solaris. Since
8it's available in glibc 2.34+, we want to detect it and only define our
9fallback if the libc doesn't provide it.
10
11Bug: https://bugs.gentoo.org/803923
12Signed-off-by: Sam James <sam@gentoo.org>
13
14[Retrieved from:
15https://github.com/libfuse/libfuse/commit/5a43d0f724c56f8836f3f92411e0de1b5f82db32]
16Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
17---
18 configure.ac           | 1 +
19 util/ulockmgr_server.c | 6 ++++++
20 2 files changed, 7 insertions(+)
21
22diff --git a/configure.ac b/configure.ac
23index 9946a0efa..a2d481aa9 100644
24--- a/configure.ac
25+++ b/configure.ac
26@@ -55,6 +55,7 @@ fi
27
28 AC_CHECK_FUNCS([fork setxattr fdatasync splice vmsplice utimensat])
29 AC_CHECK_FUNCS([posix_fallocate])
30+AC_CHECK_FUNCS([closefrom])
31 AC_CHECK_MEMBERS([struct stat.st_atim])
32 AC_CHECK_MEMBERS([struct stat.st_atimespec])
33
34diff --git a/util/ulockmgr_server.c b/util/ulockmgr_server.c
35index 273c7d923..a04dac5c6 100644
36--- a/util/ulockmgr_server.c
37+++ b/util/ulockmgr_server.c
38@@ -22,6 +22,10 @@
39 #include <sys/socket.h>
40 #include <sys/wait.h>
41
42+#ifdef HAVE_CONFIG_H
43+	#include "config.h"
44+#endif
45+
46 struct message {
47 	unsigned intr : 1;
48 	unsigned nofd : 1;
49@@ -124,6 +128,7 @@ static int receive_message(int sock, void *buf, size_t buflen, int *fdp,
50 	return res;
51 }
52
53+#if !defined(HAVE_CLOSEFROM)
54 static int closefrom(int minfd)
55 {
56 	DIR *dir = opendir("/proc/self/fd");
57@@ -141,6 +146,7 @@ static int closefrom(int minfd)
58 	}
59 	return 0;
60 }
61+#endif
62
63 static void send_reply(int cfd, struct message *msg)
64 {
65