From 480ce6f522601f3794194a6af7450f57c233fe36 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Nov 2016 21:37:47 -0400 Subject: [PATCH] core file is limited by a system by default --- Config.cpp | 2 +- DaemonLinux.cpp | 27 +++++++++++++++------------ docs/configuration.md | 2 ++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Config.cpp b/Config.cpp index 360694a0..aa75b8db 100644 --- a/Config.cpp +++ b/Config.cpp @@ -62,7 +62,7 @@ namespace config { options_description limits("Limits options"); limits.add_options() - ("limits.coresize", value()->default_value(0), "Maximum size of corefile in Kb (0 - disable coredumps)") + ("limits.coresize", value()->default_value(0), "Maximum size of corefile in Kb (0 - use system limit)") ("limits.openfiles", value()->default_value(0), "Maximum number of open files (0 - use system default)") ("limits.transittunnels", value()->default_value(2500), "Maximum active transit sessions (default:2500)") ; diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 392d28a3..edd15f07 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -102,20 +102,23 @@ namespace i2p LogPrint(eLogError, "Daemon: limits.openfiles exceeds system limit: ", limit.rlim_max); } uint32_t cfsize; i2p::config::GetOption("limits.coresize", cfsize); - cfsize *= 1024; - getrlimit(RLIMIT_CORE, &limit); - if (cfsize <= limit.rlim_max) { - limit.rlim_cur = cfsize; - if (setrlimit(RLIMIT_CORE, &limit) != 0) { - LogPrint(eLogError, "Daemon: can't set max size of coredump: ", strerror(errno)); - } else if (cfsize == 0) { - LogPrint(eLogInfo, "Daemon: coredumps disabled"); + if (cfsize) // core file size set + { + cfsize *= 1024; + getrlimit(RLIMIT_CORE, &limit); + if (cfsize <= limit.rlim_max) { + limit.rlim_cur = cfsize; + if (setrlimit(RLIMIT_CORE, &limit) != 0) { + LogPrint(eLogError, "Daemon: can't set max size of coredump: ", strerror(errno)); + } else if (cfsize == 0) { + LogPrint(eLogInfo, "Daemon: coredumps disabled"); + } else { + LogPrint(eLogInfo, "Daemon: set max size of core files to ", cfsize / 1024, "Kb"); + } } else { - LogPrint(eLogInfo, "Daemon: set max size of core files to ", cfsize / 1024, "Kb"); + LogPrint(eLogError, "Daemon: limits.coresize exceeds system limit: ", limit.rlim_max); } - } else { - LogPrint(eLogError, "Daemon: limits.coresize exceeds system limit: ", limit.rlim_max); - } + } // Pidfile // this code is c-styled and a bit ugly, but we need fd for locking pidfile diff --git a/docs/configuration.md b/docs/configuration.md index 7e99dcb2..b04be9fb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -88,6 +88,8 @@ All options below still possible in cmdline, but better write it in config file: * --addressbook.subscriptions= - AddressBook subscriptions URLs, separated by comma * --limits.transittunnels= - Override maximum number of transit tunnels. 2500 by default +* --limits.openfiles= - Maximum size of corefile in Kb (0 - use system limit) +* --limits.coresize= - Maximum size of corefile in Kb (0 - use system limit) Config files ------------