Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Sep 2002 13:03:39 -0700
From:      Bakul Shah <bakul@bitblocks.com>
To:        Archie Cobbs <archie@dellroad.org>
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   Re: /dev/stdout behavior 
Message-ID:  <200209102003.QAA28365@thunderer.cnchost.com>
In-Reply-To: Your message of "Tue, 10 Sep 2002 10:58:02 PDT." <200209101758.g8AHw2C33935@arch20m.dellroad.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
> Bakul Shah writes:
> > > For example, if you use fcntl() to set flags on fd 0, and then open
> > > /dev/stdout, the new file descriptor you get back will have those
> > > same flags set. Run the program below to see an example. This is
> > > in agreement with the man page, which states that opening /dev/stdout
> > > is equivalent to dup(2)'ing fd 0.
> > 
> > Careful reading of man stdout will reveal that opening
> > /dev/stdout is equivalent to dup()ing fd 1, not fd 0.
> 
> Arg, this whole time I meant to use '1' instead of '0'...
>
> But, hey-- now there's an even bigger bug!

As the accidental discoverer of the bug, you should report it!

dup(2) says that everything but the close-on-exec flag is
shared by the new fd with the old fd.  So (except for this
bigger bug) the FreeBSD behavior is correct as verified by
changing
	if ((flags = fcntl(0, F_GETFL, 0)) == -1)
		err(1, "fcntl");
        if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
to
	if ((flags = fcntl(1, F_GETFL, 0)) == -1)
		err(1, "fcntl");
        if (fcntl(1, F_SETFL, flags | O_NONBLOCK) == -1)

You need to fix your test program similarly and run it under
Linux to see if the two OSes behave differently.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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