Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Sep 2002 08:40:06 -0700 (PDT)
From:      Archie Cobbs <archie@packetdesign.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: misc/41331: Pthread library open sets O_NONBLOCK flag and causes  unnecessary EAGAIN errors especially with /dev/stdout.
Message-ID:  <200209101540.g8AFe6el081224@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/41331; it has been noted by GNATS.

From: Archie Cobbs <archie@packetdesign.com>
To: Antti Louko <alo@louko.com>
Cc: freebsd-gnats-submit@FreeBSD.org, deischen@freebsd.org
Subject: Re: misc/41331: Pthread library open sets O_NONBLOCK flag and causes 
 unnecessary EAGAIN errors especially with /dev/stdout.
Date: Tue, 10 Sep 2002 08:26:40 -0700

 Antti Louko wrote:
 > I just tried it in 4.6 Release and 4.6.2 and it still occurs. 
 
 I think this is a kernel bug, rather than a pthread bug.
 
 What's happening is that the file descriptor associated with
 /dev/stdout is "inheriting" the flags associated with file
 descriptor 0. This happens on both -stable and -current.
 
 This seems like broken behavior to me: flags should be associated
 with the file descriptor, not the underlying device or entity.
 But I don't know what the "official" semantics of /dev/stdout
 are supposed to be.
 
 The program below demonstrates the problem:
 
   $ cc -g -Wall -o flags flags.c
   $ ./flags 
   O_NONBLOCK is set
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <err.h>
 
 int
 main(int argc, char **argv)
 {
         int flags;
         int fd;
 
         if ((flags = fcntl(0, F_GETFL, 0)) == -1)
                 err(1, "fcntl");
         if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
                 err(1, "fcntl");
         if ((fd = open("/dev/stdout", O_WRONLY, 0)) == -1)
                 err(1, "open");
         if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
                 err(1, "fcntl");
         printf("O_NONBLOCK is %s\n", (flags & O_NONBLOCK) ? "set" : "not set");
         return (0);
 }

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




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