Subject: Re: struct emul modification
To: None <tech-kern@netbsd.org>
From: Jaromír <jdolecek@netbsd.org>
List: tech-kern
Date: 06/06/2001 12:20:55
This is the way I had in my mind when I proposed to do the Linux-specific
SIGIO hacks in Linux-specific code. This diff has not been tested,
but should give general idea :) This would need adjustment for newpipes,
of course. I still think that emulation-wide EMUL_NO_BSD_ASYNCIO_PIPE
flag is not right.

Jaromir

Index: linux_file.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/common/linux_file.c,v
retrieving revision 1.37
diff -u -p -r1.37 linux_file.c
--- linux_file.c	2001/01/22 21:31:37	1.37
+++ linux_file.c	2001/06/06 10:18:55
@@ -317,6 +317,35 @@ linux_sys_fcntl(p, v, retval)
 		return 0;
 	case LINUX_F_SETFL:
 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
+		/*
+		 * Linux doesn't send SIGIO for pipes, even when it still
+		 * allows the ASYNC flag to be set for the descriptors.
+		 * Some Linux packages (e.g. jdk) expect this behaviour
+		 * and get seriously confused if they get SIGIO for pipe.
+		 * So check if the descriptor is a pipe and clear the
+		 * async flag if appropriate.
+		 */
+		if (val & LINUX_FASYNC) {
+			struct filedesc	*fdp;
+			struct file	*fp;
+			struct socket *so;
+
+			fdp = p->p_fd;
+
+			if ((u_int)fd >= fdp->fd_nfiles ||
+			    (fp = fdp->fd_ofiles[fd]) == NULL ||
+			    (fp->f_iflags & FIF_WANTCLOSE) != 0)
+				return (EBADF);
+
+			FILE_USE(fp);
+
+			if (fp->f_type == DTYPE_VNODE &&
+			    (so = fp->f_data) && (so->so_state & SS_ISAPIPE))
+				val &= ~LINUX_FASYNC;
+
+			FILE_UNUSE(fp);
+		}
+
 		SCARG(&fca, fd) = fd;
 		SCARG(&fca, cmd) = F_SETFL;
 		SCARG(&fca, arg) = (caddr_t) val;
-- 
Jaromir Dolecek <jdolecek@NetBSD.org>      http://www.ics.muni.cz/~dolecek/
NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!