added max-nofile and max-nproc to httpd

This commit is contained in:
hyung-hwan 2013-04-13 05:22:41 +00:00
parent 45b26152e3
commit d6208e893e
5 changed files with 56 additions and 2 deletions

View File

@ -43,6 +43,10 @@
# include <sys/prctl.h>
#endif
#if defined(HAVE_SYS_RESOURCE_H)
# include <sys/resource.h>
#endif
/* --------------------------------------------------------------------- */
static qse_httpd_t* g_httpd = QSE_NULL;
@ -1294,6 +1298,39 @@ static int close_config_file (qse_httpd_t* httpd)
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)
{
@ -1314,6 +1351,13 @@ static int load_config (qse_httpd_t* httpd)
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++)
{
qse_char_t buf[32];

View File

@ -5,6 +5,10 @@
# string to be used as a httpd name
name = "QSEHTTPD v1";
# none, unlimited, or positive number
max-nofile = none;
max-nproc = none;
################################################
# default server configuration
################################################

2
qse/configure vendored
View File

@ -17560,7 +17560,7 @@ _ACEOF
fi
done
for ac_func in sysconf prctl fdopendir
for ac_func in sysconf prctl fdopendir setrlimit getrlimit
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@ -139,7 +139,7 @@ AC_CHECK_FUNCS([isblank iswblank])
AC_CHECK_FUNCS([lseek64 stat64 fstat64 lstat64 ftruncate64 readdir64])
AC_CHECK_FUNCS([timegm timelocal])
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([fork vfork posix_spawn gettid nanosleep select])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])

View File

@ -173,6 +173,9 @@
/* Define to 1 if you have the `getifaddrs' function. */
#undef HAVE_GETIFADDRS
/* Define to 1 if you have the `getrlimit' function. */
#undef HAVE_GETRLIMIT
/* Define to 1 if you have the `gettid' function. */
#undef HAVE_GETTID
@ -344,6 +347,9 @@
/* Define to 1 if you have the `setcontext' function. */
#undef HAVE_SETCONTEXT
/* Define to 1 if you have the `setrlimit' function. */
#undef HAVE_SETRLIMIT
/* Define if you have the shl_load function. */
#undef HAVE_SHL_LOAD