]> code.delx.au - pulseaudio/commitdiff
core-util: fall back to sysconf(_SC_OPEN_MAX) to find maximum file descriptor
authorLennart Poettering <lennart@poettering.net>
Thu, 21 May 2009 23:31:56 +0000 (01:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 May 2009 23:31:56 +0000 (01:31 +0200)
src/pulsecore/core-util.c

index 4658eb524e009d8830644ccc66a59c84e1426169..d4956fb8ea749510d641be9166f2c255a0fc2249 100644 (file)
@@ -2235,7 +2235,7 @@ int pa_close_all(int except_fd, ...) {
 
 int pa_close_allv(const int except_fds[]) {
     struct rlimit rl;
-    int fd;
+    int maxfd, fd;
     int saved_errno;
 
 #ifdef __linux__
@@ -2302,10 +2302,12 @@ int pa_close_allv(const int except_fds[]) {
 
 #endif
 
-    if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
-        return -1;
+    if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
+        maxfd = (int) rl.rlim_max;
+    else
+        maxfd = sysconf(_SC_OPEN_MAX);
 
-    for (fd = 3; fd < (int) rl.rlim_max; fd++) {
+    for (fd = 3; fd < maxfd; fd++) {
         int i;
         pa_bool_t found;