summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-02 23:15:18 +0200
committerJakob Unterwurzacher2017-05-02 23:15:18 +0200
commit2d43288bc821a861898125a6e37bed4c5553bd7d (patch)
tree7f81b057554d62bbefbee1a1d59ab1fbabc7bc2c
parentdaada9d7c6207328ad49a4d96050eb08e1a003a1 (diff)
main: increase open file limit to 4096
Linux by default has a soft limit of 1024 and a hard limit of 4096 on open files. We can increase it so 4096 without root permissions. This should help reduce the risk of gocryptfs running out of file descriptors, as reported at https://github.com/rfjakob/gocryptfs/issues/82 .
-rw-r--r--mount.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/mount.go b/mount.go
index 59116d6..20a5970 100644
--- a/mount.go
+++ b/mount.go
@@ -147,6 +147,18 @@ func doMount(args *argContainer) int {
// Send SIGUSR1 to our parent
sendUsr1(args.notifypid)
}
+ // Increase the number of open files limit up to the hard limit. It's not
+ // dramatic if that fails, so do it after we have switched to syslog and not
+ // bother the user with warning.
+ var lim syscall.Rlimit
+ syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
+ lim.Cur = lim.Max
+ err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
+ if err != nil {
+ tlog.Warn.Printf("Setting RLIMIT_NOFILE failed: %v", err)
+ } else if lim.Cur < 4096 {
+ tlog.Warn.Printf("Low hard limit for RLIMIT_NOFILE: %d", lim.Cur)
+ }
// Wait for SIGINT in the background and unmount ourselves if we get it.
// This prevents a dangling "Transport endpoint is not connected"
// mountpoint if the user hits CTRL-C.