| 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; |
| 48 |
– |
|
| 49 |
– |
hard_fdlimit = va_arg(args, int); |
| 50 |
– |
|
| 51 |
– |
if (ServerInfo.max_clients > MAXCLIENTS_MAX) |
| 52 |
– |
{ |
| 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 |
– |
} |
| 43 |
|
|
| 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 |
– |
} |
| 44 |
|
|
| 45 |
< |
void |
| 46 |
< |
recalc_fdlimit(void *unused) |
| 45 |
> |
static int |
| 46 |
> |
set_fdlimit(void) |
| 47 |
|
{ |
| 77 |
– |
#ifdef _WIN32 |
| 78 |
– |
/* this is what WSAStartup() usually returns. Even though they say |
| 79 |
– |
* the value is for compatibility reasons and should be ignored, |
| 80 |
– |
* we actually can create even more sockets... */ |
| 81 |
– |
hard_fdlimit = 32767; |
| 82 |
– |
#else |
| 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); |
| 69 |
< |
#endif |
| 67 |
> |
return -1; |
| 68 |
> |
} |
| 69 |
> |
|
| 70 |
> |
void |
| 71 |
> |
fdlist_init(void) |
| 72 |
> |
{ |
| 73 |
> |
set_fdlimit(); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
static inline unsigned int |
| 77 |
|
hash_fd(int fd) |
| 78 |
|
{ |
| 110 |
– |
#ifdef _WIN32 |
| 111 |
– |
return ((((unsigned) fd) >> 2) % FD_HASH_SIZE); |
| 112 |
– |
#else |
| 79 |
|
return (((unsigned) fd) % FD_HASH_SIZE); |
| 114 |
– |
#endif |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
fde_t * |
| 127 |
|
if (F->flags.is_socket) |
| 128 |
|
comm_setselect(F, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0); |
| 129 |
|
|
| 130 |
< |
if (F->dns_query != NULL) |
| 166 |
< |
{ |
| 167 |
< |
delete_resolver_queries(F->dns_query); |
| 168 |
< |
MyFree(F->dns_query); |
| 169 |
< |
} |
| 130 |
> |
delete_resolver_queries(F); |
| 131 |
|
|
| 132 |
|
#ifdef HAVE_LIBCRYPTO |
| 133 |
|
if (F->ssl) |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
/* Unlike squid, we're actually closing the FD here! -- adrian */ |
| 188 |
– |
#ifdef _WIN32 |
| 189 |
– |
if (F->flags.is_socket) |
| 190 |
– |
closesocket(F->fd); |
| 191 |
– |
else |
| 192 |
– |
CloseHandle((HANDLE)F->fd); |
| 193 |
– |
#else |
| 149 |
|
close(F->fd); |
| 195 |
– |
#endif |
| 150 |
|
number_fd--; |
| 151 |
< |
#ifdef INVARIANTS |
| 152 |
< |
memset(F, '\0', sizeof(fde_t)); |
| 199 |
< |
#endif |
| 151 |
> |
|
| 152 |
> |
memset(F, 0, sizeof(fde_t)); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
/* |
| 192 |
|
/* Make sure stdio descriptors (0-2) and profiler descriptor (3) |
| 193 |
|
* always go somewhere harmless. Use -foreground for profiling |
| 194 |
|
* or executing from gdb */ |
| 242 |
– |
#ifndef _WIN32 |
| 195 |
|
void |
| 196 |
|
close_standard_fds(void) |
| 197 |
|
{ |
| 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 |
|
} |
| 255 |
– |
#endif |
| 207 |
|
|
| 208 |
|
void |
| 209 |
|
close_fds(fde_t *one) |
| 214 |
|
for (i = 0; i < FD_HASH_SIZE; i++) |
| 215 |
|
for (F = fd_hash[i]; F != NULL; F = F->hnext) |
| 216 |
|
if (F != one) |
| 266 |
– |
{ |
| 267 |
– |
#ifdef _WIN32 |
| 268 |
– |
if (F->flags.is_socket) |
| 269 |
– |
closesocket(F->fd); |
| 270 |
– |
else |
| 271 |
– |
CloseHandle((HANDLE)F->fd); |
| 272 |
– |
#else |
| 217 |
|
close(F->fd); |
| 274 |
– |
#endif |
| 275 |
– |
} |
| 218 |
|
} |