dovecot: Added restrict_fd_limit() and restrict_raise_fd_limit()
dovecot at dovecot.org
dovecot at dovecot.org
Fri Aug 24 20:50:49 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/c6d6ce742a82
changeset: 6314:c6d6ce742a82
user: Timo Sirainen <tss at iki.fi>
date: Fri Aug 24 20:50:44 2007 +0300
description:
Added restrict_fd_limit() and restrict_raise_fd_limit()
diffstat:
2 files changed, 38 insertions(+)
src/lib/restrict-process-size.c | 33 +++++++++++++++++++++++++++++++++
src/lib/restrict-process-size.h | 5 +++++
diffs (54 lines):
diff -r 0e08960275f8 -r c6d6ce742a82 src/lib/restrict-process-size.c
--- a/src/lib/restrict-process-size.c Fri Aug 24 20:49:33 2007 +0300
+++ b/src/lib/restrict-process-size.c Fri Aug 24 20:50:44 2007 +0300
@@ -42,3 +42,36 @@ void restrict_process_size(unsigned int
}
#endif
}
+
+void restrict_fd_limit(unsigned int count)
+{
+#ifdef HAVE_SETRLIMIT
+ struct rlimit rlim;
+
+ rlim.rlim_cur = rlim.rlim_max = count;
+ if (setrlimit(RLIMIT_NOFILE, &rlim) < 0)
+ i_fatal("setrlimit(RLIMIT_NOFILE, %u): %m", count);
+#endif
+}
+
+bool restrict_raise_fd_limit(unsigned int count)
+{
+#ifdef HAVE_SETRLIMIT
+ struct rlimit rlim, new_rlim;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
+ return FALSE;
+
+ if (rlim.rlim_cur < count)
+ new_rlim.rlim_cur = new_rlim.rlim_max = count;
+ if (setrlimit(RLIMIT_NOFILE, &new_rlim) == 0)
+ return TRUE;
+
+ /* raise as high as we can */
+ if (rlim.rlim_cur < rlim.rlim_max) {
+ rlim.rlim_cur = rlim.rlim_max;
+ (void)setrlimit(RLIMIT_NOFILE, &new_rlim);
+ }
+#endif
+ return FALSE;
+}
diff -r 0e08960275f8 -r c6d6ce742a82 src/lib/restrict-process-size.h
--- a/src/lib/restrict-process-size.h Fri Aug 24 20:49:33 2007 +0300
+++ b/src/lib/restrict-process-size.h Fri Aug 24 20:50:44 2007 +0300
@@ -4,5 +4,10 @@
/* Restrict max. process size. The size is in megabytes, setting it to
(unsigned int)-1 sets it unlimited. */
void restrict_process_size(unsigned int size, unsigned int max_processes);
+/* Set fd limit to count. */
+void restrict_fd_limit(unsigned int count);
+/* If fd limit is less than count, try to raise it. Probably fails (silently)
+ if we're not running as root. Returns TRUE if succeeded. */
+bool restrict_raise_fd_limit(unsigned int count);
#endif
More information about the dovecot-cvs
mailing list