From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 30 00:10:45 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 480F216A4CE for ; Thu, 30 Dec 2004 00:10:45 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id AD70C43D39 for ; Thu, 30 Dec 2004 00:10:44 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.1) id iBU0AhKZ004199; Wed, 29 Dec 2004 18:10:43 -0600 (CST) (envelope-from dan) Date: Wed, 29 Dec 2004 18:10:43 -0600 From: Dan Nelson To: Christopher Weimann Message-ID: <20041230001043.GA88403@dan.emsphone.com> References: <20041229230521.GB31984@smtp.k12us.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041229230521.GB31984@smtp.k12us.com> X-OS: FreeBSD 5.3-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: freebsd-hackers@freebsd.org Subject: Re: execl bug? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Dec 2004 00:10:45 -0000 In the last episode (Dec 29), Christopher Weimann said: > It seems that the open handle is carried through and usable by the > child program unless the parent has done something to move the file > pointer. For example the program below (tst.c) opens a file, reads a > line, rewinds then uses execl to call "cat -" which ought to send the > file to stdout. > > I thought I must be misunderstanding how execl is supposed to work so > I tried it on a Redhat box to see if everything behaves the same. It > doesn't. On Redhat the file is displayed just as I would expect. I think your problem here is with rewind(). There's nothing that says it has to change the underlying filedescriptor; FreeBSD's fseek code knows that the beginning of the file is still within its stdio buffer, so it simply resets the seek offset in the FILE* back to zero. See the code in /usr/src/lib/libc/stdio/fseek.c . Replacing your rewind() with an lseek(0,0,SEEK_SET) makes the program work. -- Dan Nelson dnelson@allantgroup.com