2
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; version 2 of the
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27
#include <sys/types.h>
28
#ifdef HAVE_SYS_TIME_H
31
#ifdef HAVE_SYS_RESOURCE_H
32
#include <sys/resource.h>
35
#include <stdio.h> /* for _getmaxstdio() */
39
#include "chassis-limits.h"
41
gint64 chassis_fdlimit_get() {
43
return _getmaxstdio();
45
struct rlimit max_files_rlimit;
47
if (-1 == getrlimit(RLIMIT_NOFILE, &max_files_rlimit)) {
50
return max_files_rlimit.rlim_cur;
57
* redirect the old call
59
int chassis_set_fdlimit(int max_files_number) {
60
return chassis_fdlimit_set(max_files_number);
64
* set the upper limit of open files
66
* @return -1 on error, 0 on success
68
int chassis_fdlimit_set(gint64 max_files_number) {
70
int max_files_number_set;
72
max_files_number_set = _setmaxstdio(max_files_number);
74
if (-1 == max_files_number_set) {
76
} else if (max_files_number_set != max_files_number) {
77
g_critical("%s: failed to increase the maximum number of open files for stdio: %s (%d)", G_STRLOC, g_strerror(errno), errno);
83
struct rlimit max_files_rlimit;
87
if (-1 == getrlimit(RLIMIT_NOFILE, &max_files_rlimit)) {
91
soft_limit = max_files_rlimit.rlim_cur;
92
hard_limit = max_files_rlimit.rlim_max;
94
max_files_rlimit.rlim_cur = max_files_number;
95
if (hard_limit < max_files_number) { /* raise the hard-limit too in case it is smaller than the soft-limit, otherwise we get a EINVAL */
96
max_files_rlimit.rlim_max = max_files_number;
99
if (-1 == setrlimit(RLIMIT_NOFILE, &max_files_rlimit)) {