e55c42
From ae2352bca9b4e607538412da0cc2a9625cd8b692 Mon Sep 17 00:00:00 2001
e55c42
From: Sam James <sam@gentoo.org>
e55c42
Date: Sat, 24 Jul 2021 22:02:45 +0100
e55c42
Subject: [PATCH] util/ulockmgr_server.c: conditionally define closefrom (fix
e55c42
 glibc-2.34+)
e55c42
e55c42
closefrom(3) has joined us in glibc-land from *BSD and Solaris. Since
e55c42
it's available in glibc 2.34+, we want to detect it and only define our
e55c42
fallback if the libc doesn't provide it.
e55c42
e55c42
Bug: https://bugs.gentoo.org/803923
e55c42
Signed-off-by: Sam James <sam@gentoo.org>
e55c42
---
e55c42
 configure.ac           | 1 +
e55c42
 util/ulockmgr_server.c | 6 ++++++
e55c42
 2 files changed, 7 insertions(+)
e55c42
e55c42
diff --git a/configure.ac b/configure.ac
e55c42
index 9946a0efa..a2d481aa9 100644
e55c42
--- a/configure.ac
e55c42
+++ b/configure.ac
e55c42
@@ -55,6 +55,7 @@ fi
e55c42
 
e55c42
 AC_CHECK_FUNCS([fork setxattr fdatasync splice vmsplice utimensat])
e55c42
 AC_CHECK_FUNCS([posix_fallocate])
e55c42
+AC_CHECK_FUNCS([closefrom])
e55c42
 AC_CHECK_MEMBERS([struct stat.st_atim])
e55c42
 AC_CHECK_MEMBERS([struct stat.st_atimespec])
e55c42
 
e55c42
diff --git a/util/ulockmgr_server.c b/util/ulockmgr_server.c
e55c42
index 273c7d923..a04dac5c6 100644
e55c42
--- a/util/ulockmgr_server.c
e55c42
+++ b/util/ulockmgr_server.c
e55c42
@@ -22,6 +22,10 @@
e55c42
 #include <sys/socket.h>
e55c42
 #include <sys/wait.h>
e55c42
 
e55c42
+#ifdef HAVE_CONFIG_H
e55c42
+	#include "config.h"
e55c42
+#endif
e55c42
+
e55c42
 struct message {
e55c42
 	unsigned intr : 1;
e55c42
 	unsigned nofd : 1;
e55c42
@@ -124,6 +128,7 @@ static int receive_message(int sock, void *buf, size_t buflen, int *fdp,
e55c42
 	return res;
e55c42
 }
e55c42
 
e55c42
+#if !defined(HAVE_CLOSEFROM)
e55c42
 static int closefrom(int minfd)
e55c42
 {
e55c42
 	DIR *dir = opendir("/proc/self/fd");
e55c42
@@ -141,6 +146,7 @@ static int closefrom(int minfd)
e55c42
 	}
e55c42
 	return 0;
e55c42
 }
e55c42
+#endif
e55c42
 
e55c42
 static void send_reply(int cfd, struct message *msg)
e55c42
 {