From: Timo Sirainen Date: Tue, 3 Mar 2009 02:04:11 +0000 (-0500) Subject: Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3. X-Git-Tag: 2.0.alpha1~1038^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a55742ae2e6b3fd53c8e2b5b63565d081ecfb1fc;p=thirdparty%2Fdovecot%2Fcore.git Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3. --HG-- branch : HEAD --- diff --git a/configure.in b/configure.in index 18ac51f74f..75fae218e0 100644 --- a/configure.in +++ b/configure.in @@ -1056,6 +1056,18 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ AC_DEFINE(HAVE_RLIMIT_CORE,, Define if you have RLIMIT_CORE for getrlimit()) ],[]) +AC_MSG_CHECKING([PR_SET_DUMPABLE]) +AC_TRY_LINK([ + #include +], [ + prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); +], [ + AC_DEFINE(HAVE_PR_SET_DUMPABLE,, Define if you have prctl(PR_SET_DUMPABLE)) + AC_MSG_RESULT(yes) +], [ + AC_MSG_RESULT(no) +]) + dnl * Linux compatible mremap() AC_MSG_CHECKING([Linux compatible mremap()]) AC_TRY_LINK([ diff --git a/src/imap/main.c b/src/imap/main.c index a1a351dc96..fae6a844a8 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -157,6 +157,7 @@ static void drop_privileges(void) } restrict_access_by_env(!IS_STANDALONE()); + restrict_access_allow_coredumps(TRUE); } static void main_init(void) diff --git a/src/lib/restrict-access.c b/src/lib/restrict-access.c index 0c41199847..8317126b53 100644 --- a/src/lib/restrict-access.c +++ b/src/lib/restrict-access.c @@ -13,6 +13,9 @@ #include #include #include +#ifdef HAVE_PR_SET_DUMPABLE +# include +#endif static gid_t process_primary_gid = (gid_t)-1; static gid_t process_privileged_gid = (gid_t)-1; @@ -370,6 +373,13 @@ void restrict_access_by_env(bool disallow_root) env_put("RESTRICT_GID_LAST="); } +void restrict_access_allow_coredumps(bool allow ATTR_UNUSED) +{ +#ifdef HAVE_PR_SET_DUMPABLE + (void)prctl(PR_SET_DUMPABLE, allow, 0, 0, 0); +#endif +} + int restrict_access_use_priv_gid(void) { i_assert(!process_using_priv_gid); diff --git a/src/lib/restrict-access.h b/src/lib/restrict-access.h index 601c505aaa..db2b527b0e 100644 --- a/src/lib/restrict-access.h +++ b/src/lib/restrict-access.h @@ -15,6 +15,10 @@ void restrict_access_set_env(const char *user, uid_t uid, environment settings and we have root uid or gid. */ void restrict_access_by_env(bool disallow_root); +/* Try to set up the process in a way that core dumps are still allowed + after calling restrict_access_by_env(). */ +void restrict_access_allow_coredumps(bool allow); + /* If privileged_gid was set, these functions can be used to temporarily gain access to the group. */ int restrict_access_use_priv_gid(void); diff --git a/src/master/child-process.c b/src/master/child-process.c index 1b0c365111..5814cb437a 100644 --- a/src/master/child-process.c +++ b/src/master/child-process.c @@ -127,6 +127,35 @@ static const char *get_exit_status_message(enum fatal_exit_status status, return NULL; } +static void +log_coredump(string_t *str, enum process_type process_type, int status) +{ +#ifdef WCOREDUMP + int signum = WTERMSIG(status); + + if (WCOREDUMP(status)) { + str_append(str, " (core dumped)"); + return; + } + + if (signum != SIGABRT && signum != SIGSEGV && signum != SIGBUS) + return; + + /* let's try to figure out why we didn't get a core dump */ + if (process_type != PROCESS_TYPE_IMAP && + process_type != PROCESS_TYPE_POP3) + str_append(str, " (core not dumped)"); +#ifndef HAVE_PR_SET_DUMPABLE + else if (!settings_root->defaults->mail_drop_priv_before_exec) + str_append(str, " (core not dumped - set mail_drop_priv_before_exec=yes)"); +#endif + else if (core_dumps_disabled) + str_printfa(str, " (core dumps disabled)"); + else + str_append(str, " (core not dumped - is home dir set?)"); +#endif +} + static void sigchld_handler(int signo ATTR_UNUSED, void *context ATTR_UNUSED) { @@ -181,6 +210,7 @@ static void sigchld_handler(int signo ATTR_UNUSED, str_printfa(str, "child %s (%s) killed with signal %d", dec2str(pid), process_type_name, WTERMSIG(status)); + log_coredump(str, process_type, status); } if (str_len(str) > 0) { diff --git a/src/master/common.h b/src/master/common.h index fc25c0d57d..b694407a11 100644 --- a/src/master/common.h +++ b/src/master/common.h @@ -15,6 +15,7 @@ extern char program_path[]; extern char ssl_manual_key_password[]; extern const char *env_tz; extern bool auth_success_written; +extern bool core_dumps_disabled; #ifdef DEBUG extern bool gdb; #endif diff --git a/src/master/main.c b/src/master/main.c index 166e95b1ab..77088a1a56 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -46,6 +46,7 @@ char program_path[PATH_MAX]; char ssl_manual_key_password[100]; const char *env_tz; bool auth_success_written; +bool core_dumps_disabled; #ifdef DEBUG bool gdb; #endif @@ -264,7 +265,9 @@ 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) + core_dumps_disabled = restrict_get_core_limit(&core_limit) == 0 && + core_limit == 0; + if (core_dumps_disabled) i_info(STARTUP_STRING" (core dumps disabled)"); else i_info(STARTUP_STRING); diff --git a/src/pop3/main.c b/src/pop3/main.c index 0aeb51c957..484207648f 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -178,6 +178,7 @@ static void drop_privileges(void) } restrict_access_by_env(!IS_STANDALONE()); + restrict_access_allow_coredumps(TRUE); } static bool main_init(void)