Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / sandbox / linux / services / resource_limits.cc
blob1ec11295d1d4eb116369edcca7b1a1de40679f10
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/linux/services/resource_limits.h"
7 #include <sys/resource.h>
8 #include <sys/time.h>
10 #include <algorithm>
12 namespace sandbox {
14 // static
15 bool ResourceLimits::Lower(int resource, rlim_t limit) {
16 struct rlimit old_rlimit;
17 if (getrlimit(resource, &old_rlimit))
18 return false;
19 // Make sure we don't raise the existing limit.
20 const struct rlimit new_rlimit = {std::min(old_rlimit.rlim_cur, limit),
21 std::min(old_rlimit.rlim_max, limit)};
22 int rc = setrlimit(resource, &new_rlimit);
23 return rc == 0;
26 } // namespace sandbox