]> Savannah Git Hosting - gnulib.git/commitdiff
dup2, fcntl: port to AIX
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 18 Feb 2015 02:34:17 +0000 (18:34 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 18 Feb 2015 02:34:48 +0000 (18:34 -0800)
* m4/dup2.m4 (gl_FUNC_DUP2):
* m4/fcntl.m4 (gl_FUNC_FCNTL):
Prefer getrusage (RLIM_NOFILE ...)/rlim_cur to sysconf (_SC_OPEN_MAX).
The former works on AIX 7.1 but the latter does not.
Also, this may work better with Android; see:
http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00100.html

ChangeLog
m4/dup2.m4
m4/fcntl.m4

index 5083e95f6b67e49bf76a0a7a1f713fd3796d2c46..f3b7b3ac51f4e28ad14cfc9c9aee7136da6399e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2015-02-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+       dup2, fcntl: port to AIX
+       * m4/dup2.m4 (gl_FUNC_DUP2):
+       * m4/fcntl.m4 (gl_FUNC_FCNTL):
+       Prefer getrusage (RLIM_NOFILE ...)/rlim_cur to sysconf (_SC_OPEN_MAX).
+       The former works on AIX 7.1 but the latter does not.
+       Also, this may work better with Android; see:
+       http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00100.html
+
 2015-02-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        getdtablesize, dup2, fcntl: port to Android
index c47ef2786730db6de6d685d1682d6c7d1dd63b52..fec42b0d5a28cffe67440f02081e3d3d2b4955c8 100644 (file)
@@ -19,40 +19,44 @@ AC_DEFUN([gl_FUNC_DUP2],
   if test $HAVE_DUP2 = 1; then
     AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
       [AC_RUN_IFELSE([
-         AC_LANG_PROGRAM([[#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>]],
-           [int result = 0;
-            int bad_fd = INT_MAX;
-#ifdef _SC_OPEN_MAX
-            long int open_max = sysconf (_SC_OPEN_MAX);
-            if (0 <= open_max && open_max <= INT_MAX)
-              bad_fd = open_max;
-#endif
-#ifdef FD_CLOEXEC
-            if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
-              result |= 1;
-#endif
-            if (dup2 (1, 1) == 0)
-              result |= 2;
-#ifdef FD_CLOEXEC
-            if (fcntl (1, F_GETFD) != FD_CLOEXEC)
-              result |= 4;
-#endif
-            close (0);
-            if (dup2 (0, 0) != -1)
-              result |= 8;
-            /* Many gnulib modules require POSIX conformance of EBADF.  */
-            if (dup2 (2, bad_fd) == -1 && errno != EBADF)
-              result |= 16;
-            /* Flush out some cygwin core dumps.  */
-            if (dup2 (2, -1) != -1 || errno != EBADF)
-              result |= 32;
-            dup2 (2, 255);
-            dup2 (2, 256);
-            return result;
-           ])
+         AC_LANG_PROGRAM(
+           [[#include <errno.h>
+             #include <fcntl.h>
+             #include <limits.h>
+             #include <sys/resource.h>
+             #include <unistd.h>
+           ]],
+           [[int result = 0;
+             int bad_fd = INT_MAX;
+             struct rlimit rlim;
+             if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
+                 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
+                 && rlim.rlim_cur != RLIM_INFINITY
+                 && rlim.rlim_cur != RLIM_SAVED_MAX
+                 && rlim.rlim_cur != RLIM_SAVED_CUR)
+               bad_fd = rlim.rlim_cur;
+             #ifdef FD_CLOEXEC
+               if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
+                 result |= 1;
+             #endif
+             if (dup2 (1, 1) == 0)
+               result |= 2;
+             #ifdef FD_CLOEXEC
+               if (fcntl (1, F_GETFD) != FD_CLOEXEC)
+                 result |= 4;
+             #endif
+             close (0);
+             if (dup2 (0, 0) != -1)
+               result |= 8;
+             /* Many gnulib modules require POSIX conformance of EBADF.  */
+             if (dup2 (2, bad_fd) == -1 && errno != EBADF)
+               result |= 16;
+             /* Flush out some cygwin core dumps.  */
+             if (dup2 (2, -1) != -1 || errno != EBADF)
+               result |= 32;
+             dup2 (2, 255);
+             dup2 (2, 256);
+             return result;]])
         ],
         [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
         [case "$host_os" in
index 9c044dca2bb3f81ff632f06b3185b791a19dd7e0..1fce0f7e1201aeeb1ea05a8f81f899699ac1c94f 100644 (file)
@@ -27,24 +27,28 @@ AC_DEFUN([gl_FUNC_FCNTL],
     dnl haiku alpha 2 F_DUPFD has wrong errno
     AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
       [gl_cv_func_fcntl_f_dupfd_works],
-      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
-#include <limits.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-]], [[int result = 0;
-      int bad_fd = INT_MAX;
-#ifdef _SC_OPEN_MAX
-      long int open_max = sysconf (_SC_OPEN_MAX);
-      if (0 <= open_max && open_max <= INT_MAX)
-        bad_fd = open_max;
-#endif
-      if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
-      if (errno != EINVAL) result |= 2;
-      if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
-      if (errno != EINVAL) result |= 8;
-      return result;
-         ]])],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <errno.h>
+              #include <fcntl.h>
+              #include <limits.h>
+              #include <sys/resource.h>
+              #include <unistd.h>
+            ]],
+            [[int result = 0;
+              int bad_fd = INT_MAX;
+              struct rlimit rlim;
+              if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
+                  && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
+                  && rlim.rlim_cur != RLIM_INFINITY
+                  && rlim.rlim_cur != RLIM_SAVED_MAX
+                  && rlim.rlim_cur != RLIM_SAVED_CUR)
+                bad_fd = rlim.rlim_cur;
+              if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
+              if (errno != EINVAL) result |= 2;
+              if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
+              if (errno != EINVAL) result |= 8;
+              return result;]])],
          [gl_cv_func_fcntl_f_dupfd_works=yes],
          [gl_cv_func_fcntl_f_dupfd_works=no],
          [# Guess that it works on glibc systems