From 49831cd1918dfaa682ba3a7054173d1a6683436b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 8 Apr 2025 10:42:17 +0200 Subject: [PATCH] Increase reliability of stdio-common/tst-setvbuf2 (RHEL-46737) Related: RHEL-46737 --- glibc-RHEL-46737-3.patch | 112 +++++++++++++++++++++++++++++++++++++++ glibc.spec | 6 ++- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 glibc-RHEL-46737-3.patch diff --git a/glibc-RHEL-46737-3.patch b/glibc-RHEL-46737-3.patch new file mode 100644 index 0000000..fc5ce1b --- /dev/null +++ b/glibc-RHEL-46737-3.patch @@ -0,0 +1,112 @@ +commit 4fa959d13d21b8f56a43aa0a416100303736c55c +Author: Florian Weimer +Date: Tue Apr 8 10:39:44 2025 +0200 + + stdio-common: In tst-setvbuf2, close helper thread descriptor only if opened + + The helper thread may get canceled before the open system + call succeds. Then ThreadData.fd remains zero, and eventually + the xclose call in end_reader_thread fails because descriptor 0 + is not open. + + Instead, initialize the fd member to -1 (not a valid descriptor) + and close the descriptor only if valid. Do this in a new end_thread + helper routine. + + Also add more error checking to close operations. + + Fixes commit 95b780c1d0549678c0a244c6e2112ec97edf0839 ("stdio: Add + more setvbuf tests"). + +diff --git a/stdio-common/tst-setvbuf2.c b/stdio-common/tst-setvbuf2.c +index 6cc83355f391afab..84d8b43a5811b4be 100644 +--- a/stdio-common/tst-setvbuf2.c ++++ b/stdio-common/tst-setvbuf2.c +@@ -240,6 +240,21 @@ typedef struct { + /* It's OK if this is static, we only run one at a time. */ + ThreadData thread_data; + ++static void ++end_thread (pthread_t *ptid) ++{ ++ if (*ptid) ++ { ++ pthread_cancel (*ptid); ++ xpthread_join (*ptid); ++ /* The descriptor was passed in, or the helper thread made ++ sufficient progress and opened the file. */ ++ if (thread_data.fd >= 0) ++ xclose (thread_data.fd); ++ *ptid = 0; ++ } ++} ++ + static void * + writer_thread_proc (void *closure) + { +@@ -306,7 +321,7 @@ static void + start_writer_thread_n (const char *fname) + { + debug; +- thread_data.fd = 0; ++ thread_data.fd = -1; + thread_data.fname = fname; + writer_thread_tid = xpthread_create (NULL, writer_thread_proc, + (void *)&thread_data); +@@ -316,13 +331,7 @@ static void + end_writer_thread (void) + { + debug; +- if (writer_thread_tid) +- { +- pthread_cancel (writer_thread_tid); +- xpthread_join (writer_thread_tid); +- xclose (thread_data.fd); +- writer_thread_tid = 0; +- } ++ end_thread (&writer_thread_tid); + } + + static void +@@ -339,7 +348,7 @@ static void + start_reader_thread_n (const char *fname) + { + debug; +- thread_data.fd = 0; ++ thread_data.fd = -1; + thread_data.fname = fname; + reader_thread_tid = xpthread_create (NULL, reader_thread_proc, + (void *)&thread_data); +@@ -349,13 +358,7 @@ static void + end_reader_thread (void) + { + debug; +- if (reader_thread_tid) +- { +- pthread_cancel (reader_thread_tid); +- xpthread_join (reader_thread_tid); +- xclose (thread_data.fd); +- reader_thread_tid = 0; +- } ++ end_thread (&reader_thread_tid); + } + + /*------------------------------------------------------------*/ +@@ -852,7 +855,7 @@ do_second_part (FILE *fp, + } + + +- fclose (fp); ++ xfclose (fp); + return rv; + } + +@@ -939,7 +942,7 @@ recurse (FILE *fp, + break; + + default: /* parent */ +- fclose (fp); ++ xfclose (fp); + xwaitpid (pid, &status, 0); + if (WIFEXITED (status) + && WEXITSTATUS (status) == 0) diff --git a/glibc.spec b/glibc.spec index 0c9dc72..58b8320 100644 --- a/glibc.spec +++ b/glibc.spec @@ -157,7 +157,7 @@ end \ Summary: The GNU libc libraries Name: glibc Version: %{glibcversion} -Release: 185%{?dist} +Release: 186%{?dist} # In general, GPLv2+ is used by programs, LGPLv2+ is used for # libraries. @@ -1183,6 +1183,7 @@ Patch875: glibc-RHEL-46726-14.patch Patch876: glibc-RHEL-46726-15.patch Patch877: glibc-RHEL-46737-1.patch Patch878: glibc-RHEL-46737-2.patch +Patch879: glibc-RHEL-46737-3.patch ############################################################################## # Continued list of core "glibc" package information: @@ -3176,6 +3177,9 @@ update_gconv_modules_cache () %endif %changelog +* Tue Apr 8 2025 Florian Weimer - 2.34-186 +- Increase reliability of stdio-common/tst-setvbuf2 (RHEL-46737) + * Wed Apr 2 2025 DJ Delorie - 2.34-185 - Extend setvbuf testing (RHEL-46737)