bug-gnulib
[Top][All Lists]
Advanced

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

Re: OpenVMS getdtablesize.c


From: Bruno Haible
Subject: Re: OpenVMS getdtablesize.c
Date: Sat, 15 Jul 2017 17:00:30 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-83-generic; KDE/5.18.0; x86_64; ; )

John E. Malmberg wrote:
> > [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html
> According to that link, a system is not required to fail a request for a 
> file descriptor to be created higher than RLIMIT_NOFILE.

Not true. [1] refers to [2], and [2] as well as [3] say that 
getrlimit(RLIMIT_NOFILE) is
  "one greater than the maximum value that the system may assign to a 
newly-created descriptor."
The other sentence is just an explanation of the effect of this definition.

But I admit that you may have been confused because the comments in gnulib
were misleading.

> Attached is a patch for the test to pass on OpenVMS.

Not usable: Comments are wrong, and I prefer a 'case' statement over
a #ifdef that renders the test a dummy.

Here's what I'm pushing.

[1] http://pubs.opengroup.org/onlinepubs/7908799/xsh/getdtablesize.html
[2] http://pubs.opengroup.org/onlinepubs/7908799/xsh/getrlimit.html
[3] http://pubs.opengroup.org/onlinepubs/009695399/functions/getrlimit.html


2017-07-15  Bruno Haible  <address@hidden>

        getdtablesize: Add minimal support for OpenVMS.
        Reported by John E. Malmberg <address@hidden>.
        * modules/getdtablesize (Description): Fix.
        * lib/getdtablesize.c: Fix comment.
        * m4/getdtablesize.m4 (gl_FUNC_GETDTABLESIZE): Don't replace the
        getdtablesize() function, even though the test fails.
        * doc/glibc-functions/getdtablesize.texi: Reference SUSv2. Describe
        limitation on OpenVMS.

diff --git a/doc/glibc-functions/getdtablesize.texi 
b/doc/glibc-functions/getdtablesize.texi
index 921c985..b7a16d1 100644
--- a/doc/glibc-functions/getdtablesize.texi
+++ b/doc/glibc-functions/getdtablesize.texi
@@ -2,6 +2,8 @@
 @subsection @code{getdtablesize}
 @findex getdtablesize
 
+SUSv2 specification: 
@url{http://pubs.opengroup.org/onlinepubs/7908799/xsh/getdtablesize.html}
+
 Gnulib module: getdtablesize
 
 Portability problems fixed by Gnulib:
@@ -22,4 +24,8 @@ Android LP32, Cygwin 1.7.25.
 
 Portability problems not fixed by Gnulib:
 @itemize
address@hidden
+On OpenVMS, this function returns the maximum number of open file descriptors
+in a process.  The possible values of file descriptors are not constrained by
+this function.
 @end itemize
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index c356cf4..a092863 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -1,4 +1,4 @@
-/* getdtablesize() function for platforms that don't have it.
+/* getdtablesize() function: Return maximum possible file descriptor value + 1.
    Copyright (C) 2008-2017 Free Software Foundation, Inc.
    Written by Bruno Haible <address@hidden>, 2008.
 
diff --git a/m4/getdtablesize.m4 b/m4/getdtablesize.m4
index 1af2a24..f1e4f5f 100644
--- a/m4/getdtablesize.m4
+++ b/m4/getdtablesize.m4
@@ -1,4 +1,4 @@
-# getdtablesize.m4 serial 6
+# getdtablesize.m4 serial 7
 dnl Copyright (C) 2008-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,29 +12,43 @@ AC_DEFUN([gl_FUNC_GETDTABLESIZE],
   AC_CHECK_DECLS_ONCE([getdtablesize])
   if test $ac_cv_func_getdtablesize = yes &&
      test $ac_cv_have_decl_getdtablesize = yes; then
-    # Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft limit
-    # up to an unchangeable hard limit; all other platforms correctly
-    # require setrlimit before getdtablesize() can report a larger value.
     AC_CACHE_CHECK([whether getdtablesize works],
       [gl_cv_func_getdtablesize_works],
-      [AC_RUN_IFELSE([
-        AC_LANG_PROGRAM([[#include <unistd.h>]],
-          [int size = getdtablesize();
-           if (dup2 (0, getdtablesize()) != -1)
-             return 1;
-           if (size != getdtablesize())
-             return 2;
-          ])],
-        [gl_cv_func_getdtablesize_works=yes],
-        [gl_cv_func_getdtablesize_works=no],
-        [case "$host_os" in
-          cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
-            gl_cv_func_getdtablesize_works="guessing no" ;;
-          *) gl_cv_func_getdtablesize_works="guessing yes" ;;
-         esac])
+      [dnl There are two concepts: the "maximum possible file descriptor value 
+ 1"
+       dnl and the "maximum number of open file descriptors in a process".
+       dnl Per SUSv2 and POSIX, getdtablesize() should return the first one.
+       dnl On most platforms, the first and the second concept are the same.
+       dnl On OpenVMS, however, they are different and getdtablesize() returns
+       dnl the second one; thus the test below fails. But we don't care
+       dnl because there's no good way to write a replacement getdtablesize().
+       case "$host_os" in
+         vms*) gl_cv_func_getdtablesize_works="no (limitation)" ;;
+         *)
+           dnl Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft
+           dnl limit up to an unchangeable hard limit; all other platforms
+           dnl correctly require setrlimit before getdtablesize() can report
+           dnl a larger value.
+           AC_RUN_IFELSE([
+             AC_LANG_PROGRAM([[#include <unistd.h>]],
+               [int size = getdtablesize();
+                if (dup2 (0, getdtablesize()) != -1)
+                  return 1;
+                if (size != getdtablesize())
+                  return 2;
+               ])],
+             [gl_cv_func_getdtablesize_works=yes],
+             [gl_cv_func_getdtablesize_works=no],
+             [case "$host_os" in
+                cygwin*) # on cygwin 1.5.25, getdtablesize() automatically 
grows
+                  gl_cv_func_getdtablesize_works="guessing no" ;;
+                *) gl_cv_func_getdtablesize_works="guessing yes" ;;
+              esac
+             ])
+           ;;
+       esac
       ])
     case "$gl_cv_func_getdtablesize_works" in
-      *yes) ;;
+      *yes | "no (limitation)") ;;
       *) REPLACE_GETDTABLESIZE=1 ;;
     esac
   else
diff --git a/modules/getdtablesize b/modules/getdtablesize
index e458f3a..f33fcb5 100644
--- a/modules/getdtablesize
+++ b/modules/getdtablesize
@@ -1,5 +1,5 @@
 Description:
-getdtablesize() function: return maximum number of file descriptors.
+getdtablesize() function: return tight upper bound for file descriptor values.
 
 Files:
 lib/getdtablesize.c




reply via email to

[Prev in Thread] Current Thread [Next in Thread]