From: Timo Sirainen Date: Mon, 23 Jun 2008 04:28:07 +0000 (+0300) Subject: If core dump limit is 0, add "core dumps disabled" to startup log line. X-Git-Tag: 1.2.alpha1~215 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=799291e076f181e56599c93b06282156ab695fd6;p=thirdparty%2Fdovecot%2Fcore.git If core dump limit is 0, add "core dumps disabled" to startup log line. --HG-- branch : HEAD --- diff --git a/configure.in b/configure.in index 2eae3f2526..1a50d6d88b 100644 --- a/configure.in +++ b/configure.in @@ -1065,6 +1065,18 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 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 + #include + #include +]], [[ + struct rlimit r; + getrlimit(RLIMIT_CORE, &r); +]])],[ + AC_DEFINE(HAVE_RLIMIT_CORE,, Define if you have RLIMIT_CORE for getrlimit()) +],[]) + dnl * Linux compatible mremap() AC_MSG_CHECKING([Linux compatible mremap()]) AC_TRY_LINK([ diff --git a/src/lib/restrict-process-size.c b/src/lib/restrict-process-size.c index 5f29938536..1ec60748a3 100644 --- a/src/lib/restrict-process-size.c +++ b/src/lib/restrict-process-size.c @@ -4,10 +4,6 @@ #include "restrict-process-size.h" #include -#include -#ifdef HAVE_SYS_RESOURCE_H -# include -#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 count) 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 --git a/src/lib/restrict-process-size.h b/src/lib/restrict-process-size.h index 174a5f18e2..1e60a69cfa 100644 --- a/src/lib/restrict-process-size.h +++ b/src/lib/restrict-process-size.h @@ -1,10 +1,18 @@ #ifndef RESTRICT_PROCESS_SIZE_H #define RESTRICT_PROCESS_SIZE_H +#include +#ifdef HAVE_SYS_RESOURCE_H +# include +#endif + /* 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); +/* 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 --git a/src/master/main.c b/src/master/main.c index 75e07271a4..dca11a24bc 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -234,6 +234,17 @@ static void create_pid_file(const char *path) (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);