Redirecting stdout using dup/dup2
Olof Larsson
larsso at space.se
Wed Sep 25 15:08:55 UTC 2002
Hi,
Nope, both of them fail, and as Eric Norum confirmed, they seem to be broken.
He provided me with a nice workaround, though. (Many thanks to all of you for
your help!)
Olof
On Wed, 25 Sep 2002, jennifer averett wrote:
>
> Does the Psx13 test work with the version you are running?
> This test uses dup and dup2.
>
> Jennifer
>
> Joel Sherrill wrote:
> >
> > Jennifer... can you add anything to this?
> >
> > Olof Larsson wrote:
> > >
> > > Hi all,
> > >
> > > Does anyone know if redirecting stdout to a socket using dup2 or dup is
> > > supposed to work? Something along the following:
> > >
> > > fd = accept(...)
> > > dup2(fd,1)
> > > printf("foo");
> > >
> > > It works fine in Linux, but unfortunately I get nothing through on the
> > > receiving side when I try the same thing in RTEMS.
> >
> > What about the new descriptor returned by dup2?
> >
> > I thought this type of trick had been done before. Maybe someone
> > can confirm this.
> >
> > Can you do this without trying a socket
> >
> > The code for dup() and dup2() start in cpukit/libcsupport/src/dup*.c
> > and both end up going through fcntl(..F_DUPFD..)
> > (cpukit/libcsupport/src/fcntl.c). If this isn't working, then
> > the copying going on may not be deep enough.
> >
> > I also don't see a close in dup2() which I think should be done
> > between the 2nd fstat() and fcntl() if I read the Linux man page
> > correctly.
> >
> > If you can figure out what is broken, a patch would be appreciated.
> >
> > > Thanks
> >
> >
> > >
> > > Olof
> >
> > --
> > Joel Sherrill, Ph.D. Director of Research & Development
> > joel at OARcorp.com On-Line Applications Research
> > Ask me about RTEMS: a free RTOS Huntsville AL 35805
> > Support Available (256) 722-9985
>
More information about the users
mailing list