Hello list, This patch attempts to make it possible to do a nonblocking read or write of fd's pointing to possibly shared struct file's in a non-racy manner, i.e. without using fcntl. One use case is when you want to read standard input, but don't want to switch fd 0 to O_NONBLOCK mode: if you get SIGKILLed, O_NONBLOCK will stay and your parent (e.g. a shell) can be upset. On Tuesday 14 August 2007 13:33, Alan Cox wrote: > > b) Make recv(fd, buf, size, flags) and send(fd, buf, size, flags); > >    work with non-socket fds too, for flags==0 or flags==MSG_DONTWAIT. > >    (it's ok to fail with "socket op on non-socket fd" for other values > >    of flags) > > I think that makes a lot of sense, and to be honest other MSG_ flags make > useful sense and have meaningful semantics that might be helpful > elsewhere if ever coded that way. Yes, that's my feeling too. > If you want to do this the first job is going to be to sort out the way > non-block is propogated to device driver read/write handlers. At the > moment they all check filp->f_flags ...which happens in ~250 files. I'd rather not touch that much of code, if possible. Attached patch detects send/recv(fd, buf, size, MSG_DONTWAIT) on non-sockets and turns them into non-blocking write/read. Since filp->f_flags appear to be read and modified without any locking, I cannot modify it without potentially affecting other processes accessing the same file through shared struct file. Therefore I simply make a temporary copy of struct file, set O_NONBLOCK in it and pass it to vfs_read/write. Is this heresy? ;) I see only one spinlock in struct file: #ifdef CONFIG_EPOLL         spinlock_t              f_ep_lock; #endif /* #ifdef CONFIG_EPOLL */ Do I need to take it? Also attached is ndelaytest.c which can be used to test that send(MSG_DONTWAIT) indeed is failing with EAGAIN if write would block and that other processes never see O_NONBLOCK set. Comments? -- vda