Module Name:    src
Committed By:   christos
Date:           Thu Jan 30 16:13:51 UTC 2025

Modified Files:
        src/tests/lib/libexecinfo: t_backtrace_sandbox.c

Log Message:
fork and don't use atf in the child (from martin@)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libexecinfo/t_backtrace_sandbox.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libexecinfo/t_backtrace_sandbox.c
diff -u src/tests/lib/libexecinfo/t_backtrace_sandbox.c:1.2 src/tests/lib/libexecinfo/t_backtrace_sandbox.c:1.3
--- src/tests/lib/libexecinfo/t_backtrace_sandbox.c:1.2	Mon Jan 27 12:02:50 2025
+++ src/tests/lib/libexecinfo/t_backtrace_sandbox.c	Thu Jan 30 11:13:51 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_backtrace_sandbox.c,v 1.2 2025/01/27 17:02:50 riastradh Exp $	*/
+/*	$NetBSD: t_backtrace_sandbox.c,v 1.3 2025/01/30 16:13:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 2025 Kyle Evans <kev...@freebsd.org>
@@ -6,9 +6,10 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_backtrace_sandbox.c,v 1.2 2025/01/27 17:02:50 riastradh Exp $");
+__RCSID("$NetBSD: t_backtrace_sandbox.c,v 1.3 2025/01/30 16:13:51 christos Exp $");
 
 #include <sys/param.h>
+#include <sys/wait.h>
 #ifdef __FreeBSD__
 #include <sys/capsicum.h>
 #define __arraycount(a) nitems(a)
@@ -18,6 +19,7 @@ __RCSID("$NetBSD: t_backtrace_sandbox.c,
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include <atf-c.h>
@@ -39,6 +41,8 @@ ATF_TC_BODY(backtrace_sandbox, tc)
 	void *addr[BT_FUNCTIONS];
 	char **syms;
 	size_t frames;
+	pid_t pid;
+	int status;
 
 	frames = backtrace(addr, __arraycount(addr));
 	ATF_REQUIRE(frames > 0);
@@ -46,15 +50,33 @@ ATF_TC_BODY(backtrace_sandbox, tc)
 	syms = backtrace_symbols_fmt(addr, frames, "%n");
 	ATF_REQUIRE(strcmp(syms[0], "atfu_backtrace_sandbox_body") == 0);
 
-	backtrace_sandbox_init();
+	pid = fork();
+	ATF_REQUIRE(pid >= 0);
+
+	if (pid == 0) {
+
+		backtrace_sandbox_init();
 #ifdef __FreeBSD__
-	cap_enter();
+		cap_enter();
 #else
-	ATF_REQUIRE(chroot("/tmp") == 0);
+		if (chroot("/tmp") != 0)
+			_exit(EXIT_FAILURE);
 #endif
 
-	syms = backtrace_symbols_fmt(addr, frames, "%n");
-	ATF_REQUIRE(strcmp(syms[0], "atfu_backtrace_sandbox_body") == 0);
+		syms = backtrace_symbols_fmt(addr, frames, "%n");
+		if (strcmp(syms[0], "atfu_backtrace_sandbox_body") != 0)
+			_exit(EXIT_FAILURE);
+
+		backtrace_sandbox_fini();
+
+		_exit(EXIT_SUCCESS);
+	}
+
+	(void)wait(&status);
+
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
+		atf_tc_fail("resolving symbols in chroot failed");
+
 }
 
 ATF_TP_ADD_TCS(tp)

Reply via email to