bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] tests: don't assume getdtablesize () <= 10000000


From: Paul Eggert
Subject: Re: [PATCH] tests: don't assume getdtablesize () <= 10000000
Date: Tue, 11 Jun 2013 00:14:17 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6

Thanks, I pushed the following to try to fix that.
Does it work for you now?

>From 342e81a945375561e6185e2ad724970b29a8129f Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Tue, 11 Jun 2013 00:10:21 -0700
Subject: [PATCH] tests: port large-fd POSIX spawn tests to OS X

Problem reported by Daiki Ueno in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00031.html>.
* tests/test-posix_spawn_file_actions_addclose.c:
* tests/test-posix_spawn_file_actions_adddup2.c:
* tests/test-posix_spawn_file_actions_addopen.c:
Include <limits.h>, for OPEN_MAX, if available.
(big_fd): New static function.
(main): Use it.
---
 ChangeLog                                      | 12 ++++++++++++
 tests/test-posix_spawn_file_actions_addclose.c | 19 +++++++++++++++++--
 tests/test-posix_spawn_file_actions_adddup2.c  | 17 ++++++++++++++++-
 tests/test-posix_spawn_file_actions_addopen.c  | 18 +++++++++++++++++-
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2c2ac44..aeb1bc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2013-06-11  Paul Eggert  <address@hidden>
+
+       tests: port large-fd POSIX spawn tests to OS X
+       Problem reported by Daiki Ueno in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00031.html>.
+       * tests/test-posix_spawn_file_actions_addclose.c:
+       * tests/test-posix_spawn_file_actions_adddup2.c:
+       * tests/test-posix_spawn_file_actions_addopen.c:
+       Include <limits.h>, for OPEN_MAX, if available.
+       (big_fd): New static function.
+       (main): Use it.
+
 2013-06-04  Bernhard Voelker  <address@hidden>
 
        tests/nap.h: use an adaptive delay to avoid ctime update issues
diff --git a/tests/test-posix_spawn_file_actions_addclose.c 
b/tests/test-posix_spawn_file_actions_addclose.c
index 47b12d0..296f101 100644
--- a/tests/test-posix_spawn_file_actions_addclose.c
+++ b/tests/test-posix_spawn_file_actions_addclose.c
@@ -23,10 +23,25 @@ SIGNATURE_CHECK (posix_spawn_file_actions_addclose, int,
                  (posix_spawn_file_actions_t *, int));
 
 #include <errno.h>
+#include <limits.h>
 #include <unistd.h>
 
 #include "macros.h"
 
+/* Return a file descriptor that is too big to use.
+   Prefer the smallest such fd, except use OPEN_MAX if it is defined
+   and is greater than getdtablesize (), as that's how OS X works.  */
+static int
+big_fd (void)
+{
+  int fd = getdtablesize ();
+#ifdef OPEN_MAX
+  if (fd < OPEN_MAX)
+    fd = OPEN_MAX;
+#endif
+  return fd;
+}
+
 int
 main (void)
 {
@@ -40,9 +55,9 @@ main (void)
     ASSERT (posix_spawn_file_actions_addclose (&actions, -1) == EBADF);
   }
   {
+    int bad_fd = big_fd ();
     errno = 0;
-    ASSERT (posix_spawn_file_actions_addclose (&actions, getdtablesize ())
-            == EBADF);
+    ASSERT (posix_spawn_file_actions_addclose (&actions, bad_fd) == EBADF);
   }
 
   return 0;
diff --git a/tests/test-posix_spawn_file_actions_adddup2.c 
b/tests/test-posix_spawn_file_actions_adddup2.c
index d728eff..fe33c02 100644
--- a/tests/test-posix_spawn_file_actions_adddup2.c
+++ b/tests/test-posix_spawn_file_actions_adddup2.c
@@ -23,14 +23,29 @@ SIGNATURE_CHECK (posix_spawn_file_actions_adddup2, int,
                  (posix_spawn_file_actions_t *, int, int));
 
 #include <errno.h>
+#include <limits.h>
 #include <unistd.h>
 
 #include "macros.h"
 
+/* Return a file descriptor that is too big to use.
+   Prefer the smallest such fd, except use OPEN_MAX if it is defined
+   and is greater than getdtablesize (), as that's how OS X works.  */
+static int
+big_fd (void)
+{
+  int fd = getdtablesize ();
+#ifdef OPEN_MAX
+  if (fd < OPEN_MAX)
+    fd = OPEN_MAX;
+#endif
+  return fd;
+}
+
 int
 main (void)
 {
-  int bad_fd = getdtablesize ();
+  int bad_fd = big_fd ();
   posix_spawn_file_actions_t actions;
 
   ASSERT (posix_spawn_file_actions_init (&actions) == 0);
diff --git a/tests/test-posix_spawn_file_actions_addopen.c 
b/tests/test-posix_spawn_file_actions_addopen.c
index c2329d4..a4865ca 100644
--- a/tests/test-posix_spawn_file_actions_addopen.c
+++ b/tests/test-posix_spawn_file_actions_addopen.c
@@ -25,10 +25,25 @@ SIGNATURE_CHECK (posix_spawn_file_actions_addopen, int,
 
 #include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <unistd.h>
 
 #include "macros.h"
 
+/* Return a file descriptor that is too big to use.
+   Prefer the smallest such fd, except use OPEN_MAX if it is defined
+   and is greater than getdtablesize (), as that's how OS X works.  */
+static int
+big_fd (void)
+{
+  int fd = getdtablesize ();
+#ifdef OPEN_MAX
+  if (fd < OPEN_MAX)
+    fd = OPEN_MAX;
+#endif
+  return fd;
+}
+
 int
 main (void)
 {
@@ -44,8 +59,9 @@ main (void)
             == EBADF);
   }
   {
+    int bad_fd = big_fd ();
     errno = 0;
-    ASSERT (posix_spawn_file_actions_addopen (&actions, getdtablesize (),
+    ASSERT (posix_spawn_file_actions_addopen (&actions, bad_fd,
                                               "foo", 0, O_RDONLY)
             == EBADF);
   }
-- 
1.7.11.7




reply via email to

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