From bjb@alpha.intern.dd.dk  Wed Nov 29 02:54:38 2000
Return-Path: <bjb@alpha.intern.dd.dk>
Received: from alpha.intern.dd.dk (client.dk.damgaard.com [213.237.136.126])
	by hub.freebsd.org (Postfix) with ESMTP id 50A5337B400
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 29 Nov 2000 02:54:37 -0800 (PST)
Received: (from bjb@localhost)
	by alpha.intern.dd.dk (8.11.1/8.11.1) id eATAqjW13768;
	Wed, 29 Nov 2000 11:52:45 +0100 (CET)
	(envelope-from bjb)
Message-Id: <200011291052.eATAqjW13768@alpha.intern.dd.dk>
Date: Wed, 29 Nov 2000 11:52:45 +0100 (CET)
From: bbl@dk.damgaard.com
Sender: bjb@alpha.intern.dd.dk
Reply-To: bbl@dk.damgaard.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: read hangs in linux emulation 
X-Send-Pr-Version: 3.2

>Number:         23173
>Category:       kern
>Synopsis:       read hangs in linux emulation
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    marcel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 29 03:00:01 PST 2000
>Closed-Date:    Sat Jun 28 12:33:39 PDT 2003
>Last-Modified:  Sat Jun 28 12:33:39 PDT 2003
>Originator:     Bjarne Blichfeldt
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
>Environment:

	

>Description:

The following testprogram wil demonstrate an error in linux compatibility
between linux and freebsd, both on intelplatform.
The program is compiled on an intel linux Slackware 7.0 with gcc 2.95.2 and
the binary is then copied to FreeBSD 4.2-stable.
The problem is seen both on 4.1 and 4.2

The correct behaviour on linux, is to read a charcter on stdin, provided
there is one, othervise return 0.

On FreeBSD, the read will just hang until a key is pressed. 
After a key is pressed, the character is returned after aprox. 20 seconds.


If 
   st_tbuf.c_cc[VTIME] = 0;  

is changed to 
   st_tbuf.c_cc[VTIME] = 100; 

the read is supposed to wait max. 10 seconds, whereafter 0 is returned.

On FreeBSD, read will hang indefinitely, until a key is pressed. 
After a key is pressed, read will return after aprox. 20 seconds.
	

>How-To-Repeat:

#include <stdio.h>
#include <termios.h>
#include <unistd.h>


struct termios st_tbuf, old_st;

main () {
   char buf [256];
   int  ret;


  ret = tcgetattr(0, &old_st);

  st_tbuf.c_lflag &= ~(ICANON | ECHO);
  st_tbuf.c_cc[VMIN]  = 0;
  st_tbuf.c_cc[VTIME] = 0;
  ret = tcsetattr(0, TCSANOW, &st_tbuf);

  ret = read (0, (char *)buf, 1);

  tcsetattr(0, TCSANOW, &old_st);

  if (ret > 0)   printf ("inp = %c\n", buf[0]);
  else           printf ("Zip\n");
}


>Fix:

	


>Release-Note:
>Audit-Trail:

From: Boris Nikolaus <bn@dali.tellique.de>
To: freebsd-gnats-submit@FreeBSD.org
Cc: bbl@dk.damgaard.com, marcel@FreeBSD.org
Subject: Re: kern/23173: read hangs in linux emulation
Date: Sun, 29 Apr 2001 04:36:05 +0200

 Hi Bjarne.
 
 There's a bug in the termios struct conversion, which replaces
 0 in VMIN and VTIME by 255 (as it substitutes all _POSIX_VDISABLE from
 Linux (0) by _POSIX_VDISABLE from FreeBSD (255) in termios.c_cc[]).
 
 The following patch for /usr/src/sys/compat/linux/linux_ioctl.c will fix
 this problem:
 
 *** linux_ioctl.c.orig  Sat Apr 28 03:08:21 2001
 --- linux_ioctl.c       Sun Apr 29 04:22:10 2001
 ***************
 *** 321,327 ****
         lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT];
   
         for (i=0; i<LINUX_NCCS; i++) {
 !               if (lios->c_cc[i] == _POSIX_VDISABLE)
                         lios->c_cc[i] = LINUX_POSIX_VDISABLE;
         }
         lios->c_line = 0;
 --- 321,328 ----
         lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT];
   
         for (i=0; i<LINUX_NCCS; i++) {
 !               if (i != LINUX_VMIN && i != LINUX_VTIME &&
 !                   lios->c_cc[i] == _POSIX_VDISABLE)
                         lios->c_cc[i] = LINUX_POSIX_VDISABLE;
         }
         lios->c_line = 0;
 ***************
 *** 454,460 ****
         bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT];
   
         for (i=0; i<NCCS; i++) {
 !               if (bios->c_cc[i] == LINUX_POSIX_VDISABLE)
                         bios->c_cc[i] = _POSIX_VDISABLE;
         }
   
 --- 455,462 ----
         bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT];
   
         for (i=0; i<NCCS; i++) {
 !               if (i != VMIN && i != VTIME &&
 !                   bios->c_cc[i] == LINUX_POSIX_VDISABLE)
                         bios->c_cc[i] = _POSIX_VDISABLE;
         }
 
 Greetings,
 Boris Nikolaus
 
 P.S.: Your test program is missing a "st_tbuf = old_st;" after the tcgetattr.

From: Joseph Holland King <gte743n@cad.gatech.edu>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/23173: read hangs in linux emulation
Date: Wed, 19 Jun 2002 16:31:53 -0400

 a patch has been given, can this pr be closed?
 
 -- 
 Holland King        
 gte743n@cad.gatech.edu

From: Joseph Holland King <gte743n@cad.gatech.edu>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/23173: read hangs in linux emulation
Date: Mon, 18 Nov 2002 23:48:10 -0500

 this bug has had a patch for close to 9 months now, and no other
 traffic. any reason it has not been closed?
 
 -- 
 Holland King        
 gte743n@cad.gatech.edu
State-Changed-From-To: open->feedback 
State-Changed-By: dougb 
State-Changed-When: Thu Jan 23 02:17:45 PST 2003 
State-Changed-Why:  

Is this still a problem with more modern systems? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23173 

From: Philipp Mergenthaler <philipp.mergenthaler@stud.uni-karlsruhe.de>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/23173: read hangs in linux emulation
Date: Sun, 11 May 2003 09:47:21 +0200

 I can confirm that this bug still exists in -current as of 2003-05-11
 and that the patch by Boris Nikolaus fixes it.
 
 It doesn't apply cleanly to -current anymore, though.  Below is an
 updated version.
 
 Bye, Philipp
 
 
 Index: linux_ioctl.c
 ===================================================================
 RCS file: /ncvs/src/sys/compat/linux/linux_ioctl.c,v
 retrieving revision 1.107
 diff -u -r1.107 linux_ioctl.c
 --- linux_ioctl.c	24 Apr 2003 23:36:35 -0000	1.107
 +++ linux_ioctl.c	11 May 2003 07:06:50 -0000
 @@ -345,7 +345,8 @@
  	lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT];
  
  	for (i=0; i<LINUX_NCCS; i++) {
 -		if (lios->c_cc[i] == _POSIX_VDISABLE)
 +		if (i != LINUX_VMIN && i != LINUX_VTIME &&
 +		    lios->c_cc[i] == _POSIX_VDISABLE)
  			lios->c_cc[i] = LINUX_POSIX_VDISABLE;
  	}
  	lios->c_line = 0;
 @@ -484,7 +485,8 @@
  	bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT];
  
  	for (i=0; i<NCCS; i++) {
 -		if (bios->c_cc[i] == LINUX_POSIX_VDISABLE)
 +		if (i != VMIN && i != VTIME &&
 +		    bios->c_cc[i] == LINUX_POSIX_VDISABLE)
  			bios->c_cc[i] = _POSIX_VDISABLE;
  	}
  
State-Changed-From-To: feedback->open 
State-Changed-By: maxim 
State-Changed-When: Sat Jun 28 11:31:38 PDT 2003 
State-Changed-Why:  
Marcel, could your please take a look at the patch in the PR? 


Responsible-Changed-From-To: freebsd-bugs->marcel 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Sat Jun 28 11:31:38 PDT 2003 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23173 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Sat Jun 28 12:32:44 PDT 2003 
State-Changed-Why:  
Patch committed to -current. MFC in 5 days. Sorry for the delay. 


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