| 21 |
|
* |
| 22 |
|
* $Id$ |
| 23 |
|
*/ |
| 24 |
+ |
|
| 25 |
|
#include "stdinc.h" |
| 26 |
|
#include "fdlist.h" |
| 27 |
|
#include "client.h" /* struct Client */ |
| 27 |
– |
#include "common.h" |
| 28 |
|
#include "event.h" |
| 29 |
|
#include "ircd.h" /* GlobalSetOptions */ |
| 30 |
|
#include "irc_string.h" |
| 31 |
– |
#include "rlimits.h" |
| 31 |
|
#include "s_bsd.h" /* comm_setselect */ |
| 32 |
< |
#include "s_conf.h" /* ServerInfo */ |
| 32 |
> |
#include "conf.h" /* ServerInfo */ |
| 33 |
|
#include "send.h" |
| 34 |
|
#include "memory.h" |
| 35 |
|
#include "numeric.h" |
| 36 |
+ |
#include "s_misc.h" |
| 37 |
+ |
#include "irc_res.h" |
| 38 |
|
|
| 39 |
|
fde_t *fd_hash[FD_HASH_SIZE]; |
| 40 |
|
fde_t *fd_next_in_loop = NULL; |
| 41 |
|
int number_fd = LEAKED_FDS; |
| 42 |
|
int hard_fdlimit = 0; |
| 42 |
– |
struct Callback *fdlimit_cb = NULL; |
| 43 |
– |
|
| 44 |
– |
static void * |
| 45 |
– |
changing_fdlimit(va_list args) |
| 46 |
– |
{ |
| 47 |
– |
int old_fdlimit = hard_fdlimit; |
| 43 |
|
|
| 49 |
– |
hard_fdlimit = va_arg(args, int); |
| 44 |
|
|
| 45 |
< |
if (ServerInfo.max_clients > MAXCLIENTS_MAX) |
| 46 |
< |
{ |
| 53 |
< |
if (old_fdlimit != 0) |
| 54 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 55 |
< |
"HARD_FDLIMIT changed to %d, adjusting MAXCLIENTS to %d", |
| 56 |
< |
hard_fdlimit, MAXCLIENTS_MAX); |
| 57 |
< |
|
| 58 |
< |
ServerInfo.max_clients = MAXCLIENTS_MAX; |
| 59 |
< |
} |
| 60 |
< |
|
| 61 |
< |
return NULL; |
| 62 |
< |
} |
| 63 |
< |
|
| 64 |
< |
void |
| 65 |
< |
fdlist_init(void) |
| 66 |
< |
{ |
| 67 |
< |
memset(&fd_hash, 0, sizeof(fd_hash)); |
| 68 |
< |
|
| 69 |
< |
fdlimit_cb = register_callback("changing_fdlimit", changing_fdlimit); |
| 70 |
< |
eventAddIsh("recalc_fdlimit", recalc_fdlimit, NULL, 58); |
| 71 |
< |
recalc_fdlimit(NULL); |
| 72 |
< |
} |
| 73 |
< |
|
| 74 |
< |
void |
| 75 |
< |
recalc_fdlimit(void *unused) |
| 45 |
> |
static int |
| 46 |
> |
set_fdlimit(void) |
| 47 |
|
{ |
| 48 |
|
int fdmax; |
| 49 |
|
struct rlimit limit; |
| 50 |
|
|
| 51 |
< |
if (!getrlimit(RLIMIT_FD_MAX, &limit)) |
| 51 |
> |
if (!getrlimit(RLIMIT_NOFILE, &limit)) |
| 52 |
|
{ |
| 53 |
|
limit.rlim_cur = limit.rlim_max; |
| 54 |
< |
setrlimit(RLIMIT_FD_MAX, &limit); |
| 54 |
> |
setrlimit(RLIMIT_NOFILE, &limit); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
fdmax = getdtablesize(); |
| 62 |
|
|
| 63 |
|
/* under no condition shall this raise over 65536 |
| 64 |
|
* for example user ip heap is sized 2*hard_fdlimit */ |
| 65 |
< |
fdmax = IRCD_MIN(fdmax, 65536); |
| 65 |
> |
hard_fdlimit = IRCD_MIN(fdmax, 65536); |
| 66 |
|
|
| 67 |
< |
if (fdmax != hard_fdlimit) |
| 68 |
< |
execute_callback(fdlimit_cb, fdmax); |
| 67 |
> |
return -1; |
| 68 |
> |
} |
| 69 |
> |
|
| 70 |
> |
void |
| 71 |
> |
fdlist_init(void) |
| 72 |
> |
{ |
| 73 |
> |
set_fdlimit(); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
static inline unsigned int |
| 200 |
|
for (i = 0; i < LOWEST_SAFE_FD; i++) |
| 201 |
|
{ |
| 202 |
|
close(i); |
| 203 |
< |
if (open(PATH_DEVNULL, O_RDWR) < 0) |
| 203 |
> |
if (open("/dev/null", O_RDWR) < 0) |
| 204 |
|
exit(-1); /* we're hosed if we can't even open /dev/null */ |
| 205 |
|
} |
| 206 |
|
} |