aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-runner.c
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-03-15 22:37:49 +0000
committerAlexander Richardson <alexander.richardson@cl.cam.ac.uk>2021-09-10 11:35:54 +0000
commitbb928288077ff0fcab50a881e1ade2cf249f7a14 (patch)
tree965ef48d243a79989398d8e182cda7ea4d97593e /tests/test-runner.c
parentUse /dev/fd instead of /proc/self/fd (diff)
downloadwayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar.gz
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar.bz2
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar.lz
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar.xz
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.tar.zst
wayland-bb928288077ff0fcab50a881e1ade2cf249f7a14.zip
test-runner: Implement is_debugger_attached() for FreeBSD
FreeBSD provides a PROC_TRACE_STATUS procctl(2) to detect this directly. Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Diffstat (limited to 'tests/test-runner.c')
-rw-r--r--tests/test-runner.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 8f08445..c0247b5 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -22,6 +22,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "../config.h"
#define _GNU_SOURCE
@@ -36,11 +37,16 @@
#include <dlfcn.h>
#include <errno.h>
#include <limits.h>
+#include <signal.h>
#include <sys/ptrace.h>
+#ifdef HAVE_SYS_PROCCTL_H
+#include <sys/procctl.h>
+#elif defined(HAVE_SYS_PRCTL_H)
#include <sys/prctl.h>
#ifndef PR_SET_PTRACER
# define PR_SET_PTRACER 0x59616d61
#endif
+#endif
#include "test-runner.h"
@@ -226,6 +232,21 @@ stderr_reset_color(void)
* Returns: 1 if a debugger is confirmed present; 0 if no debugger is
* present or if it can't be determined.
*/
+#if defined(HAVE_SYS_PROCCTL_H) && defined(PROC_TRACE_STATUS)
+static int
+is_debugger_attached(void)
+{
+ int rc;
+ int status;
+ rc = procctl(P_PID, getpid(), PROC_TRACE_STATUS, &status);
+ if (rc == -1) {
+ perror("procctl");
+ return 0;
+ }
+ /* -1=tracing disabled, 0=no debugger attached, >0=pid of debugger. */
+ return status > 0;
+}
+#elif defined(HAVE_SYS_PRCTL_H)
static int
is_debugger_attached(void)
{
@@ -287,6 +308,7 @@ is_debugger_attached(void)
return rc;
}
+#endif
int main(int argc, char *argv[])
{