@@ -453,7 +453,7 @@ int do_suid(const int uid, const int gid)
453
453
* \param target target that should be reached
454
454
* \return return 0 on success, -1 on error
455
455
*/
456
- int increase_open_fds ( unsigned int target )
456
+ int set_open_fds_limit ( void )
457
457
{
458
458
struct rlimit lim , orig ;
459
459
@@ -465,18 +465,23 @@ int increase_open_fds(unsigned int target)
465
465
orig = lim ;
466
466
LM_DBG ("current open file limits: %lu/%lu\n" ,
467
467
(unsigned long )lim .rlim_cur , (unsigned long )lim .rlim_max );
468
- if ((lim .rlim_cur == RLIM_INFINITY ) || (target <=lim .rlim_cur ))
469
- /* nothing to do */
468
+ if (open_files_limit <=0 ) {
469
+ /* if not set from cfg, we just read the existing value */
470
+ open_files_limit = lim .rlim_cur ;
470
471
goto done ;
471
- else if ((lim .rlim_max == RLIM_INFINITY ) || (target <=lim .rlim_max )){
472
- lim .rlim_cur = target ; /* increase soft limit to target */
473
- }else {
472
+ }
473
+ if ((lim .rlim_cur == RLIM_INFINITY ) || (open_files_limit <=lim .rlim_cur ))
474
+ /* nothing to do (we do no reduce the limit) */
475
+ goto done ;
476
+ if ((lim .rlim_max == RLIM_INFINITY ) || (open_files_limit <=lim .rlim_max )) {
477
+ lim .rlim_cur = open_files_limit ; /* increase soft limit to target */
478
+ } else {
474
479
/* more than the hard limit */
475
480
LM_INFO ("trying to increase the open file limit"
476
481
" past the hard limit (%ld -> %d)\n" ,
477
- (unsigned long )lim .rlim_max , target );
478
- lim .rlim_max = target ;
479
- lim .rlim_cur = target ;
482
+ (unsigned long )lim .rlim_max , open_files_limit );
483
+ lim .rlim_max = open_files_limit ;
484
+ lim .rlim_cur = open_files_limit ;
480
485
}
481
486
LM_DBG ("increasing open file limits to: %lu/%lu\n" ,
482
487
(unsigned long )lim .rlim_cur , (unsigned long )lim .rlim_max );
@@ -493,11 +498,14 @@ int increase_open_fds(unsigned int target)
493
498
if (setrlimit (RLIMIT_NOFILE , & lim )== 0 ){
494
499
LM_CRIT ("maximum number of file descriptors increased to"
495
500
" %u\n" ,(unsigned )orig .rlim_max );
501
+ open_files_limit = orig .rlim_max ;
502
+ goto done ;
496
503
}
497
504
}
498
505
goto error ;
499
506
}
500
507
done :
508
+ LM_DBG ("open files limit set to %d\n" ,open_files_limit );
501
509
return 0 ;
502
510
error :
503
511
return -1 ;
0 commit comments