Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Dec 2004 18:10:43 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Christopher Weimann <csw@k12hq.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: execl bug?
Message-ID:  <20041230001043.GA88403@dan.emsphone.com>
In-Reply-To: <20041229230521.GB31984@smtp.k12us.com>
References:  <20041229230521.GB31984@smtp.k12us.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041230001043.GA88403>