Skip to contentSkip to conversation

Various portability fixes

PATCH New Michael Forney 2 participants 6 messages Oct 3, 2013 – Oct 4, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hi,

These patches address various portability issues. They are needed to build util-linux against musl libc.

#1 lore raw

PATCH 1/4 Use _POSIX_VERSION to determine support for %m

%m is included in POSIX 2008, so we can check if the libc implements that before failing.

---
 configure.ac | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
configure.ac +7 -1
index cbcda46..95ff8b3 100644
@@ -430,6 +430,7 @@ AC_CACHE_VAL([scanf_cv_alloc_modifier],
 
     [AC_COMPILE_IFELSE([AC_LANG_SOURCE([
      #include <stdio.h>
+     #include <unistd.h>
 
      #ifdef __GLIBC__
 
@@ -437,8 +438,13 @@ AC_CACHE_VAL([scanf_cv_alloc_modifier],
      #error %m is not available
      #endif
 
-     #else
+     #elif defined(_POSIX_VERSION)
 
+     #if _POSIX_VERSION < 200809L
+     #error %m is not available
+     #endif
+
+     #else
      #error Your C-library is not supported.
      #endif
      ])],
Signature · 1 line
1.8.4
#2 lore raw

PATCH 2/4 Add missing includes

In reply to Michael Forney

sys/types.h: For u_char typedef
sys/params.h: For MAXNAMLEN
sys/ttydefaults.h: For various tty definitions (also add configure check)

---
 configure.ac         | 1 +
 include/ttyutils.h   | 3 +++
 term-utils/ttymsg.c  | 1 +
 text-utils/display.c | 1 +
 4 files changed, 6 insertions(+)
configure.ac +1 -0
index 95ff8b3..12d0bab 100644
@@ -204,6 +204,7 @@ AC_CHECK_HEADERS([ \
 	sys/swap.h \
 	sys/syscall.h \
 	sys/time.h \
+	sys/ttydefaults.h \
 	sys/types.h \
 	sys/un.h \
 	unistd.h \
include/ttyutils.h +3 -0
index 13495ba..4f2fd88 100644
@@ -13,6 +13,9 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifdef HAVE_SYS_TTYDEFAULTS_H
+#include <sys/ttydefaults.h>
+#endif
 
 /* Some shorthands for control characters. */
 #define CTL(x)		((x) ^ 0100)	/* Assumes ASCII dialect */
term-utils/ttymsg.c +1 -0
index d610826..8bf993c 100644
@@ -41,6 +41,7 @@
   */
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/uio.h>
 #include <signal.h>
 #include <fcntl.h>
text-utils/display.c +1 -0
index 1f9a11b..1130366 100644
@@ -33,6 +33,7 @@
 
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include <errno.h>
 #include <ctype.h>
Signature · 1 line
1.8.4
#3 lore raw

PATCH 3/4 Check for type sighandler_t and use if present

In reply to Michael Forney

__sighandler_t is libc implementation specific and should not be relied upon. Instead, we fall back upon void (*)(int), as specified by POSIX.

---
 configure.ac    | 4 ++++
 fdisks/cfdisk.c | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
configure.ac +4 -0
index 12d0bab..93572fe 100644
@@ -497,6 +497,10 @@ AC_CHECK_TYPES([cpu_set_t], [have_cpu_set_t=yes], [], [[
 
 AM_CONDITIONAL([HAVE_CPU_SET_T], [test "x$have_cpu_set_t" = xyes])
 
+AC_CHECK_TYPES([sighandler_t], [], [], [[
+#include <signal.h>
+]])
+
 AC_CHECK_DECLS([CPU_ALLOC], [], [], [[
 #include <sched.h>
 ]])
fdisks/cfdisk.c +5 -1
index 5007fc9..bb32433 100644
@@ -324,7 +324,11 @@ int num_parts = 0;
 int logical = 0;
 long long logical_sectors[MAXIMUM_PARTS];
 
-__sighandler_t old_SIGINT, old_SIGTERM;
+#ifdef HAVE_SIGHANDLER_T
+sighandler_t old_SIGINT, old_SIGTERM;
+#else
+void (* old_SIGINT)(int), (* old_SIGTERM)(int);
+#endif
 
 int arrow_cursor = FALSE;
 int display_units = MEGABYTES;
Signature · 1 line
1.8.4
#4 lore raw

PATCH 4/4 Fix check for __GNU_LIBRARY__

In reply to Michael Forney

If we are not on glibc, __GNU_LIBRARY__ will not exist causing the check to always fail and try to use syscalls directly.

---
 term-utils/setterm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
term-utils/setterm.c +1 -1
index d41e335..f179ea8 100644
@@ -124,7 +124,7 @@
 #include "nls.h"
 #include "closestream.h"
 
-#if __GNU_LIBRARY__ < 5
+#if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ < 5
 #ifndef __alpha__
 # include <linux/unistd.h>
 #define __NR_klogctl __NR_syslog
Signature · 1 line
1.8.4
maintainer Applied
#5 lore raw
In reply to Michael Forney
Quoted 2 lines · Michael Forney

These patches address various portability issues. They are needed to build util-linux against musl libc.

Applied, thanks! (Please, use "Signed-off-by:" next time.)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com