[PATCH] Cygwin: getdtablesize: always return OPEN_MAX_MAX

Ken Brown kbrown@cornell.edu
Thu Jan 28 20:33:39 GMT 2021

On 1/28/2021 11:07 AM, Corinna Vinschen via Cygwin-patches wrote:
> On Jan 28 08:42, Ken Brown via Cygwin-patches wrote:
>> On 1/28/2021 5:20 AM, Corinna Vinschen via Cygwin-patches wrote:
>>> On Jan 27 21:51, Ken Brown via Cygwin-patches wrote:
>>>> According to the Linux man page for getdtablesize(3), the latter is
>>>> supposed to return "the maximum number of files a process can have
>>>> open, one more than the largest possible value for a file descriptor."
>>>> The constant OPEN_MAX_MAX is the only limit enforced by Cygwin, so we
>>>> now return that.
>>>> Previously getdtablesize returned the current size of cygheap->fdtab,
>>>> Cygwin's internal file descriptor table.  But this is a dynamically
>>>> growing table, and its current size does not reflect an actual limit
>>>> on the number of open files.
>>>> With this change, gnulib now reports that getdtablesize and
>>>> fcntl(F_DUPFD) work on Cygwin.  Packages like GNU tar that use the
>>>> corresponding gnulib modules will no longer use gnulib replacements on
>>>> Cygwin.
>>>> ---
>>>>    winsup/cygwin/syscalls.cc | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>> diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
>>>> index 5da05b18a..1f16d54b9 100644
>>>> --- a/winsup/cygwin/syscalls.cc
>>>> +++ b/winsup/cygwin/syscalls.cc
>>>> @@ -2887,7 +2887,7 @@ setdtablesize (int size)
>>>>    extern "C" int
>>>>    getdtablesize ()
>>>>    {
>>>> -  return cygheap->fdtab.size;
>>>> +  return OPEN_MAX_MAX;
>>>>    }
>>> getdtablesize is used internally, too.  After this change, the values
>>> returned by sysconf and getrlimit should be revisited as well.
>> They will now return OPEN_MAX_MAX, as I think they should.  The only
>> question in my mind is whether to simplify the code by removing the calls to
>> getdtablesize, something like this (untested):
> But then again, what happens with OPEN_MAX in limits.h?  Linux removed
> it entirely.  Given we have such a limit and it's not flexible as on
> Linux, should we go ahead, drop OPEN_MAX_MAX entirely and define
> OPEN_MAX as 3200?

Makes sense to me.

> One problem is that there are some applications in the wild which run
> loops up to either sysconf(_SC_OPEN_MAX) or OPEN_MAX to handle open
> descriptors.  tcsh is one of them.  It may slow done tcsh quite a bit
> if the loop runs to 3200 now every time.

I don't use tcsh.  Is it easy to test this?


More information about the Cygwin-patches mailing list