File xinetd-2.3.14-file-limit.patch of Package xinetd.5694
Index: xinetd-2.3.14/xinetd/attr.h
===================================================================
--- xinetd-2.3.14.orig/xinetd/attr.h
+++ xinetd-2.3.14/xinetd/attr.h
@@ -61,12 +61,13 @@
#define A_DISABLED 43
#define A_MDNS 44
#define A_LIBWRAP 45
+#define A_RLIMIT_FILES 46
/*
* SERVICE_ATTRIBUTES is the number of service attributes and also
* the number from which defaults-only attributes start.
*/
-#define SERVICE_ATTRIBUTES ( A_MDNS + 1 )
+#define SERVICE_ATTRIBUTES ( A_MDNS + 2 )
/*
* Mask of attributes that must be specified.
Index: xinetd-2.3.14/xinetd/child.c
===================================================================
--- xinetd-2.3.14.orig/xinetd/child.c
+++ xinetd-2.3.14/xinetd/child.c
@@ -98,6 +98,10 @@ void exec_server( const struct server *s
#ifdef RLIMIT_NOFILE
+ if ( SC_RLIM_FILES( scp ))
+ {
+ ps.ros.max_descriptors = SC_RLIM_FILES( scp );
+ }
rl.rlim_max = ps.ros.orig_max_descriptors ;
rl.rlim_cur = ps.ros.max_descriptors ;
(void) setrlimit( RLIMIT_NOFILE, &rl ) ;
Index: xinetd-2.3.14/xinetd/parse.c
===================================================================
--- xinetd-2.3.14.orig/xinetd/parse.c
+++ xinetd-2.3.14/xinetd/parse.c
@@ -92,6 +92,9 @@ static const struct attribute service_at
#ifdef RLIMIT_DATA
{ "rlimit_data", A_RLIMIT_DATA, 1, rlim_data_parser },
#endif
+#ifdef RLIMIT_NOFILE
+ { "rlimit_files", A_RLIMIT_FILES, 1, rlim_files_parser },
+#endif
#ifdef RLIMIT_RSS
{ "rlimit_rss", A_RLIMIT_RSS, 1, rlim_rss_parser },
#endif
Index: xinetd-2.3.14/xinetd/parsers.c
===================================================================
--- xinetd-2.3.14.orig/xinetd/parsers.c
+++ xinetd-2.3.14/xinetd/parsers.c
@@ -1415,9 +1415,32 @@ status_e rlim_data_parser( pset_h values
}
#endif
+#ifdef RLIMIT_NOFILE
+status_e rlim_files_parser( pset_h values,
+ struct service_config *scp,
+ enum assign_op op )
+{
+ char *mem = (char *) pset_pointer( values, 0 ) ;
+ const char *func = "rlim_files_parser" ;
+
+ if ( EQ( mem, "UNLIMITED" ) )
+ SC_RLIM_FILES(scp) = (rlim_t)RLIM_INFINITY ;
+ else
+ {
+ if ( get_limit ( mem, &SC_RLIM_FILES(scp)) )
+ {
+ parsemsg( LOG_ERR, func,
+ "Max files limit is invalid: %s", mem ) ;
+ return( FAILED ) ;
+ }
+ }
+ return( OK ) ;
+}
+#endif
+
#ifdef RLIMIT_RSS
status_e rlim_rss_parser( pset_h values,
- struct service_config *scp,
+ struct service_config *scp,
enum assign_op op )
{
char *mem = (char *) pset_pointer( values, 0 ) ;
Index: xinetd-2.3.14/xinetd/parsers.h
===================================================================
--- xinetd-2.3.14.orig/xinetd/parsers.h
+++ xinetd-2.3.14/xinetd/parsers.h
@@ -57,6 +57,9 @@ status_e rlim_cpu_parser(pset_h, struct
#ifdef RLIMIT_DATA
status_e rlim_data_parser(pset_h, struct service_config *, enum assign_op) ;
#endif
+#ifdef RLIMIT_NOFILE
+status_e rlim_files_parser(pset_h, struct service_config *, enum assign_op) ;
+#endif
#ifdef RLIMIT_RSS
status_e rlim_rss_parser(pset_h, struct service_config *, enum assign_op) ;
#endif
Index: xinetd-2.3.14/xinetd/sconf.h
===================================================================
--- xinetd-2.3.14.orig/xinetd/sconf.h
+++ xinetd-2.3.14/xinetd/sconf.h
@@ -142,6 +142,7 @@ struct service_config
rlim_t sc_rlim_as;
rlim_t sc_rlim_cpu;
rlim_t sc_rlim_data;
+ rlim_t sc_rlim_files;
rlim_t sc_rlim_rss;
rlim_t sc_rlim_stack;
mode_t sc_umask;
@@ -190,6 +191,7 @@ struct service_config
#define SC_RLIM_AS( scp ) (scp)->sc_rlim_as
#define SC_RLIM_CPU( scp ) (scp)->sc_rlim_cpu
#define SC_RLIM_DATA( scp ) (scp)->sc_rlim_data
+#define SC_RLIM_FILES( scp ) (scp)->sc_rlim_files
#define SC_RLIM_RSS( scp ) (scp)->sc_rlim_rss
#define SC_RLIM_STACK( scp ) (scp)->sc_rlim_stack
#define SC_TYPE( scp ) (scp)->sc_type
Index: xinetd-2.3.14/xinetd/xinetd.conf.man
===================================================================
--- xinetd-2.3.14.orig/xinetd/xinetd.conf.man
+++ xinetd-2.3.14/xinetd/xinetd.conf.man
@@ -568,6 +568,12 @@ is implemented, it is more useful to set
rlimit_rss and rlimit_stack. This resource limit is only implemented on
Linux systems.
.TP
+.B rlimit_files
+Sets the maximum number of open files that the service may use.
+One parameter is required, which is a positive integer representing
+the number of open file descriptors. Practical limit of this number
+is around 1024000.
+.TP
.B rlimit_cpu
Sets the maximum number of CPU seconds that the service may use.
One parameter is required, which is either a positive integer representing