From: H.J. Lu Date: Sat, 19 Jul 2025 14:43:27 +0000 (-0700) Subject: tst-fopen-threaded.c: Delete temporary file X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ec7a532ffdb9a6e0a4b220d7a694d6120701035;p=thirdparty%2Fglibc.git tst-fopen-threaded.c: Delete temporary file Update tst-fopen-threaded.c to call support_create_temp_directory to create a temporary directory and open "file" in the temporary directory, instead of using /tmp/openclosetest and leaving it behind. This partially fixes BZ #33182. Signed-off-by: H.J. Lu Reviewed-by: Adhemerval Zanella (cherry picked from commit e7db5150603bb2224a2bfd9628cae04ddcbe49e3) --- diff --git a/sysdeps/pthread/tst-fopen-threaded.c b/sysdeps/pthread/tst-fopen-threaded.c index ade58ad19e..c17f1eaa13 100644 --- a/sysdeps/pthread/tst-fopen-threaded.c +++ b/sysdeps/pthread/tst-fopen-threaded.c @@ -34,11 +34,13 @@ #include #include #include +#include #include #include #include #include +#include #define NUM_THREADS 100 #define ITERS 10 @@ -111,7 +113,8 @@ threadOpenCloseRoutine (void *argv) /* Wait for all threads to be ready to call fopen and fclose. */ xpthread_barrier_wait (&barrier); - FILE *fd = xfopen ("/tmp/openclosetest", "w+"); + char *file = (char *) argv; + FILE *fd = xfopen (file, "w+"); xfclose (fd); return NULL; } @@ -235,6 +238,10 @@ do_test (void) xfclose (fd_file); } + char *tempdir = support_create_temp_directory ("openclosetest-"); + char *file = xasprintf ("%s/file", tempdir); + add_temp_file (file); + /* Test 3: Concurrent open/close. */ for (int reps = 1; reps <= ITERS; reps++) { @@ -243,7 +250,7 @@ do_test (void) { threads[i] = xpthread_create (support_small_stack_thread_attribute (), - threadOpenCloseRoutine, NULL); + threadOpenCloseRoutine, file); } for (int i = 0; i < NUM_THREADS; i++) { @@ -252,6 +259,9 @@ do_test (void) xpthread_barrier_destroy (&barrier); } + free (file); + free (tempdir); + return 0; }