1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
#include "mysys_priv.h" |
|
17 |
#include "my_static.h" |
|
212.5.18
by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype. |
18 |
#include <mystrings/m_string.h> |
1
by brian
clean slate |
19 |
|
20 |
/*
|
|
21 |
set how many open files we want to be able to handle
|
|
22 |
||
23 |
SYNOPSIS
|
|
24 |
set_maximum_open_files()
|
|
25 |
max_file_limit Files to open
|
|
26 |
||
27 |
NOTES
|
|
28 |
The request may not fulfilled becasue of system limitations
|
|
29 |
||
30 |
RETURN
|
|
31 |
Files available to open.
|
|
32 |
May be more or less than max_file_limit!
|
|
33 |
*/
|
|
34 |
||
35 |
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
|
|
36 |
||
37 |
#ifndef RLIM_INFINITY
|
|
38 |
#define RLIM_INFINITY ((uint) 0xffffffff)
|
|
39 |
#endif
|
|
40 |
||
41 |
static uint set_max_open_files(uint max_file_limit) |
|
42 |
{
|
|
43 |
struct rlimit rlimit; |
|
44 |
uint old_cur; |
|
45 |
||
46 |
if (!getrlimit(RLIMIT_NOFILE,&rlimit)) |
|
47 |
{
|
|
48 |
old_cur= (uint) rlimit.rlim_cur; |
|
49 |
if (rlimit.rlim_cur == RLIM_INFINITY) |
|
50 |
rlimit.rlim_cur = max_file_limit; |
|
51 |
if (rlimit.rlim_cur >= max_file_limit) |
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
52 |
return(rlimit.rlim_cur); /* purecov: inspected */ |
1
by brian
clean slate |
53 |
rlimit.rlim_cur= rlimit.rlim_max= max_file_limit; |
54 |
if (setrlimit(RLIMIT_NOFILE, &rlimit)) |
|
55 |
max_file_limit= old_cur; /* Use original value */ |
|
56 |
else
|
|
57 |
{
|
|
58 |
rlimit.rlim_cur= 0; /* Safety if next call fails */ |
|
59 |
(void) getrlimit(RLIMIT_NOFILE,&rlimit); |
|
60 |
if (rlimit.rlim_cur) /* If call didn't fail */ |
|
61 |
max_file_limit= (uint) rlimit.rlim_cur; |
|
62 |
}
|
|
63 |
}
|
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
64 |
return(max_file_limit); |
1
by brian
clean slate |
65 |
}
|
66 |
||
67 |
#else
|
|
68 |
static int set_max_open_files(uint max_file_limit) |
|
69 |
{
|
|
70 |
/* We don't know the limit. Return best guess */
|
|
71 |
return min(max_file_limit, OS_FILE_LIMIT); |
|
72 |
}
|
|
73 |
#endif
|
|
74 |
||
75 |
||
76 |
/*
|
|
77 |
Change number of open files
|
|
78 |
||
79 |
SYNOPSIS:
|
|
80 |
my_set_max_open_files()
|
|
81 |
files Number of requested files
|
|
82 |
||
83 |
RETURN
|
|
84 |
number of files available for open
|
|
85 |
*/
|
|
86 |
||
87 |
uint my_set_max_open_files(uint files) |
|
88 |
{
|
|
89 |
struct st_my_file_info *tmp; |
|
90 |
||
91 |
files= set_max_open_files(min(files, OS_FILE_LIMIT)); |
|
92 |
if (files <= MY_NFILE) |
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
93 |
return(files); |
1
by brian
clean slate |
94 |
|
95 |
if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files, |
|
96 |
MYF(MY_WME)))) |
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
97 |
return(MY_NFILE); |
1
by brian
clean slate |
98 |
|
99 |
/* Copy any initialized files */
|
|
100 |
memcpy((char*) tmp, (char*) my_file_info, |
|
101 |
sizeof(*tmp) * min(my_file_limit, files)); |
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
102 |
memset((char*) (tmp + my_file_limit), 0, |
103 |
max((int) (files- my_file_limit), 0)*sizeof(*tmp)); |
|
1
by brian
clean slate |
104 |
my_free_open_file_info(); /* Free if already allocated */ |
105 |
my_file_info= tmp; |
|
106 |
my_file_limit= files; |
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
107 |
return(files); |
1
by brian
clean slate |
108 |
}
|
109 |
||
110 |
||
111 |
void my_free_open_file_info() |
|
112 |
{
|
|
113 |
if (my_file_info != my_file_info_default) |
|
114 |
{
|
|
115 |
/* Copy data back for my_print_open_files */
|
|
116 |
memcpy((char*) my_file_info_default, my_file_info, |
|
117 |
sizeof(*my_file_info_default)* MY_NFILE); |
|
118 |
my_free((char*) my_file_info, MYF(0)); |
|
119 |
my_file_info= my_file_info_default; |
|
120 |
my_file_limit= MY_NFILE; |
|
121 |
}
|
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
122 |
return; |
1
by brian
clean slate |
123 |
}
|