static TALLOC_CTX *talloc_autofree_ctx;
+/*
+ * On BSD systems, ptrace(PT_DETACH) uses a third argument for
+ * resume address, with the magic value (void *)1 to resume where
+ * process stopped. Specifying NULL there leads to a crash because
+ * process resumes at address 0.
+ */
#ifdef HAVE_SYS_PTRACE_H
# ifdef __linux__
# define _PTRACE(_x, _y) ptrace(_x, _y, NULL, NULL)
+# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, NULL, NULL)
# else
# define _PTRACE(_x, _y) ptrace(_x, _y, NULL, 0)
+# define _PTRACE_DETACH(_x) ptrace(PT_DETACH, _x, (void *)1, NULL)
# endif
# ifdef HAVE_CAPABILITY_H
}
/* Detach */
- _PTRACE(PT_DETACH, ppid);
+ _PTRACE_DETACH(ppid);
exit(0);
}