| 109 | |
| 110 | |
| 111 | Try<Nothing> set(const RLimitInfo::RLimit& limit) |
| 112 | { |
| 113 | const Try<int> resource = convert(limit.type()); |
| 114 | if (resource.isError()) { |
| 115 | return Error("Could not convert rlimit: " + resource.error()); |
| 116 | } |
| 117 | |
| 118 | ::rlimit resourceLimit; |
| 119 | if (limit.has_soft() && limit.has_hard()) { |
| 120 | resourceLimit.rlim_cur = limit.soft(); |
| 121 | resourceLimit.rlim_max = limit.hard(); |
| 122 | } else if (!limit.has_soft() && !limit.has_hard()) { |
| 123 | resourceLimit.rlim_cur = RLIM_INFINITY; |
| 124 | resourceLimit.rlim_max = RLIM_INFINITY; |
| 125 | } else { |
| 126 | return Error("Invalid rlimit values"); |
| 127 | } |
| 128 | |
| 129 | if (setrlimit(resource.get(), &resourceLimit) != 0) { |
| 130 | return ErrnoError(); |
| 131 | } |
| 132 | |
| 133 | return Nothing(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | Try<RLimitInfo::RLimit> get(RLimitInfo::RLimit::Type type) |