[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: kernel on buildd (Re: [Glibc-bsd-commits] r5714 - trunk/glibc-ports/kfreebsd/bits)



Hi!

On Thu, 2015-05-28 at 09:00:41 +0200, Petr Salinger wrote:
> what is currently used kernel on buildd for kfreebsd-* ?
> 
> According to last log of util-linux (22 May 2015/fayrfax.debian.org):
> Kernel: GNU/kFreeBSD 9.0-2-amd64 kfreebsd-amd64 (x86_64)
> 
> Please beware, that F_DUPFD_CLOEXEC is not supported on this kernel.
> The addition of F_DUPFD_CLOEXEC bellow is long term way, but in mean time
> (until buildd is upgraded to 10.x), we need to use fallback to previous code
> path in util-linux.

That might be needed only if that code path is executed on the buildds,
something I'm not sure about.

In any case here's the patches I've prepared to send upstream. Only
build tested, though.

Thanks,
Guillem
From e8cfe3d17d61e19203445cbf96a136fad30fc05a Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Thu, 28 May 2015 17:46:02 +0200
Subject: [PATCH 1/3] include/c: Define F_DUPFD_CLOEXEC on kFreeBSD systems if
 missing

The kernel of FreeBSD version 10 and higher supports this fcntl command,
but the system libc, in this case glibc, might not yet know about it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
---
 include/c.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/c.h b/include/c.h
index a72e264..1eda75f 100644
--- a/include/c.h
+++ b/include/c.h
@@ -231,6 +231,12 @@ static inline int dirfd(DIR *d)
 #define O_CLOEXEC 0
 #endif
 
+#ifdef __FreeBSD_kernel__
+#ifndef F_DUPFD_CLOEXEC
+#define F_DUPFD_CLOEXEC	17	/* Like F_DUPFD, but FD_CLOEXEC is set */
+#endif
+#endif
+
 
 #ifndef AI_ADDRCONFIG
 #define AI_ADDRCONFIG 0x0020
-- 
2.2.1.209.g41e5f3a

From 0267c0f4e739b788a90500446173585502e6ddb3 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Thu, 28 May 2015 17:51:09 +0200
Subject: [PATCH 2/3] lib/fileutils: Add new dup_fd_cloexec function

This function duplicates and marks a file descriptor as close-on-exec.
Takes care of build and run-time support for the fcntl F_DUPFD_CLOEXEC
command, and other errors.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
---
 include/fileutils.h |  1 +
 lib/fileutils.c     | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/fileutils.h b/include/fileutils.h
index 3353f69..e0e2ece 100644
--- a/include/fileutils.h
+++ b/include/fileutils.h
@@ -25,6 +25,7 @@ static inline FILE *xfmkstemp(char **tmpname, char *dir)
 	return ret;
 }
 
+extern int dup_fd_cloexec(int oldfd, int lowfd);
 extern int get_fd_tabsize(void);
 
 extern int mkdir_p(const char *path, mode_t mode);
diff --git a/lib/fileutils.c b/lib/fileutils.c
index bffa8ff..81b38ad 100644
--- a/lib/fileutils.c
+++ b/lib/fileutils.c
@@ -50,6 +50,36 @@ int xmkstemp(char **tmpname, char *dir)
 	return fd;
 }
 
+int dup_fd_cloexec(int oldfd, int lowfd)
+{
+	int fd, flags, errno_save;
+
+#ifdef F_DUPFD_CLOEXEC
+	fd = fcntl(oldfd, F_DUPFD_CLOEXEC, lowfd);
+	if (fd >= 0)
+		return fd;
+#endif
+
+	fd = dup(oldfd);
+	if (fd < 0)
+		return fd;
+
+	flags = fcntl(fd, F_GETFD);
+	if (flags < 0)
+		goto unwind;
+	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
+		goto unwind;
+
+	return fd;
+
+unwind:
+	errno_save = errno;
+	close(fd);
+	errno = errno_save;
+
+	return -1;
+}
+
 /*
  * portable getdtablesize()
  */
-- 
2.2.1.209.g41e5f3a

From 53e0536299ae17540a465fe3f71a636676abb965 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Thu, 28 May 2015 17:52:33 +0200
Subject: [PATCH 3/3] lib/sysfs: Use dup_fd_cloexec instead of direct call to
 fcntl

Signed-off-by: Guillem Jover <guillem@hadrons.org>
---
 lib/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 1ea2e77..975e264 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -265,7 +265,7 @@ DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr)
 		 * -- we cannot use cxt->sysfs_fd directly, because closedir()
 		 * will close this our persistent file descriptor.
 		 */
-		fd = fcntl(cxt->dir_fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
+		fd = dup_fd_cloexec(cxt->dir_fd, STDERR_FILENO + 1);
 
 	if (fd < 0)
 		return NULL;
-- 
2.2.1.209.g41e5f3a


Reply to: