init.c (xinetd-2.3.15) | : | init.c (xinetd-2.3.15.4.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
* (c) Copyright 1992 by Panagiotis Tsirigotis | * (c) Copyright 1992 by Panagiotis Tsirigotis | |||
* (c) Sections Copyright 1998-2001 by Rob Braun | * (c) Sections Copyright 1998-2001 by Rob Braun | |||
* All rights reserved. The file named COPYRIGHT specifies the terms | * All rights reserved. The file named COPYRIGHT specifies the terms | |||
* and conditions for redistribution. | * and conditions for redistribution. | |||
*/ | */ | |||
#include "config.h" | #include "config.h" | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <sys/time.h> | #include <sys/time.h> | |||
#include <sys/stat.h> | #include <sys/stat.h> | |||
#ifdef HAVE_SYS_RESOURCE_H | ||||
#include <sys/resource.h> | #include <sys/resource.h> | |||
#endif | ||||
#include <syslog.h> | #include <syslog.h> | |||
#include <fcntl.h> | #include <fcntl.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <stdlib.h> | ||||
#include "sio.h" | #include "sio.h" | |||
#include "init.h" | #include "init.h" | |||
#include "defs.h" | #include "defs.h" | |||
#include "msg.h" | #include "msg.h" | |||
#include "signals.h" | #include "signals.h" | |||
#include "env.h" | #include "env.h" | |||
#include "confparse.h" | #include "confparse.h" | |||
#include "options.h" | #include "options.h" | |||
#include "main.h" | #include "main.h" | |||
#include "xconfig.h" | #include "xconfig.h" | |||
skipping to change at line 137 | skipping to change at line 135 | |||
if ( null_fd > MAX_PASS_FD ) | if ( null_fd > MAX_PASS_FD ) | |||
(void) Sclose( null_fd ) ; | (void) Sclose( null_fd ) ; | |||
} | } | |||
/* msg() cannot be used in this function, as it has not been initialized yet. */ | /* msg() cannot be used in this function, as it has not been initialized yet. */ | |||
static void set_fd_limit(void) | static void set_fd_limit(void) | |||
{ | { | |||
#ifdef RLIMIT_NOFILE | #ifdef RLIMIT_NOFILE | |||
struct rlimit rl ; | struct rlimit rl ; | |||
rlim_t maxfd ; | ||||
/* | /* | |||
* Set the soft file descriptor limit to the hard limit. | * Set the soft file descriptor limit to the hard limit. | |||
*/ | */ | |||
if ( getrlimit( RLIMIT_NOFILE, &rl ) == -1 ) | if ( getrlimit( RLIMIT_NOFILE, &rl ) == -1 ) | |||
{ | { | |||
syscall_failed("getrlimit(RLIMIT_NOFILE)"); | syscall_failed("getrlimit(RLIMIT_NOFILE)"); | |||
exit( 1 ) ; | exit( 1 ) ; | |||
} | } | |||
maxfd = rl.rlim_max; | ||||
if ( rl.rlim_max == RLIM_INFINITY ) | if ( rl.rlim_max == RLIM_INFINITY ) | |||
rl.rlim_max = FD_SETSIZE; | rl.rlim_max = MAX_FDS; | |||
/* XXX: a dumb way to prevent fd_set overflow possibilities; the rest | ||||
* of xinetd should be changed to use an OpenBSD inetd-like fd_grow(). */ | ||||
if ( rl.rlim_max > FD_SETSIZE ) | ||||
rl.rlim_max = FD_SETSIZE; | ||||
rl.rlim_cur = rl.rlim_max ; | ||||
if ( setrlimit( RLIMIT_NOFILE, &rl ) == -1 ) | ||||
{ | ||||
syscall_failed("setrlimit(RLIMIT_NOFILE)"); | ||||
ps.ros.max_descriptors = FD_SETSIZE; | ||||
ps.ros.orig_max_descriptors = FD_SETSIZE; | ||||
return ; | ||||
} | ||||
ps.ros.orig_max_descriptors = maxfd ; | ||||
ps.ros.max_descriptors = rl.rlim_max ; | ps.ros.max_descriptors = rl.rlim_max ; | |||
#else /* ! RLIMIT_NOFILE */ | #else /* ! RLIMIT_NOFILE */ | |||
ps.ros.max_descriptors = getdtablesize() ; | ps.ros.max_descriptors = getdtablesize() ; | |||
#endif /* RLIMIT_NOFILE */ | #endif /* RLIMIT_NOFILE */ | |||
} | } | |||
static void init_common( int argc, char *argv[] ) | static void init_common( int argc, char *argv[] ) | |||
{ | { | |||
const struct module *mp = NULL; | const struct module *mp = NULL; | |||
const char *func = "init_common" ; | const char *func = "init_common" ; | |||
skipping to change at line 286 | skipping to change at line 267 | |||
exit( 1 ) ; | exit( 1 ) ; | |||
} | } | |||
return( tab ) ; | return( tab ) ; | |||
} | } | |||
/* | /* | |||
* Create tables | * Create tables | |||
*/ | */ | |||
static void init_rw_state( void ) | static void init_rw_state( void ) | |||
{ | { | |||
const char *func = "init_rw_state" ; | ||||
SERVERS( ps ) = new_table( 0 ) ; | SERVERS( ps ) = new_table( 0 ) ; | |||
RETRIES( ps ) = new_table( 0 ) ; | RETRIES( ps ) = new_table( 0 ) ; | |||
SERVICES( ps ) = new_table( 0 ) ; | SERVICES( ps ) = new_table( 0 ) ; | |||
ps.rws.descriptors_free = ps.ros.max_descriptors - DESCRIPTORS_RESERVED ; | ps.rws.descriptors_free = ps.ros.max_descriptors - DESCRIPTORS_RESERVED ; | |||
#ifdef HAVE_POLL | ||||
ps.rws.pfds_allocated = ps.ros.max_descriptors ; | ||||
ps.rws.pfd_array = (struct pollfd *) | ||||
malloc( sizeof( struct pollfd ) * ps.rws.pfds_allocated ) | ||||
; | ||||
if ( ps.rws.pfd_array == NULL ) | ||||
{ | ||||
out_of_memory(func) ; | ||||
exit( 1 ) ; | ||||
} | ||||
ps.rws.pfds_last = 0 ; | ||||
#else | ||||
FD_ZERO( &ps.rws.socket_mask ) ; | FD_ZERO( &ps.rws.socket_mask ) ; | |||
ps.rws.mask_max = 0 ; | ps.rws.mask_max = 0 ; | |||
#endif /* HAVE_POLL */ | ||||
} | } | |||
/* | /* | |||
* Perform all necessary initializations | * Perform all necessary initializations | |||
*/ | */ | |||
void init_daemon( int argc, char *argv[] ) | void init_daemon( int argc, char *argv[] ) | |||
{ | { | |||
const char *fail = NULL; | const char *fail = NULL; | |||
debug.on = 0; | debug.on = 0; | |||
End of changes. 10 change blocks. | ||||
22 lines changed or deleted | 16 lines changed or added |