Permalink
Browse files

Configure allowed open fds based on OS

On Mac OS X (and other BSDs), poll() does not check RLIMIT_NOFILES.
The default is to assume the best case and disallow any new fds from
being opened in the child.
  • Loading branch information...
1 parent 4bb7070 commit 422fa2775d3afe959bffa506895fa56b3fc94a62 @msantos committed Jul 1, 2012
Showing with 10 additions and 5 deletions.
  1. +7 −3 c_src/epcap.c
  2. +3 −2 rebar.config
View
@@ -45,6 +45,12 @@ void usage(EPCAP_STATE *ep);
int child_exited = 0;
+/* On some platforms (Linux), poll() (used by pcap)
+ * will return EINVAL if RLIMIT_NOFILES < numfd */
+#ifndef EPCAP_RLIMIT_NOFILES
+#define EPCAP_RLIMIT_NOFILES 0
+#endif
+
int
main(int argc, char *argv[])
@@ -120,9 +126,7 @@ main(int argc, char *argv[])
IS_LTZERO(dup2(fd, STDIN_FILENO));
IS_LTZERO(close(fd));
IS_LTZERO(epcap_init(ep));
- /* poll() (used by pcap) will return EINVAL
- * if RLIMIT_NOFILES < numfd */
- IS_LTZERO(epcap_priv_rlimits(1));
+ IS_LTZERO(epcap_priv_rlimits(EPCAP_RLIMIT_NOFILES));
epcap_loop(ep);
break;
default:
View
@@ -1,6 +1,7 @@
{port_env, [
- {"EXE_CFLAGS", "-g -Wall $ERL_CFLAGS"},
- {"EXE_LDFLAGS", "-lpcap $ERL_LDFLAGS"}
+ {"EXE_LDFLAGS", "-lpcap $ERL_LDFLAGS"},
+ {"linux", "EXE_CFLAGS", "$EXE_CFLAGS -DEPCAP_RLIMIT_NOFILES=1"},
+ {"solaris", "EXE_CFLAGS", "$EXE_CFLAGS -DEPCAP_RLIMIT_NOFILES=1"}
]}.
{port_specs, [
{"priv/epcap", ["c_src/epcap.c", "c_src/epcap_priv.c"]}

0 comments on commit 422fa27

Please sign in to comment.