• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_sys_control.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   This file produces Unicorns and Rainbows for the ATS community
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "ink_sys_control.h"
00025 #include "ink_platform.h"
00026 #include "ink_assert.h"
00027 
00028 rlim_t
00029 ink_max_out_rlimit(int which, bool max_it, bool unlim_it)
00030 {
00031   struct rlimit rl;
00032 
00033 #if defined(linux)
00034 #  define MAGIC_CAST(x) (enum __rlimit_resource)(x)
00035 #else
00036 #  define MAGIC_CAST(x) x
00037 #endif
00038 
00039   if (max_it) {
00040     ink_release_assert(getrlimit(MAGIC_CAST(which), &rl) >= 0);
00041     if (rl.rlim_cur != rl.rlim_max) {
00042 #if defined(darwin)
00043       if (which == RLIMIT_NOFILE)
00044         rl.rlim_cur = fmin(OPEN_MAX, rl.rlim_max);
00045       else
00046         rl.rlim_cur = rl.rlim_max;
00047 #else
00048       rl.rlim_cur = rl.rlim_max;
00049 #endif
00050       ink_release_assert(setrlimit(MAGIC_CAST(which), &rl) >= 0);
00051     }
00052   }
00053 
00054 #if !defined(darwin)
00055   if (unlim_it) {
00056     ink_release_assert(getrlimit(MAGIC_CAST(which), &rl) >= 0);
00057     if (rl.rlim_cur != (rlim_t)RLIM_INFINITY) {
00058       rl.rlim_cur = (rl.rlim_max = RLIM_INFINITY);
00059       ink_release_assert(setrlimit(MAGIC_CAST(which), &rl) >= 0);
00060     }
00061   }
00062 #endif
00063   ink_release_assert(getrlimit(MAGIC_CAST(which), &rl) >= 0);
00064   return rl.rlim_cur;
00065 }

Generated by  doxygen 1.7.1