Ticket UUID: | 723502 | |||
Title: | Directory Read Bug w/TCL_THREADS | |||
Type: | Bug | Version: | obsolete: 8.4.2 | |
Submitter: | peterdrexel | Created on: | 2003-04-18 05:04:31 | |
Subsystem: | 49. Threading | Assigned To: | vasiljevic | |
Priority: | 9 Immediate | Severity: | ||
Status: | Closed | Last Modified: | 2003-05-15 00:38:16 | |
Resolution: | Fixed | Closed By: | hobbs | |
Closed on: | 2003-05-14 17:38:16 | |||
Description: |
Version: TCL 8.4.2 OS: Mac OSX 10.1.5 (or any platform where TCL_THREADS is defined) Behavior: Directory entries are not read correctly when TCL commands such as glob are used. Instead the result indicates that no entries could be found. Expected Behavior: glob *.o should return a list of .o files within a directory (it there are any of course) The last argument in the call to memcpy in the function TclpReaddir in source file tclUnixThrd.c is incorrect. The sizeof operator is applied to the address of the item being copied instead of the item itself and consequently only a fraction of the necessary directory information is being copied. 8.4.2 code: memcpy((VOID *) &tsdPtr->rdbuf.ent, (VOID *) ent, sizeof(&tsdPtr->rdbuf)); should read: memcpy((VOID *) &tsdPtr->rdbuf.ent, (VOID *) ent, sizeof(tsdPtr->rdbuf)); | |||
User Comments: |
hobbs added on 2003-05-15 00:38:16:
Logged In: YES user_id=72656 Closing as Zoran noted it was fixed. vasiljevic added on 2003-05-12 15:54:01: Logged In: YES user_id=95086 I can't say for sure, without actually testing this, but I suppose yes, it will break. So, the better way, as I said is to try the regular bug-report path. I will try the bugreporter.apple.com. Lets see how this works. BTW, this one is now fixed both in 8.4 branch and in head. Zoran das added on 2003-05-12 15:42:00: Logged In: YES user_id=90580 so does this mean that the code in tclUnixThrd.c fails on OS X even if HAVE_READDIR_R is not defined due to the opendir/ closedir bug? I have had good experiences with bug reports to http://bugreporter.apple.com but I fear it may already be too late now to get a fix into 10.3, you should ask if this bug is known and if it will be fixed in 10.3 on the darwin developers list http://www.lists.apple.com/mailman/listinfo/darwin-development many apple engineers working at the libc level hang out there. Might be useful to mention the realpath issue as well. vasiljevic added on 2003-05-12 15:32:28: Logged In: YES user_id=95086 Well, the readdir_r is supposed to be thread-safe, but on osx, when many threads are doing: opendir readdir_r closedir in parallel, you get memory corruption in closedir after a while. What I did was wrap all those with my own wrappers with my_opendir doing the actual opendir, slurping all dir entries in an linked list with readdir_r and my_readdir simply traversing this list. The my_closedir frees the whole thing. All work of my_opendir is done under mutex protection. This was the only way I could solve the memory-trashing, which happens otherwise. I'm not sure you can plug this into Tcl current layout easily. That's why I suggest to wait for Apple to catch up and update the OS and correct the bug. No; I haven't posted a bug to Apple yet. Somehow I have a very bad feeling about that (i.e. waste of time) judging from my own previous experiences with the company. But I may be wrong and things may have changed since... Zoran das added on 2003-05-12 15:19:41: Logged In: YES user_id=90580 oy, that's bad, the point of _r in readdir_r is supposed to be that it's thread safe... I hope you have reported this as a bug to Apple? Given that I have to do something for realpath in the makesystem already, I'll see about removing HAVE_READDIR_R as well so that the tcl version gets used. vasiljevic added on 2003-05-12 15:14:40: Logged In: YES user_id=95086 Oh yes. The readdir_r in 10.2 (at least the version I have) is also broken when multiple threads are engaged in file tree walks. The problem is difficult to reproduce (as with all MT problems, phew) but it's there. We have our own kind of "find" utility employing MT and written for the AOLserver. Now, for that, I had to write my own readdir/opendir/closedir wrappers. I hope to see the problem solved with the new release of MacOSX. If not, we must/should do something there as well. I wouldn't rush, though, because most of the people won't hit this one. Speaking of 10.1 bug, it is ok. I will correct it in the CVS now. Zoran. das added on 2003-05-12 15:10:48: Logged In: YES user_id=90580 oops, I meant "check this in", not "check this"... das added on 2003-05-12 15:00:27: Logged In: YES user_id=90580 Zoran, could you check this soon so that it makes it into 8.4.3 (or I can do it if you prefer), 8.4.2 is completely broken on 10.1 due to this... are you saying that we should use the tcl provided version of readdir_r on 10.2 and later as well (similar to what we need to do for realpath in bug 711232)? vasiljevic added on 2003-05-12 14:52:13: Logged In: YES user_id=95086 Well, this is happening for older 10.1.xxx OSX since newer ones have readdir_r already. But the bug report is correct, i.e. there is a mistake in the code, as described. I will correct this in both CVS HEAD and in 8.4 branch if nobody objects. Th problem is: even the newer readdir_r with its opendir/closedir companions is broken for MT. I will have to avait the new OSX update and if it shows same problems, I might talk to Daniel Steffen and Jim Ingham how best to correct that. Zoran peterdrexel added on 2003-04-18 12:04:31: File Added - 48090: tclUnixThrd.c |
Attachments:
- tclUnixThrd.c [download] added by peterdrexel on 2003-04-18 12:04:31. [details]