Subject: fdclone() and FNONBLOCK
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 02/12/2005 21:34:53
Hi,
I have an application (initiallty written for linux) that
open(O_NONBLOCK|O_RDWR) a device. This device uses fdclone() in its open:
xenevtopen(dev_t dev, int flag, int mode, struct proc *p)
{
        struct xenevt_d *d;
        struct file *fp;
        int fd, error;  

        printf("xenevtopen flags %d\n", flag);

        /* falloc() will use the descriptor for us. */
        if ((error = falloc(p, &fp, &fd)) != 0)
                return error;

        d = malloc(sizeof(*d), M_DEVBUF, M_WAITOK | M_ZERO);

        return fdclone(p, fp, fd, &xenevt_fileops, d);
}

This works as expected, expect that FNONBLOCK isn't set in struct file
passed to the read routine.
First I'm not sure open(O_NONBLOCK) will cause FNONBLOCK to be set on
read. The open(2) linux man page is clear about this, but the NetBSD one
isn't (it doesn't say if the nonblock behavior is only for open, or for
subsequent I/O as well).
If open() is supposed to set FNONBLOCK for subsequent operations, then
it's fdclone() which doesn't preserve the flags. Could someone explain
me where the problem is here ?

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--