Update of /cvsroot/dhcp-agent/dhcp-agent
In directory usw-pr-cvs1:/tmp/cvs-serv5818
Modified Files:
config.h.in configure configure.in dhcp-agent.h dhcp-daemon.c
Log Message:
fixed to do file descriptor limit checking properly;
Index: config.h.in
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/config.h.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** config.h.in 2 Feb 2002 15:28:46 -0000 1.5
--- config.h.in 14 Feb 2002 10:43:34 -0000 1.6
***************
*** 16,19 ****
--- 16,22 ----
#undef HAVE_GETOPT_H
+ /* Define if you have the `getrusage' function. */
+ #undef HAVE_GETRUSAGE
+
/* Define if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
***************
*** 33,36 ****
--- 36,42 ----
/* Define if you have the `strdup' function. */
#undef HAVE_STRDUP
+
+ /* Define if you have the `sysconf' function. */
+ #undef HAVE_SYSCONF
/* Define if you have the <sys/utsname.h> header file. */
Index: configure
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** configure 2 Feb 2002 15:28:47 -0000 1.9
--- configure 14 Feb 2002 10:43:34 -0000 1.10
***************
*** 2378,2382 ****
done
! for ac_func in strdup uname calloc daemon rename
do
ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh`
--- 2378,2382 ----
done
! for ac_func in strdup uname calloc daemon rename sysconf getrusage
do
ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh`
Index: configure.in
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** configure.in 2 Feb 2002 15:28:47 -0000 1.9
--- configure.in 14 Feb 2002 10:43:34 -0000 1.10
***************
*** 32,36 ****
dnl check for functions
! AC_CHECK_FUNCS(strdup uname calloc daemon rename)
AC_CHECK_FUNCS(sprintf vsnprintf,
--- 32,36 ----
dnl check for functions
! AC_CHECK_FUNCS(strdup uname calloc daemon rename sysconf getrusage)
AC_CHECK_FUNCS(sprintf vsnprintf,
Index: dhcp-agent.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** dhcp-agent.h 14 Feb 2002 10:06:53 -0000 1.25
--- dhcp-agent.h 14 Feb 2002 10:43:34 -0000 1.26
***************
*** 116,119 ****
--- 116,124 ----
# define MAX_OPTIONS_HANDLED 62
+ /* sensible default for max descriptors -- we use this if we
+ can't find it through other means (sysconf/getrusage) */
+
+ #define SENSIBLE_DESCRIPTOR_MAX 128
+
/* type string limits. */
Index: dhcp-daemon.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** dhcp-daemon.c 14 Feb 2002 10:06:53 -0000 1.4
--- dhcp-daemon.c 14 Feb 2002 10:43:34 -0000 1.5
***************
*** 117,120 ****
--- 117,123 ----
{
long i, max_descriptors;
+ #ifdef RLIMIT_NOFILES
+ struct rlimit usage_limit;
+ #endif
/* If we have daemon() use it. */
***************
*** 168,189 ****
/* If we have sysconf and _SC_OPEN_MAX
* use them */
!
! #ifdef _SC_OPEN_MAX
max_descriptors = sysconf(_SC_OPEN_MAX);
#elif MAX_FILES
max_descriptors = MAX_FILES;
! #elif RLIMIT_NOFILES
! max_descriptors = getrusage(RLIMIT_NOFILES);
! #else
/* If we don't have any of these
! * use something big like 128. */
!
! max_descriptors = 128;
! #endif
!
! /* FIXME: we should be closing all descriptors
! * but we're not. */
for(i = 0;i < max_descriptors;i++) {
--- 171,206 ----
/* If we have sysconf and _SC_OPEN_MAX
* use them */
!
!
! #ifdef HAVE_SYSCONF
!
max_descriptors = sysconf(_SC_OPEN_MAX);
+
+ if(max_descriptors <= 0) /* indeterminate or error. */
+ max_descriptors = SENSIBLE_DESCRIPTOR_MAX;
+
+ /* Otherwise check for getrusage and use it. */
+
+ #elif HAVE_GETRUSAGE
+
+ if(getrusage(RLIMIT_NOFILES, &usage_limit) < 0)
+ max_descriptors = SENSIBLE_DESCRIPTOR_MAX;
+
+ max_descriptors = usage_limit.rlim_cur;
+
+ /* If we have neither of the above see if MAX_FILES is defined. */
#elif MAX_FILES
+
max_descriptors = MAX_FILES;
!
! /* If we have none of the above just use our sensible default. */
! #else /* _SC_OPEN_MAX */
/* If we don't have any of these
! * use our sensible default. */
! max_descriptors = SENSIBLE_DESCRIPTOR_MAX;
!
! #endif /* _SC_OPEN_MAX */
for(i = 0;i < max_descriptors;i++) {
|