added max-nofile and max-nproc to httpd
This commit is contained in:
		| @ -43,6 +43,10 @@ | |||||||
| #	include <sys/prctl.h> | #	include <sys/prctl.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #if defined(HAVE_SYS_RESOURCE_H) | ||||||
|  | #	include <sys/resource.h> | ||||||
|  | #endif | ||||||
|  |  | ||||||
| /* --------------------------------------------------------------------- */ | /* --------------------------------------------------------------------- */ | ||||||
|  |  | ||||||
| static qse_httpd_t* g_httpd = QSE_NULL; | static qse_httpd_t* g_httpd = QSE_NULL; | ||||||
| @ -1294,6 +1298,39 @@ static int close_config_file (qse_httpd_t* httpd) | |||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | static void set_limit (qse_httpd_t* httpd, const qse_char_t* name, int what) | ||||||
|  | { | ||||||
|  | 	qse_xli_pair_t* pair; | ||||||
|  | 	httpd_xtn_t* httpd_xtn; | ||||||
|  |  | ||||||
|  | 	httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtnstd (httpd); | ||||||
|  |  | ||||||
|  | 	pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, name); | ||||||
|  | 	if (pair && pair->val->type == QSE_XLI_STR) | ||||||
|  | 	{ | ||||||
|  | #if defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) | ||||||
|  | 		struct rlimit lim; | ||||||
|  |  | ||||||
|  | 		if (getrlimit (what, &lim) == 0) | ||||||
|  | 		{ | ||||||
|  | 			const qse_char_t* str; | ||||||
|  |  | ||||||
|  | 			str = ((qse_xli_str_t*)pair->val)->ptr; | ||||||
|  | 			if (qse_strcasecmp (str, QSE_T("none")) != 0) | ||||||
|  | 			{ | ||||||
|  | 				if (qse_strcasecmp (str, QSE_T("unlimited")) == 0) | ||||||
|  | 					lim.rlim_cur = RLIM_INFINITY; | ||||||
|  | 				else | ||||||
|  | 					lim.rlim_cur = qse_strtoui (((qse_xli_str_t*)pair->val)->ptr); | ||||||
|  | 				if (setrlimit (what, &lim) <= -1) | ||||||
|  | 				{ | ||||||
|  | 					/* TODO: warning */ | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | #endif | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| static int load_config (qse_httpd_t* httpd) | static int load_config (qse_httpd_t* httpd) | ||||||
| { | { | ||||||
| @ -1314,6 +1351,13 @@ static int load_config (qse_httpd_t* httpd) | |||||||
| 		qse_httpd_freemem (httpd, tmp); | 		qse_httpd_freemem (httpd, tmp); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | #if defined(RLIMIT_NOFILE) | ||||||
|  | 	set_limit (httpd, QSE_T("max-nofile"), RLIMIT_NOFILE); | ||||||
|  | #endif | ||||||
|  | #if defined(RLIMIT_NPROC) | ||||||
|  | 	set_limit (httpd, QSE_T("max-nproc"), RLIMIT_NPROC); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	for (i = 0; ; i++) | 	for (i = 0; ; i++) | ||||||
| 	{ | 	{ | ||||||
| 		qse_char_t buf[32]; | 		qse_char_t buf[32]; | ||||||
|  | |||||||
| @ -5,6 +5,10 @@ | |||||||
| # string to be used as a httpd name  | # string to be used as a httpd name  | ||||||
| name = "QSEHTTPD v1"; | name = "QSEHTTPD v1"; | ||||||
|  |  | ||||||
|  | # none, unlimited, or positive number | ||||||
|  | max-nofile = none; | ||||||
|  | max-nproc = none; | ||||||
|  |  | ||||||
| ################################################ | ################################################ | ||||||
| # default server configuration | # default server configuration | ||||||
| ################################################ | ################################################ | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								qse/configure
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								qse/configure
									
									
									
									
										vendored
									
									
								
							| @ -17560,7 +17560,7 @@ _ACEOF | |||||||
| fi | fi | ||||||
| done | done | ||||||
|  |  | ||||||
| for ac_func in sysconf prctl fdopendir | for ac_func in sysconf prctl fdopendir setrlimit getrlimit | ||||||
| do : | do : | ||||||
|   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` |   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` | ||||||
| ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" | ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" | ||||||
|  | |||||||
| @ -139,7 +139,7 @@ AC_CHECK_FUNCS([isblank iswblank]) | |||||||
| AC_CHECK_FUNCS([lseek64 stat64 fstat64 lstat64 ftruncate64 readdir64]) | AC_CHECK_FUNCS([lseek64 stat64 fstat64 lstat64 ftruncate64 readdir64]) | ||||||
| AC_CHECK_FUNCS([timegm timelocal]) | AC_CHECK_FUNCS([timegm timelocal]) | ||||||
| AC_CHECK_FUNCS([utime utimes]) | AC_CHECK_FUNCS([utime utimes]) | ||||||
| AC_CHECK_FUNCS([sysconf prctl fdopendir]) | AC_CHECK_FUNCS([sysconf prctl fdopendir setrlimit getrlimit]) | ||||||
| AC_CHECK_FUNCS([backtrace backtrace_symbols]) | AC_CHECK_FUNCS([backtrace backtrace_symbols]) | ||||||
| AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select]) | AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select]) | ||||||
| AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) | AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) | ||||||
|  | |||||||
| @ -173,6 +173,9 @@ | |||||||
| /* Define to 1 if you have the `getifaddrs' function. */ | /* Define to 1 if you have the `getifaddrs' function. */ | ||||||
| #undef HAVE_GETIFADDRS | #undef HAVE_GETIFADDRS | ||||||
|  |  | ||||||
|  | /* Define to 1 if you have the `getrlimit' function. */ | ||||||
|  | #undef HAVE_GETRLIMIT | ||||||
|  |  | ||||||
| /* Define to 1 if you have the `gettid' function. */ | /* Define to 1 if you have the `gettid' function. */ | ||||||
| #undef HAVE_GETTID | #undef HAVE_GETTID | ||||||
|  |  | ||||||
| @ -344,6 +347,9 @@ | |||||||
| /* Define to 1 if you have the `setcontext' function. */ | /* Define to 1 if you have the `setcontext' function. */ | ||||||
| #undef HAVE_SETCONTEXT | #undef HAVE_SETCONTEXT | ||||||
|  |  | ||||||
|  | /* Define to 1 if you have the `setrlimit' function. */ | ||||||
|  | #undef HAVE_SETRLIMIT | ||||||
|  |  | ||||||
| /* Define if you have the shl_load function. */ | /* Define if you have the shl_load function. */ | ||||||
| #undef HAVE_SHL_LOAD | #undef HAVE_SHL_LOAD | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user