From 41a77b78cff821007e3dd874619ebec7ce708c3d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 19 Jul 2025 07:43:28 -0700 Subject: [PATCH] tst-freopen4-main.c: Call support_capture_subprocess with chroot Update tst-freopen4-main.c to call support_capture_subprocess with chroot, which makes temporary files inaccessible, so that temporary files can be deleted. This partially fixes BZ #33182. Signed-off-by: H.J. Lu Reviewed-by: Adhemerval Zanella (cherry picked from commit 6463d4a7b28e5ee3891c34a8a1f0a59c24dfa9de) --- stdio-common/tst-freopen4-main.c | 44 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/stdio-common/tst-freopen4-main.c b/stdio-common/tst-freopen4-main.c index 3336f5327d..436da4d203 100644 --- a/stdio-common/tst-freopen4-main.c +++ b/stdio-common/tst-freopen4-main.c @@ -28,25 +28,15 @@ #include #include #include +#include -int -do_test (void) +static void +do_test_chroot (void *data) { - mtrace (); - char *temp_dir; + char *temp_dir = (char *) data; FILE *fp; int ret; - /* These chroot tests verify that either reopening a renamed or - deleted file works even in the absence of /proc, or that it fails - (without memory leaks); thus, for example, such reopening does - not crash in the absence of /proc. */ - - support_become_root (); - if (!support_can_chroot ()) - return EXIT_UNSUPPORTED; - - temp_dir = support_create_temp_directory ("tst-freopen4"); xchroot (temp_dir); /* Test freopen with NULL, renamed file. This verifies that @@ -96,6 +86,32 @@ do_test (void) puts ("freopen of deleted file failed (OK)"); free (temp_dir); +} + +int +do_test (void) +{ + mtrace (); + char *temp_dir; + + /* These chroot tests verify that either reopening a renamed or + deleted file works even in the absence of /proc, or that it fails + (without memory leaks); thus, for example, such reopening does + not crash in the absence of /proc. */ + + support_become_root (); + if (!support_can_chroot ()) + return EXIT_UNSUPPORTED; + + temp_dir = support_create_temp_directory ("tst-freopen4"); + + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_chroot, temp_dir); + support_capture_subprocess_check (&result, "freopen4", 0, + sc_allow_stdout); + fputs (result.out.buffer, stdout); + support_capture_subprocess_free (&result); + return 0; } -- 2.47.2