Skip to content
Snippets Groups Projects
Commit a753e50e authored by Per Hedbor's avatar Per Hedbor
Browse files

Reallocate fds_to_close when needed.

Rev: src/fd_control.c:1.28
parent c0d65d17
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "error.h" #include "error.h"
#include "fdlib.h" #include "fdlib.h"
RCSID("$Id: fd_control.c,v 1.27 1999/09/14 21:07:20 hubbe Exp $"); RCSID("$Id: fd_control.c,v 1.28 2000/05/20 02:21:47 per Exp $");
#else /* TESTING */ #else /* TESTING */
...@@ -73,9 +73,8 @@ int set_nonblocking(int fd,int which) ...@@ -73,9 +73,8 @@ int set_nonblocking(int fd,int which)
{ {
int ret; int ret;
#ifdef PIKE_DEBUG #ifdef PIKE_DEBUG
if(fd<0 || fd >MAX_OPEN_FILEDESCRIPTORS) if(fd<0)
fatal("Filedescriptor %d out of range [0,%d).\n", fatal("Filedescriptor %d out of range [0,inf).\n", fd);
fd, MAX_OPEN_FILEDESCRIPTORS);
#endif #endif
do do
...@@ -110,7 +109,7 @@ int query_nonblocking(int fd) ...@@ -110,7 +109,7 @@ int query_nonblocking(int fd)
{ {
int ret; int ret;
#ifdef PIKE_DEBUG #ifdef PIKE_DEBUG
if(fd<0 || fd > MAX_OPEN_FILEDESCRIPTORS) if(fd<0)
fatal("Filedescriptor out of range.\n"); fatal("Filedescriptor out of range.\n");
#endif #endif
...@@ -140,8 +139,23 @@ int query_nonblocking(int fd) ...@@ -140,8 +139,23 @@ int query_nonblocking(int fd)
#endif /* FD_CLOEXEC */ #endif /* FD_CLOEXEC */
#ifdef HAVE_BROKEN_F_SETFD #ifdef HAVE_BROKEN_F_SETFD
static int fds_to_close[MAX_OPEN_FILEDESCRIPTORS]; static int *fds_to_close;
static int num_fds_to_close = 0; static int fds_to_close_size = 0;
#define ASSURE_FDS_TO_CLOSE_SIZE(X) \
do{while(fds_to_close_size-1 < X) grow_fds_to_close();}while(0)
static void grow_fds_to_close( )
{
if(!fds_to_close_size)
fds_to_close_size = 1;
fds_to_close_size *= 2;
fds_to_close = realloc( fds_to_close, sizeof( int ) * fds_to_close_size );
if(!fds_to_close)
fatal("Out of memory in fd_control::grow_fds_to_close()\n"
"Tried to allocate %d fd_datum structs\n", fds_to_close_size);
MEMSET( fds+(fds_size/2), 0, fds_to_close_size*sizeof(int)/2 );
}
void do_close_on_exec(void) void do_close_on_exec(void)
{ {
...@@ -170,6 +184,7 @@ int set_close_on_exec(int fd, int which) ...@@ -170,6 +184,7 @@ int set_close_on_exec(int fd, int which)
return(0); /* Already marked */ return(0); /* Already marked */
} }
} }
ASSURE_FDS_TO_CLOSE_SIZE((num_fds_to_close+1));
fds_to_close[num_fds_to_close++] = fd; fds_to_close[num_fds_to_close++] = fd;
return(0); return(0);
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment