dovecot-1.2: If core dump limit is 0, add "core dumps disabled" ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 23 07:28:15 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/aad49536db41
changeset: 7946:aad49536db41
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 23 07:28:07 2008 +0300
description:
If core dump limit is 0, add "core dumps disabled" to startup log line.

diffstat:

4 files changed, 48 insertions(+), 5 deletions(-)
configure.in                    |   12 ++++++++++++
src/lib/restrict-process-size.c |   20 ++++++++++++++++----
src/lib/restrict-process-size.h |    8 ++++++++
src/master/main.c               |   13 ++++++++++++-

diffs (108 lines):

diff -r 346fb1ff74ed -r aad49536db41 configure.in
--- a/configure.in	Mon Jun 23 06:52:55 2008 +0300
+++ b/configure.in	Mon Jun 23 07:28:07 2008 +0300
@@ -1063,6 +1063,18 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   getrlimit(RLIMIT_NPROC, &r);
 ]])],[
   AC_DEFINE(HAVE_RLIMIT_NPROC,, Define if you have RLIMIT_NPROC for setrlimit())
+],[])
+
+dnl * Do we have RLIMIT_CORE?
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+  #include <sys/types.h>
+  #include <sys/time.h>
+  #include <sys/resource.h>
+]], [[
+  struct rlimit r;
+  getrlimit(RLIMIT_CORE, &r);
+]])],[
+  AC_DEFINE(HAVE_RLIMIT_CORE,, Define if you have RLIMIT_CORE for getrlimit())
 ],[])
 
 dnl * Linux compatible mremap()
diff -r 346fb1ff74ed -r aad49536db41 src/lib/restrict-process-size.c
--- a/src/lib/restrict-process-size.c	Mon Jun 23 06:52:55 2008 +0300
+++ b/src/lib/restrict-process-size.c	Mon Jun 23 07:28:07 2008 +0300
@@ -4,10 +4,6 @@
 #include "restrict-process-size.h"
 
 #include <unistd.h>
-#include <sys/time.h>
-#ifdef HAVE_SYS_RESOURCE_H
-#  include <sys/resource.h>
-#endif
 
 void restrict_process_size(unsigned int size ATTR_UNUSED,
 			   unsigned int max_processes ATTR_UNUSED)
@@ -53,3 +49,19 @@ void restrict_fd_limit(unsigned int coun
 		i_fatal("setrlimit(RLIMIT_NOFILE, %u): %m", count);
 #endif
 }
+
+int restrict_get_core_limit(rlim_t *limit_r)
+{
+#ifdef HAVE_RLIMIT_CORE
+	struct rlimit rlim;
+
+	if (getrlimit(RLIMIT_CORE, &rlim) < 0) {
+		i_error("getrlimit(RLIMIT_CORE) failed: %m");
+		return -1;
+	}
+	*limit_r = rlim.rlim_cur;
+	return 0;
+#else
+	return -1;
+#endif
+}
diff -r 346fb1ff74ed -r aad49536db41 src/lib/restrict-process-size.h
--- a/src/lib/restrict-process-size.h	Mon Jun 23 06:52:55 2008 +0300
+++ b/src/lib/restrict-process-size.h	Mon Jun 23 07:28:07 2008 +0300
@@ -1,5 +1,10 @@
 #ifndef RESTRICT_PROCESS_SIZE_H
 #define RESTRICT_PROCESS_SIZE_H
+
+#include <sys/time.h>
+#ifdef HAVE_SYS_RESOURCE_H
+#  include <sys/resource.h>
+#endif
 
 /* Restrict max. process size. The size is in megabytes, setting it to
    (unsigned int)-1 sets it unlimited. */
@@ -7,4 +12,7 @@ void restrict_process_size(unsigned int 
 /* Set fd limit to count. */
 void restrict_fd_limit(unsigned int count);
 
+/* Get the core dump size limit. Returns 0 if ok, -1 if lookup failed. */
+int restrict_get_core_limit(rlim_t *limit_r);
+
 #endif
diff -r 346fb1ff74ed -r aad49536db41 src/master/main.c
--- a/src/master/main.c	Mon Jun 23 06:52:55 2008 +0300
+++ b/src/master/main.c	Mon Jun 23 07:28:07 2008 +0300
@@ -234,6 +234,17 @@ static void create_pid_file(const char *
 	(void)close(fd);
 }
 
+static void main_log_startup(void)
+{
+#define STARTUP_STRING PACKAGE_NAME" v"VERSION" starting up"
+	rlim_t core_limit;
+
+	if (restrict_get_core_limit(&core_limit) == 0 && core_limit == 0)
+		i_info(STARTUP_STRING" (core dumps disabled)");
+	else
+		i_info(STARTUP_STRING);
+}
+
 static void main_init(bool log_error)
 {
 	drop_capabilities();
@@ -255,7 +266,7 @@ static void main_init(bool log_error)
 		i_error("This is Dovecot's error log");
 		i_fatal("This is Dovecot's fatal log");
 	}
-	i_info(PACKAGE_NAME" v"VERSION" starting up");
+	main_log_startup();
 
 	lib_signals_init();
         lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);


More information about the dovecot-cvs mailing list