Skip to contentSkip to conversation

util-linux: add a check for mkostemp()

PATCH New Romain Naour 2 participants 3 messages Apr 6, 2014 – Apr 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 util-linux: add a check for mkostemp()

mkostemp() is missing with older version of uClibc (uClibc <= 0.9.33). So, we need to check if mkostemp() is available.
If not, we use a wrapper function based on mkstemp() to implement it.

Since util-linux v2.23, mkostemp() is called with O_CLOEXEC flag. If we use a define to mkstemp() to implement mkostemp(), flags will be discared.
mkstemp() will pass O_RDWR|O_CREAT|O_EXCL, but not O_CLOEXEC, which means that the file descriptor will no longer be closed automatically upon exec().

To avoid to discard the flags, we add a call to fcntl() to set O_CLOEXEC flag just after mkstemp().

---
v2: add a check for mkostemp() instead of using a define for uClibc case. (ThomasP)

 ...fine-mkostemp-for-older-version-of-uClibc.patch | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 package/util-linux/util-linux-004-c.h-define-mkostemp-for-older-version-of-uClibc.patch
package/util-linux/util-linux-004-c.h-define-mkostemp-for-older-version-of-uClibc.patch new file +50 -0
new file mode 100644
index 0000000..0dfe7be
@@ -0,0 +1,50 @@
+From 42a84250fc78bae3e885ecd1379e713663fe6487 Mon Sep 17 00:00:00 2001
+From: Romain Naour <[email protected]>
+Date: Sun, 6 Apr 2014 12:12:41 +0200
+Subject: [PATCH 1/1] c.h: define mkostemp for older version of uClibc
+
+Signed-off-by: Romain Naour <[email protected]>
+---
+ configure.ac |  2 ++
+ include/c.h  | 14 ++++++++++++++
+ 2 files changed, 16 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index 35a1f26..a9b8d34 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -321,6 +321,8 @@ AC_CHECK_FUNCS([ \
+ ])
+ AC_FUNC_FSEEKO
+ 
++AC_CHECK_FUNCS([mkostemp])
++
+ AC_CHECK_FUNCS([openat fstatat unlinkat], [have_openat=yes], [have_openat=no])
+ AC_CHECK_FUNCS([ioperm iopl], [have_io=yes])
+ 
+diff --git a/include/c.h b/include/c.h
+index 4a9bf3d..1b880ed 100644
+--- a/include/c.h
++++ b/include/c.h
+@@ -300,4 +300,18 @@ static inline int usleep(useconds_t usec)
+ # define SEEK_HOLE	4
+ #endif
+ 
++/*
++ * mkostemp() may be missing with older version of uClibc
++ */
++#ifndef HAVE_MKOSTEMP
++static inline int mkostemp(char *template, int flags)
++{
++	int fd;
++	fd = mkstemp(template);
++	if (flags & O_CLOEXEC && fd >= 0)
++		fcntl(fd, F_SETFD, FD_CLOEXEC);
++	return fd;
++}
++#endif
++
+ #endif /* UTIL_LINUX_C_H */
+-- 
+1.9.0
+
Signature · 1 line
1.9.0
#1 lore raw

PATCH v2 2/2 util-linux: add missing dependency on libcap-ng

---
 package/util-linux/util-linux.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/util-linux/util-linux.mk +4 -0
index d661447..f0ae3ae 100644
@@ -40,6 +40,10 @@ UTIL_LINUX_DEPENDENCIES += gettext
 UTIL_LINUX_MAKE_OPT += LIBS=-lintl
 endif
 
+ifeq ($(BR2_PACKAGE_LIBCAP_NG),y)
+UTIL_LINUX_DEPENDENCIES += libcap-ng
+endif
+
 # Used by cramfs utils
 UTIL_LINUX_DEPENDENCIES += $(if $(BR2_PACKAGE_ZLIB),zlib)
 
Signature · 1 line
1.9.0
#2 lore raw

PATCH v2 1/2 util-linux: add a check for mkostemp()

In reply to Romain Naour
Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Romain" == Romain Naour <[email protected]> writes:

mkostemp() is missing with older version of uClibc (uClibc <= 0.9.33). So, we need to check if mkostemp() is available.
If not, we use a wrapper function based on mkstemp() to implement it.

Since util-linux v2.23, mkostemp() is called with O_CLOEXEC flag. If we use a define to mkstemp() to implement mkostemp(), flags will be discared.
mkstemp() will pass O_RDWR|O_CREAT|O_EXCL, but not O_CLOEXEC, which means that the file descriptor will no longer be closed automatically upon exec().

Quoted 6 lines

To avoid to discard the flags, we add a call to fcntl() to set O_CLOEXEC flag just after mkstemp().

---
v2: add a check for mkostemp() instead of using a define for uClibc case. (ThomasP)

Committed both, thanks. Don't forget to send the patch upstream.

Signature · 1 line
Bye, Peter Korsgaard