changeset 14198:1c1c2a1c85d7

Added restrict_get_process_size()
author Timo Sirainen <tss@iki.fi>
date Tue, 21 Feb 2012 11:35:05 +0200
parents a6a58512f0df
children 242ad2a73648
files src/lib/restrict-process-size.c src/lib/restrict-process-size.h
diffstat 2 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/restrict-process-size.c	Tue Feb 21 11:15:56 2012 +0200
+++ b/src/lib/restrict-process-size.c	Tue Feb 21 11:35:05 2012 +0200
@@ -49,6 +49,25 @@
 #endif
 }
 
+int restrict_get_process_size(rlim_t *limit_r)
+{
+	struct rlimit rlim;
+
+#ifdef HAVE_RLIMIT_AS
+	if (getrlimit(RLIMIT_AS, &rlim) < 0) {
+		i_error("getrlimit(RLIMIT_AS): %m");
+		return -1;
+	}
+#else
+	if (getrlimit(RLIMIT_DATA, &rlim) < 0) {
+		i_error("getrlimit(RLIMIT_DATA): %m");
+		return -1;
+	}
+#endif
+	*limit_r = rlim.rlim_cur;
+	return 0;
+}
+
 int restrict_get_core_limit(rlim_t *limit_r)
 {
 #ifdef HAVE_RLIMIT_CORE
--- a/src/lib/restrict-process-size.h	Tue Feb 21 11:15:56 2012 +0200
+++ b/src/lib/restrict-process-size.h	Tue Feb 21 11:35:05 2012 +0200
@@ -15,6 +15,8 @@
 
 /* Get the core dump size limit. Returns 0 if ok, -1 if lookup failed. */
 int restrict_get_core_limit(rlim_t *limit_r);
+/* Get the process VSZ size limit. Returns 0 if ok, -1 if lookup failed. */
+int restrict_get_process_size(rlim_t *limit_r);
 /* Get the process count limit. Returns 0 if ok, -1 if lookup failed. */
 int restrict_get_process_limit(rlim_t *limit_r);
 /* Get the fd limit. Returns 0 if ok, -1 if lookup failed. */