bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH 2/3] getdtablesize: Extend RLIMIT_NOFILE fallback case to And


From: Kevin Cernekee
Subject: Re: [PATCH 2/3] getdtablesize: Extend RLIMIT_NOFILE fallback case to Android
Date: Tue, 17 Feb 2015 09:47:14 -0800

On Mon, Feb 16, 2015 at 9:46 PM, Paul Eggert <address@hidden> wrote:
> The other patches (after your revisions) look good and I installed them, but
> this one didn't look right.  That part of the code really is intended to be
> used only on Cygwin and it's not portable to other platforms (e.g., it
> mishandles RLIM_SAVED_MAX).  I suppose we could get it to work on Android
> too but let's not bother.  Instead, let's not use Android's getdtablesize
> since it's obsolescent.
>
> I installed the attached patch instead, which I hope solves the problem in a
> different way.  Please let me know whether it works on Android.

On Android, sysconf (_SC_OPEN_MAX) always returns the constant
OPEN_MAX (256).  So if `ulimit -n` is not exactly 256,
test-{dup2,fcntl,getdtablesize} all fail because they think the OS
should have stopped them from using file descriptor 256.

Android behavior: (android-21, arm 32-bit)

# /shared/tmp/fdtest
rlimit: 1024
sysconf: 256
getdtablesize: 1024

Ubuntu/glibc behavior:

$ /tmp/fdtest
rlimit: 32768
sysconf: 32768
getdtablesize: 32768


Test program:

#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>

int main(int argc, char **argv)
{
    struct rlimit lim;

    if (getrlimit (RLIMIT_NOFILE, &lim) == 0)
        printf("rlimit: %d\n", (int)lim.rlim_cur);
    printf("sysconf: %ld\n", sysconf (_SC_OPEN_MAX));
    printf("getdtablesize: %d\n", getdtablesize());
    return 0;
}


FWIW, the deprecated Bionic getdtablesize() function is implemented as:

// This was removed from POSIX 2004.
extern "C" int getdtablesize() {
  struct rlimit r;

  if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
    return sysconf(_SC_OPEN_MAX);
  }

  return r.rlim_cur;
}



reply via email to

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