s3:lib/util: make sure panic action can attach a debugger on ubuntu (>=10.10)
[ira/wip.git] / source3 / lib / util.c
index 689d41ed17c3bd907f998b5eb3a4028cbc788eeb..887d1849ee8cc1aee0238615f243f75a14dee97f 100644 (file)
 #include <ccan/hash/hash.h>
 #include "libcli/security/security.h"
 
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
 /* Max allowable allococation - 256mb - 0x10000000 */
 #define MAX_ALLOC_SIZE (1024*1024*256)
 
@@ -778,6 +782,13 @@ void smb_panic_s3(const char *why)
                    (unsigned long long)sys_getpid(), why));
        log_stack_trace();
 
+#if defined(HAVE_PRCTL) && defined(PR_SET_PTRACER)
+       /*
+        * Make sure all children can attach a debugger.
+        */
+       prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
+#endif
+
        cmd = lp_panic_action();
        if (cmd && *cmd) {
                DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmd));