9 static const char rcsid[] __attribute__((used)) =
"$Id: ResourceLimit.cpp 1653 2016-02-28 19:54:59Z sella $";
11 #include "ResourceLimit.h"
13 #include <sys/resource.h>
15 using namespace sella::util;
17 void ResourceLimit::setCoredumpSize(
unsigned long size, Type type)
throw (ResourceLimitException) {
21 limit.rlim_cur = limit.rlim_max = size;
22 }
else if (type == Hard) {
23 limit.rlim_max = size;
25 limit.rlim_cur = size;
28 if (setrlimit(RLIMIT_CORE, &limit) != 0) {
29 THROW2(ResourceLimitException,
"Failed to adjust coredump size");
33 void ResourceLimit::setFileDescriptors(
unsigned long size, Type type)
throw (ResourceLimitException) {
37 limit.rlim_cur = limit.rlim_max = size;
38 }
else if (type == Hard) {
39 limit.rlim_max = size;
41 limit.rlim_cur = size;
44 if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
45 THROW2(ResourceLimitException,
"Failed to adjust file descriptor limit");
49 unsigned long ResourceLimit::getCoredumpSize(Type type)
throw (ResourceLimitException) {
52 if (getrlimit(RLIMIT_CORE, &limit) != 0) {
53 THROW2(ResourceLimitException,
"Failed to access coredump size");
57 return limit.rlim_max;
60 return limit.rlim_cur;
63 unsigned long ResourceLimit::getFileDescriptors(Type type)
throw (ResourceLimitException) {
66 if (getrlimit(RLIMIT_NOFILE, &limit) != 0) {
67 THROW2(ResourceLimitException,
"Failed to access file descriptor limit");
71 return limit.rlim_max;
74 return limit.rlim_cur;