mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
* DaemonLinux.cpp : resource limiting
This commit is contained in:
parent
89059abe15
commit
6ee227675a
@ -8,6 +8,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
@ -83,6 +84,39 @@ namespace i2p
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set proc limits
|
||||||
|
struct rlimit limit;
|
||||||
|
uint16_t nfiles; i2p::config::GetOption("limits.openfiles", nfiles);
|
||||||
|
getrlimit(RLIMIT_NOFILE, &limit);
|
||||||
|
if (nfiles == 0) {
|
||||||
|
LogPrint(eLogInfo, "Daemon: using system limit in ", limit.rlim_cur, " max open files");
|
||||||
|
} else if (nfiles <= limit.rlim_max) {
|
||||||
|
limit.rlim_cur = nfiles;
|
||||||
|
if (setrlimit(RLIMIT_NOFILE, &limit) == 0) {
|
||||||
|
LogPrint(eLogInfo, "Daemon: set max number of open files to ",
|
||||||
|
nfiles, " (system limit is ", limit.rlim_max, ")");
|
||||||
|
} else {
|
||||||
|
LogPrint(eLogError, "Daemon: can't set max number of open files: ", strerror(errno));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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");
|
||||||
|
} else {
|
||||||
|
LogPrint(eLogInfo, "Daemon: set max size of core files to ", cfsize / 1024, "Kb");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LogPrint(eLogError, "Daemon: limits.coresize exceeds system limit: ", limit.rlim_max);
|
||||||
|
}
|
||||||
|
|
||||||
// Pidfile
|
// Pidfile
|
||||||
// this code is c-styled and a bit ugly, but we need fd for locking pidfile
|
// this code is c-styled and a bit ugly, but we need fd for locking pidfile
|
||||||
std::string pidfile; i2p::config::GetOption("pidfile", pidfile);
|
std::string pidfile; i2p::config::GetOption("pidfile", pidfile);
|
||||||
|
Loading…
Reference in New Issue
Block a user