svn commit: trunk/uClibc/libc/stdio

vapier at uclibc.org vapier at uclibc.org
Thu Feb 8 18:05:45 UTC 2007


Author: vapier
Date: 2007-02-08 10:05:44 -0800 (Thu, 08 Feb 2007)
New Revision: 17815

Log:
Paul Brook writes:
I'm seeing a hang in applications that open and close files with a
non-threaded uClibc.  There is code in fclose() to remove a file handle from
_stdio_openlist however it's commented out, allegedly because it is dead.
_stdio_openlist is used in several places, including _stdio_term when a
program exits. fclose() frees the struct, so I don't see how the code can
possibly be redundant.

In the __UCLIBC_HAS_THREADS__ && __STDIO_BUFFERS case the file is removed from
_stdio_openlist by __STDIO_OPENLIST_DEC_USE.

The attached patch fixes this bug be re-enabling the code.


Modified:
   trunk/uClibc/libc/stdio/fclose.c


Changeset:
Modified: trunk/uClibc/libc/stdio/fclose.c
===================================================================
--- trunk/uClibc/libc/stdio/fclose.c	2007-02-08 16:49:07 UTC (rev 17814)
+++ trunk/uClibc/libc/stdio/fclose.c	2007-02-08 18:05:44 UTC (rev 17815)
@@ -16,37 +16,32 @@
 	int rv = 0;
 	__STDIO_AUTO_THREADLOCK_VAR;
 
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning REMINDER: dead code... but may want to simply check and not remove
+#ifdef __STDIO_HAS_OPENLIST
+#if !defined(__UCLIBC_HAS_THREADS__) || !defined(__STDIO_BUFFERS)
+	/* First, remove the file from the open file list. */
+	{
+		FILE *ptr;
+
+		__STDIO_THREADLOCK_OPENLIST_DEL;
+		__STDIO_THREADLOCK_OPENLIST_ADD;
+		ptr = _stdio_openlist;
+		if ((ptr = _stdio_openlist) == stream) {
+			_stdio_openlist = stream->__nextopen;
+		} else {
+			while (ptr) {
+				if (ptr->__nextopen == stream) {
+					ptr->__nextopen = stream->__nextopen;
+					break;
+				}
+				ptr = ptr->__nextopen;
+			}
+		}
+		__STDIO_THREADUNLOCK_OPENLIST_ADD;
+		__STDIO_THREADUNLOCK_OPENLIST_DEL;
+	}
 #endif
-/* #ifdef __STDIO_HAS_OPENLIST */
-/* #if !defined(__UCLIBC_HAS_THREADS__) || !defined(__STDIO_BUFFERS) */
-/* 	/\* First, remove the file from the open file list. *\/ */
-/* 	{ */
-/* 		register FILE *ptr; */
+#endif
 
-/* 		__STDIO_THREADLOCK_OPENLIST; */
-/* 		if ((ptr = _stdio_openlist) == stream) { */
-/* #warning does a mod!!! */
-/* 			_stdio_openlist = stream->__nextopen; */
-/* 		} else { */
-/* 			while (ptr) { */
-/* 				if (ptr->__nextopen == stream) { */
-/* 					ptr->__nextopen = stream->__nextopen; */
-/* 					break; */
-/* 				} */
-/* 				ptr = ptr->__nextopen; */
-/* 			} */
-/* 		} */
-/* 		__STDIO_THREADUNLOCK_OPENLIST; */
-
-/* 		if (!ptr) {	  /\* Did not find stream in the open file list! *\/ */
-/* 			return EOF; */
-/* 		} */
-/* 	} */
-/* #endif */
-/* #endif */
-
 	__STDIO_AUTO_THREADLOCK(stream);
 
 	__STDIO_STREAM_VALIDATE(stream);




More information about the uClibc-cvs mailing list