Allow setting resource limits on core dump size and memory usage. Idea and some code from crawl.develz.org dgl.
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@523 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
43f2b685c7
commit
11eef77614
38
configure.ac
38
configure.ac
|
@ -108,6 +108,44 @@ if test "$enable_sqlite" = yes; then
|
|||
AC_DEFINE_UNQUOTED(USE_SQLITE_DB, "$dgl_sqlite_db", [Path and filename of the SQLite database.])
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
dgl_rlimit_core_default=157286400
|
||||
AC_ARG_WITH(rlimit-core,
|
||||
[AC_HELP_STRING([--with-rlimit-core=SIZE], [Enable and set the core dump maximum size.])],
|
||||
[dgl_rlimit_core=$withval; enable_rlimit=yes], [dgl_rlimit_core=$dgl_rlimit_core_default])
|
||||
|
||||
if test "$enable_rlimit" = yes; then
|
||||
if test "$dgl_rlimit_core" = yes; then
|
||||
dgl_rlimit_core=$dgl_rlimit_core_default
|
||||
fi
|
||||
AC_CHECK_HEADERS([sys/resource.h], [], [AC_MSG_ERROR([sys/resource.h not found.])], [])
|
||||
AC_MSG_RESULT([Enabled and set maximum core dump size to $dgl_rlimit_core])
|
||||
AC_DEFINE(USE_RLIMIT,1,[Use getrlimit/setrlimit])
|
||||
AC_DEFINE_UNQUOTED(USE_RLIMIT_CORE, $dgl_rlimit_core, [Maximum core dump size])
|
||||
enable_rlimit=no
|
||||
fi
|
||||
|
||||
dgl_rlimit_as_default=104857600
|
||||
AC_ARG_WITH(rlimit-as,
|
||||
[AC_HELP_STRING([--with-rlimit-as=SIZE], [Enable and set the maximum memory usage.])],
|
||||
[dgl_rlimit_as=$withval; enable_rlimit=yes], [dgl_rlimit_as=$dgl_rlimit_as_default])
|
||||
|
||||
if test "$enable_rlimit" = yes; then
|
||||
if test "$dgl_rlimit_as" = yes; then
|
||||
dgl_rlimit_as=$dgl_rlimit_as_default
|
||||
fi
|
||||
AC_CHECK_HEADERS([sys/resource.h], [], [AC_MSG_ERROR([sys/resource.h not found.])], [])
|
||||
AC_MSG_RESULT([Enabled and set maximum memory usage limit to $dgl_rlimit_as])
|
||||
AC_DEFINE(USE_RLIMIT,1,[Use getrlimit/setrlimit])
|
||||
AC_DEFINE_UNQUOTED(USE_RLIMIT_AS, $dgl_rlimit_as, [Maximum mem usage])
|
||||
enable_rlimit=no
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
AC_ARG_WITH(config-file,
|
||||
[AC_HELP_STRING([--with-config-file=PATH], [Define the path to the default configuration file.])],
|
||||
[configfile=$withval], [configfile="/etc/dgamelaunch.conf"])
|
||||
|
|
|
@ -50,6 +50,9 @@
|
|||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h> /* ttyrec */
|
||||
#include <sys/stat.h>
|
||||
#ifdef USE_RLIMIT
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
#include <libgen.h>
|
||||
#include <stdlib.h>
|
||||
#include <curses.h>
|
||||
|
@ -1987,6 +1990,9 @@ main (int argc, char** argv)
|
|||
int userchoice;
|
||||
char *tmp;
|
||||
char *wall_email_str = NULL;
|
||||
#ifdef USE_RLIMIT
|
||||
struct rlimit lim;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
/* save argc, argv */
|
||||
|
@ -2082,6 +2088,23 @@ main (int argc, char** argv)
|
|||
if (!nhext && !nhauth)
|
||||
ttyrec_getpty ();
|
||||
|
||||
#ifdef USE_RLIMIT
|
||||
#ifdef USE_RLIMIT_CORE
|
||||
/* enable and set core dump size */
|
||||
if (!getrlimit(RLIMIT_CORE, &lim)) {
|
||||
lim.rlim_cur = USE_RLIMIT_CORE;
|
||||
setrlimit(RLIMIT_CORE, &lim);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_RLIMIT_AS
|
||||
/* set maximum memory usage */
|
||||
if (!getrlimit(RLIMIT_AS, &lim)) {
|
||||
lim.rlim_cur = USE_RLIMIT_AS;
|
||||
setrlimit(RLIMIT_AS, &lim);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (geteuid () != globalconfig.shed_uid)
|
||||
{
|
||||
/* chroot */
|
||||
|
|
Loading…
Reference in New Issue