Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!husc6!rice!sun-spots-request From: essick@prisma.com (Ray Essick) Newsgroups: comp.sys.sun Subject: Re: Possible bug in SunOS Release 4 Bourne Shell? Keywords: SunOS Message-ID: <1646@brazos.Rice.edu> Date: 25 Sep 89 14:10:13 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 26 Approved: Sun-Spots@rice.edu X-Sun-Spots-Digest: Volume 8, Issue 132, message 3 of 9 Keith Waclena shows a simple shell script that surprisingly changes behavior depending on whether its input is a pipe or a file. The alleged culprit is the Bourne shell under SunOS 4.x We recreated the same situation here at Prisma and found that the problem is NOT in the Bourne shell. Instead, the bad program is /bin/cat. SunOS 4 /bin/cat knows about mmap() and tries to use a mmap/write cycle instead of a read/write cycle. This saves a buffer copy from the kernel to user space; so it does make sense. The bad news is that the code that says "can we use mmap()" within /bin/cat assumes that the entire file is to be copied. It starts the mmap() at offset 0. In Keith's script, the shell hands cat a perfectly positioned file descriptor and, in essence, cat blindly does an lseek(,0,0) when it uses mmap(). Our fix was to modify /bin/cat's test so that it checked the file position and only uses mmap() if the file was positioned on a page boundary. A more complete solution could have done the appropriate mmap() and offset into the page, but we felt that it wasn't worth the effort. Our fix reverts to the read/write loop when things aren't perfectly aligned. -- Ray Essick, essick@prisma.com