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>
15 bool ResourceLimits::Lower(int resource
, rlim_t limit
) {
16 struct rlimit old_rlimit
;
17 if (getrlimit(resource
, &old_rlimit
))
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
);
26 } // namespace sandbox