Home | History | Annotate | Download | only in services
      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.
      4 
      5 #include "sandbox/linux/services/resource_limits.h"
      6 
      7 #include <sys/resource.h>
      8 #include <sys/time.h>
      9 
     10 #include <algorithm>
     11 
     12 namespace sandbox {
     13 
     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;
     24 }
     25 
     26 }  // namespace sandbox
     27