From mac@romy.ascape.com  Thu Jun  1 05:46:26 2000
Return-Path: <mac@romy.ascape.com>
Received: from romy.ascape.com (romy.ascape.com [212.105.74.153])
	by hub.freebsd.org (Postfix) with ESMTP id D328C37B79A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  1 Jun 2000 05:46:21 -0700 (PDT)
	(envelope-from mac@romy.ascape.com)
Received: by romy.ascape.com (Postfix, from userid 1001)
	id 235A33835; Thu,  1 Jun 2000 14:46:03 +0200 (CEST)
Message-Id: <20000601124603.235A33835@romy.ascape.com>
Date: Thu,  1 Jun 2000 14:46:03 +0200 (CEST)
From: markush@acc.umu.se
Sender: mac@romy.ascape.com
Reply-To:
To: FreeBSD-gnats-submit@freebsd.org
Subject: Reading from stdin using linux-jdk1.2.2 under Linux emulation fails
X-Send-Pr-Version: 3.2

>Number:         18940
>Category:       i386
>Synopsis:       Reading from stdin using linux-jdk-1.2.2 under Linux emulation fails
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 01 05:50:00 PDT 2000
>Closed-Date:    Mon Oct 8 05:50:08 PDT 2001
>Last-Modified:  Mon Oct 08 05:50:28 PDT 2001
>Originator:     Markus Holmberg
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
n/a
>Environment:

	FreeBSD 4.0-STABLE (also tested on 3.4-STABLE)
	linux-jdk-1.2.2 (port is submitted as pr, but not processed)

>Description:

Several people on the freebsd-java mailing list have reported problems with
reading from standard input in linux-jdk-1.2.2. The problem is that input does
not seem to be "sent" to the java process running under Linux emulation, which
means that the Java program blocks in the i/o read operation (even though there
is input to be read).

>How-To-Repeat:

Using the Java-snippet below, a dot character should be printed on a line for itself
for each character that has been read in from stdin. This will not happen on a broken
system (a few dots might be output, but after that it's blocked).

(Read.java)
-8<------------------------------------------
import java.io.*;

public class Read {
    public static void main(String[] args) {
        try {
            while (System.in.read() != -1) {
                System.out.println(".");
            }
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}
-8<------------------------------------------

>Fix:

There was a patch (for 3.x) posted to the freebsd-java mailing list some months
ago, but it is unclear why the patch works and if it causes any undesired side
effects (since it removes a lot of code). 

Marcel Moolenaar (Linux emulation maintainer) has seen the patch but is not sure
if it's safe to remove the code that the patch wants to remove.

John Rochesters original patch for 3.x (only the patch for linux_file.c is relevant
in the posting):
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=22905+0+archive/2000/freebsd-java/20000220.freebsd-java

Here's the same patch adapted for 4.0-STABLE (May 29th):

--- linux_file.c.orig	Mon May 29 13:21:09 2000
+++ linux_file.c	Mon May 29 13:26:05 2000
@@ -199,12 +199,6 @@
     } */ fcntl_args; 
     struct linux_flock linux_flock;
     struct flock *bsd_flock;
-    struct filedesc *fdp;
-    struct file *fp;
-    struct vnode *vp;
-    long pgid;
-    struct pgrp *pgrp;
-    struct tty *tp;
     caddr_t sg;
     dev_t dev;
 
@@ -289,47 +283,9 @@
 
     case LINUX_F_SETOWN:
     case LINUX_F_GETOWN:
-	/*
-	 * We need to route around the normal fcntl() for these calls,
-	 * since it uses TIOC{G,S}PGRP, which is too restrictive for
-	 * Linux F_{G,S}ETOWN semantics. For sockets, this problem
-	 * does not exist.
-	 */
-	fdp = p->p_fd;
-	if ((u_int)args->fd >= fdp->fd_nfiles ||
-		(fp = fdp->fd_ofiles[args->fd]) == NULL)
-	    return EBADF;
-	if (fp->f_type == DTYPE_SOCKET) {
-	    fcntl_args.cmd = args->cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
-    	    fcntl_args.arg = args->arg;
-	    return fcntl(p, &fcntl_args); 
-	}
-	vp = (struct vnode *)fp->f_data;
-	dev = vn_todev(vp);
-	if (dev == NODEV)
-	    return EINVAL;
-	if (!(devsw(dev)->d_flags & D_TTY))
-	    return EINVAL;
-	tp = dev->si_tty;
-	if (!tp)
-	    return EINVAL;
-	if (args->cmd == LINUX_F_GETOWN) {
-	    p->p_retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
-	    return 0;
-	}
-	if ((long)args->arg <= 0) {
-	    pgid = -(long)args->arg;
-	} else {
-	    struct proc *p1 = pfind((long)args->arg);
-	    if (p1 == 0)
-		return (ESRCH);
-	    pgid = (long)p1->p_pgrp->pg_id;
-	}
-	pgrp = pgfind(pgid);
-	if (pgrp == NULL || pgrp->pg_session != p->p_session)
-	    return EPERM;
-	tp->t_pgrp = pgrp;
-	return 0;
+       fcntl_args.cmd = args->cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
+       fcntl_args.arg = args->arg;
+       return fcntl(p, &fcntl_args); 
     }
     return EINVAL;
 }

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: mike 
State-Changed-When: Sat Jul 21 20:03:52 PDT 2001 
State-Changed-Why:  

Does this problem still occur in newer versions of FreeBSD, 
such as 4.3-RELEASE? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18940 
State-Changed-From-To: feedback->closed 
State-Changed-By: sobomax 
State-Changed-When: Mon Oct 8 05:50:08 PDT 2001 
State-Changed-Why:  
Feedback timeout. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18940 
>Unformatted:
