Subject: Re: bug#20733: coreutils build problem

From: Paul Eggert <[email-masked]>
Date: Sat, 06 Jun 2015 00:51:02 -0700

I installed the attached further patches to gnulib and to coreutils, 
respectively.  Could you please try:

http://www.cs.ucla.edu/~eggert/coreutils-8.23.212-d8a5.tar.xz
>From 4e02fe2fa7eaf841e8f84bf3a370ba4475ebee3c Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 5 Jun 2015 11:47:37 -0700
Subject: [PATCH] acl-permissions: more porting to AIX

* lib/file-has-acl.c (file_has_acl) [HAVE_STATACL]:
* lib/readutmp.c (read_utmp) [UTMP_NAME_FUNCTION]:
* lib/set-permissions.c (set_acls) [HAVE_ACLX_GET && ACL_AIX_WIP]:
Add cast for AIX, whose system calls are declared to accept
char * even though the arguments are really char const *.
* lib/mountlist.c (read_file_system_list) [MOUNTED_VMOUNT]:
Rework types to pacify xlc.
---
 ChangeLog             | 13 +++++++++++--
 lib/file-has-acl.c    |  2 +-
 lib/mountlist.c       |  8 +++++---
 lib/readutmp.c        |  2 +-
 lib/set-permissions.c |  2 +-
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 296ccaf..cba559d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,11 +5,20 @@
 
 2015-06-05  Paul Eggert  <[email-masked]>
 
-	acl-permissions: port to older AIX, C89 HP-UX
+	acl-permissions: port to AIX, C89 HP-UX
+	Problems reported by Michael Felt.
+	* lib/file-has-acl.c (file_has_acl) [HAVE_STATACL]:
+	* lib/get-permissions.c (get_permissions) [USE_ACL && HAVE_STATACL]:
+	* lib/readutmp.c (read_utmp) [UTMP_NAME_FUNCTION]:
+	* lib/set-permissions.c (set_acls) [HAVE_ACLX_GET && ACL_AIX_WIP]:
+	Add cast for AIX, whose system calls are declared to accept
+	char * even though the arguments are really char const *.
 	* lib/get-permissions.c (get_permissions):
 	If USE_ACL && HAVE_GETACL /* HP-UX */, don't assume C99.
 	If USE_ACL && HAVE_STATACL /* older AIX */, add missing decl
-	that broke a build, reported by Michael Felt.
+	that broke a build.
+	* lib/mountlist.c (read_file_system_list) [MOUNTED_VMOUNT]:
+	Rework types to pacify xlc.
 
 2015-06-03  Pádraig Brady  <[email-masked]>
 
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 7e26c53..8488b7e 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -457,7 +457,7 @@ file_has_acl (char const *name, struct stat const *sb)
 
       union { struct acl a; char room[4096]; } u;
 
-      if (statacl (name, STX_NORMAL, &u.a, sizeof (u)) < 0)
+      if (statacl ((char *) name, STX_NORMAL, &u.a, sizeof (u)) < 0)
         return -1;
 
       return acl_nontrivial (&u.a);
diff --git a/lib/mountlist.c b/lib/mountlist.c
index fe36157..d548252 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -970,18 +970,20 @@ read_file_system_list (bool need_fs_type)
 #ifdef MOUNTED_VMOUNT           /* AIX.  */
   {
     int bufsize;
-    char *entries, *thisent;
+    void *entries;
+    char *thisent;
     struct vmount *vmp;
     int n_entries;
     int i;
 
     /* Ask how many bytes to allocate for the mounted file system info.  */
-    if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0)
+    entries = &bufsize;
+    if (mntctl (MCTL_QUERY, sizeof bufsize, entries) != 0)
       return NULL;
     entries = xmalloc (bufsize);
 
     /* Get the list of mounted file systems.  */
-    n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
+    n_entries = mntctl (MCTL_QUERY, bufsize, entries);
     if (n_entries < 0)
       {
         int saved_errno = errno;
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 8a3936f..1005003 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -97,7 +97,7 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
      Solaris' utmpname returns 1 upon success -- which is contrary
      to what the GNU libc version does.  In addition, older GNU libc
      versions are actually void.   */
-  UTMP_NAME_FUNCTION (file);
+  UTMP_NAME_FUNCTION ((char *) file);
 
   SET_UTMP_ENT ();
 
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index ba291f3..2236879 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -699,7 +699,7 @@ set_acls (struct permission_context *ctx, const char *name, int desc,
       if (desc != -1)
 	ret = fchacl (desc, &ctx->u.a, ctx->u.a.acl_len);
       else
-	ret = chacl (name, &ctx->u.a, ctx->u.a.acl_len);
+	ret = chacl ((char *) name, &ctx->u.a, ctx->u.a.acl_len);
       if (ret < 0)
 	{
 	  if (errno == ENOSYS && from_mode)
-- 
2.1.0

>From d7d1ada451c2e14d8bde656aa1898ced8893ce2d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 5 Jun 2015 08:23:18 -0700
Subject: [PATCH 1/2] build: update gnulib submodule to latest

---
 gnulib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnulib b/gnulib
index fa21489..ecabc6b 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit fa214897526d2822e88175fd840cf08ca3e6ba81
+Subproject commit ecabc6b01567522dd542889c353a14f0c2e22f6e
-- 
2.1.0

>From d8a5fc98fd5d4f28adb5b43b2e496679d98fdc70 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 5 Jun 2015 17:33:54 -0700
Subject: [PATCH 2/2] build: port to AIX
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problems reported by Michael Felt, and and part of this fix taken
from code suggested by Pádraig Brady in:
http://bugs.gnu.org/20733#112
* configure.ac (stdbuf_supported): Check for warnings, and
for -fPIC and -shared, for AIX.
* src/stat.c (STRUCT_STATVFS): Define to struct statvfs64 if
STATFS is statvfs64.
* src/sync.c (sync_arg) [_AIX]: Open in write mode,
since AIX fsync doesn't work on read-only file descriptors.
* tests/misc/wc-parallel.sh: Skip test if xargs -P does not work.
---
 configure.ac              | 18 ++++++++++++++----
 src/stat.c                |  3 ++-
 src/sync.c                | 18 ++++++++++++++----
 tests/misc/wc-parallel.sh |  4 ++++
 4 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index c159983..a50992d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -454,8 +454,17 @@ if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
   gl_ADD_PROG([optional_bin_progs], [df])
 fi
 
-AC_MSG_CHECKING([whether this is system supports stdbuf])
-AC_COMPILE_IFELSE(
+ac_save_CFLAGS=$CFLAGS
+ac_save_LDFLAGS=$LDFLAGS
+# Detect warnings about ignored "constructor" attributes.
+gl_WARN_ADD([-Werror], [CFLAGS])
+gl_WARN_ADD([-errwarn], [CFLAGS])
+# Put this message here, after gl_WARN_ADD's chatter.
+AC_MSG_CHECKING([whether this system supports stdbuf])
+CFLAGS="-fPIC $CFLAGS"
+LDFLAGS="-shared $LDFLAGS"
+stdbuf_supported=no
+AC_LINK_IFELSE(
   [AC_LANG_PROGRAM([[
     static int stdbuf = 0;
 
@@ -470,12 +479,13 @@ AC_COMPILE_IFELSE(
     }]],[[
     return !(stdbuf == 1);]])
   ],
-  [stdbuf_supported=yes],
-  [stdbuf_supported=no])
+  [stdbuf_supported=yes])
 AC_MSG_RESULT([$stdbuf_supported])
 if test "$stdbuf_supported" = "yes" && test -z "$EXEEXT"; then
   gl_ADD_PROG([optional_bin_progs], [stdbuf])
 fi
+CFLAGS=$ac_save_CFLAGS
+LDFLAGS=$ac_save_LDFLAGS
 
 ############################################################################
 
diff --git a/src/stat.c b/src/stat.c
index 4b5aff7..6d23665 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -74,15 +74,16 @@
 #include "xvasprintf.h"
 
 #if USE_STATVFS
-# define STRUCT_STATVFS struct statvfs
 # define STRUCT_STATXFS_F_FSID_IS_INTEGER STRUCT_STATVFS_F_FSID_IS_INTEGER
 # define HAVE_STRUCT_STATXFS_F_TYPE HAVE_STRUCT_STATVFS_F_TYPE
 # if HAVE_STRUCT_STATVFS_F_NAMEMAX
 #  define SB_F_NAMEMAX(S) ((S)->f_namemax)
 # endif
 # if ! STAT_STATVFS && STAT_STATVFS64
+#  define STRUCT_STATVFS struct statvfs64
 #  define STATFS statvfs64
 # else
+#  define STRUCT_STATVFS struct statvfs
 #  define STATFS statvfs
 # endif
 # define STATFS_FRSIZE(S) ((S)->f_frsize)
diff --git a/src/sync.c b/src/sync.c
index 85d77c0..5e1dbb8 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -91,24 +91,34 @@ static bool
 sync_arg (enum sync_mode mode, char const *file)
 {
   bool ret = true;
+  int open_flags = O_RDONLY | O_NONBLOCK;
   int fd;
 
+#ifdef _AIX
+  /* AIX 7.1 fsync requires write access to file.  */
+  if (mode == MODE_FILE)
+    open_flags = O_WRONLY | O_NONBLOCK;
+#endif
+
   /* Note O_PATH might be supported with syncfs(),
      though as of Linux 3.18 is not.  */
-  if ((fd = open (file, O_RDONLY | O_NONBLOCK)) < 0)
+  fd = open (file, open_flags);
+  if (fd < 0)
     {
       /* Use the O_RDONLY errno, which is significant
          with directories for example.  */
       int rd_errno = errno;
-      if ((fd = open (file, O_WRONLY | O_NONBLOCK)) < 0)
+      if (open_flags != (O_WRONLY | O_NONBLOCK))
+        fd = open (file, O_WRONLY | O_NONBLOCK);
+      if (fd < 0)
         error (0, rd_errno, _("error opening %s"), quote (file));
       return false;
     }
 
   /* We used O_NONBLOCK above to not hang with fifos,
      so reset that here.  */
-  int fdflags;
-  if ((fdflags = fcntl (fd, F_GETFL)) == -1
+  int fdflags = fcntl (fd, F_GETFL);
+  if (fdflags == -1
       || fcntl (fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
     {
       error (0, errno, _("couldn't reset non-blocking mode %s"), quote (file));
diff --git a/tests/misc/wc-parallel.sh b/tests/misc/wc-parallel.sh
index 2d1e9f4..98c36b9 100755
--- a/tests/misc/wc-parallel.sh
+++ b/tests/misc/wc-parallel.sh
@@ -20,6 +20,10 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ wc
 
+if xargs -P2 </dev/null >/dev/null 2>&1
+  skip_ 'xargs -P is required'
+fi
+
 (mkdir tmp && cd tmp && seq 2000 | xargs touch)
 
 # This will output at least 16KiB per process
-- 
2.1.0