From a8bf6a97824ac7a7e69cbdb4c1caaa24b2e64cd8 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 14 May 2015 12:58:00 +0200 Subject: [PATCH] Refactor Tools::disableCoreDumps(). - Use all available methods. - Don't print a warning when no method is implmeneted on the platform. --- src/core/Tools.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 01ec316e2..8034417f0 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -39,10 +39,12 @@ #include "config-keepassx.h" +#if defined(HAVE_RLIMIT_CORE) +#include +#endif + #if defined(HAVE_PR_SET_DUMPABLE) #include -#elif defined(HAVE_RLIMIT_CORE) -#include #endif #ifdef HAVE_PT_DENY_ATTACH @@ -222,21 +224,23 @@ QString platform() void disableCoreDumps() { - bool success = false; + // default to true + // there is no point in printing a warning if this is not implemented on the platform + bool success = true; - // prefer PR_SET_DUMPABLE since that also prevents ptrace -#if defined(HAVE_PR_SET_DUMPABLE) - success = (prctl(PR_SET_DUMPABLE, 0) == 0); -#elif defined(HAVE_RLIMIT_CORE) +#if defined(HAVE_RLIMIT_CORE) struct rlimit limit; limit.rlim_cur = 0; limit.rlim_max = 0; - success = (setrlimit(RLIMIT_CORE, &limit) == 0); + success = success && (setrlimit(RLIMIT_CORE, &limit) == 0); +#endif + +#if defined(HAVE_PR_SET_DUMPABLE) + success = success && (prctl(PR_SET_DUMPABLE, 0) == 0); #endif // Mac OS X #ifdef HAVE_PT_DENY_ATTACH - // make sure setrlimit() and ptrace() succeeded success = success && (ptrace(PT_DENY_ATTACH, 0, 0, 0) == 0); #endif