summaryrefslogtreecommitdiff
path: root/dbus/dbus-sysdeps-util-unix.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2018-11-20 12:48:40 +0000
committerSimon McVittie <smcv@collabora.com>2018-11-20 12:58:17 +0000
commit77327b7bd897985261315e38e8524c21c266b1f0 (patch)
tree8884e769491908e678464bc6085d055f882d3827 /dbus/dbus-sysdeps-util-unix.c
parent16d2453ffada1d0c84996f392c7e4cad091da715 (diff)
downloaddbus-77327b7bd897985261315e38e8524c21c266b1f0.tar.gz
_dbus_disable_crash_handling: Factor out from test-segfault
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'dbus/dbus-sysdeps-util-unix.c')
-rw-r--r--dbus/dbus-sysdeps-util-unix.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
index 262dcfde..3e74cf17 100644
--- a/dbus/dbus-sysdeps-util-unix.c
+++ b/dbus/dbus-sysdeps-util-unix.c
@@ -52,6 +52,10 @@
#include <dirent.h>
#include <sys/un.h>
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
#ifdef HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
#endif
@@ -1583,3 +1587,28 @@ _dbus_daemon_report_stopping (void)
sd_notify (0, "STOPPING=1");
#endif
}
+
+/**
+ * Try to disable core dumps and similar special crash handling.
+ */
+void
+_dbus_disable_crash_handling (void)
+{
+#ifdef HAVE_SETRLIMIT
+ /* No core dumps please, we know we crashed. */
+ struct rlimit r = { 0, };
+
+ getrlimit (RLIMIT_CORE, &r);
+ r.rlim_cur = 0;
+ setrlimit (RLIMIT_CORE, &r);
+#endif
+
+#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
+ /* Really, no core dumps please. On Linux, if core_pattern is
+ * set to a pipe (for abrt/apport/corekeeper/etc.), RLIMIT_CORE of 0
+ * is ignored (deliberately, so people can debug init(8) and other
+ * early stuff); but Linux has PR_SET_DUMPABLE, so we can avoid core
+ * dumps anyway. */
+ prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
+#endif
+}