Skip to content

Commit

Permalink
The default value for RLIMIT_NOFILE on mac is 256, try to fix at star…
Browse files Browse the repository at this point in the history
…tup.
  • Loading branch information
taviso committed Nov 2, 2018
1 parent c0cf735 commit 8a43202
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions halfempty.c
Expand Up @@ -22,6 +22,9 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#ifdef __APPLE__
# include <sys/sysctl.h>
#endif
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -176,6 +179,26 @@ int main(int argc, char **argv)
// crashes or exits before we send it all the data we have, we get SIGPIPE.
sigaction(SIGPIPE, &sa, NULL);

#ifdef __APPLE__
// The default for RLIMIT_NOFILE on macOS is insanely small (256), lets
// turn it up to something reasonable.
{
struct rlimit limfiles = {
.rlim_cur = 32768,
.rlim_max = RLIM_INFINITY,
};
size_t length = sizeof(rlim_t);

if (sysctlbyname("kern.maxfilesperproc", &limfiles.rlim_cur, &length, NULL, 0) == 0) {
if (setrlimit(RLIMIT_NOFILE, &limfiles) != 0) {
g_warning("failed to adjust resource limits, use \"ulimit -n\" instead");
}
} else {
g_warning("failed to query kern.maxfilesperproc, use \"ulimit -n\" instead");
}
}
#endif

if (argc != 3) {
g_warning("You must specify two parameters, a test program and an inputfile");
return EXIT_FAILURE;
Expand Down

0 comments on commit 8a43202

Please sign in to comment.