]> skyeroc.xyz Git - dgamelaunch/commitdiff
Allow setting resource limits on core dump size and memory usage. Idea and some code...
authorPasi Kallinen <paxed@alt.org>
Thu, 25 Feb 2010 16:40:55 +0000 (16:40 +0000)
committerPasi Kallinen <paxed@alt.org>
Thu, 25 Feb 2010 16:40:55 +0000 (16:40 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@523 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

configure.ac
dgamelaunch.c

index 421add278eda02e6bc329d25a6876ec5eea9adf7..8034a99abefa9191f98d458f83ffe38e2f590ad4 100644 (file)
@@ -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"])
index 7ec2e4483ee00764ba0b7da259ce2719c81414eb..c57ceb223e296ee08164a3e11d89ba4279a9b964 100644 (file)
@@ -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 */