Skip to content

Commit

Permalink
Setup ulimits on startup to prevent "too many open files"
Browse files Browse the repository at this point in the history
  • Loading branch information
vdudouyt committed Aug 18, 2015
1 parent 4cba41d commit 175e153
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <unistd.h>

#include <glib.h>
#include <sys/resource.h>

#ifndef WITHOUT_XATTR
#include <attr/xattr.h>
Expand Down Expand Up @@ -1019,6 +1020,19 @@ static int mhdd_removexattr(const char *path, const char *attrname)
}
#endif

static void limits_init()
{
struct rlimit limit;
limit.rlim_cur = 512000;
limit.rlim_max = 512000;

if(setrlimit(RLIMIT_NOFILE, &limit) != 0)
{
perror("setrlimit() failed");
exit(-1);
}
}

// functions links
static struct fuse_operations mhdd_oper = {
.getattr = mhdd_stat,
Expand Down Expand Up @@ -1059,6 +1073,7 @@ int main(int argc, char *argv[])
mhdd_debug_init();
struct fuse_args *args = parse_options(argc, argv);
flist_init();
limits_init();
signal(SIGSEGV, save_backtrace);
return fuse_main(args->argc, args->argv, &mhdd_oper, 0);
}

0 comments on commit 175e153

Please sign in to comment.