From owner-freebsd-stable@FreeBSD.ORG Tue Aug 31 18:36:11 2004 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5682216A4CE; Tue, 31 Aug 2004 18:36:11 +0000 (GMT) Received: from mail.vicor-nb.com (bigwoop.vicor-nb.com [208.206.78.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0AD1D43D58; Tue, 31 Aug 2004 18:36:11 +0000 (GMT) (envelope-from julian@vicor.com) Received: from vicor.com (julian.vicor-nb.com [208.206.78.97]) by mail.vicor-nb.com (Postfix) with ESMTP id E6B9A7A403; Tue, 31 Aug 2004 11:36:10 -0700 (PDT) Message-ID: <4134C51A.8010207@vicor.com> Date: Tue, 31 Aug 2004 11:36:10 -0700 From: Julian Elischer Organization: VICOR User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3.1) Gecko/20030516 X-Accept-Language: en, hu MIME-Version: 1.0 To: freebsd-stable@freebsd.org, threads@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: 4-stable termios diff behaviour lc/lc_r X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2004 18:36:11 -0000 this should have been sent to -threads.. -------------------------------------------- >Hi list, >> >> I think I've found a possible bug in 4-stable, though I'm not that >> kind of an expert so I'll leave that decision up to you. >> >> Attached is a little test program that opens /dev/cuaa0 and tries to >> read a couple bytes. >> >> When compiled using "gcc vtime.c -o vtime" there's no problem. For >> example, when you run vtime without anything attached to cuaa0, >> it'll wait about 2 seconds and timeout, since VMIN=0 and VTIME=20. >> >> When compiled using "gcc -pthread vtime.c -o vtime" however, the >> read function returns immediately, which as far as I can understand, >> is not what it's supposed to do. >> >> Does anyone know if this intended or not, or how I can get the right >> behaviour in a threaded program? I've done some more testing. It appears that when linked with lc_r, VTIME is completely ignored. As explained in termios(4), when VMIN>0, the read call will wait indefinitely for the first byte and then use VTIME as an interbyte timer. When using lc_r however, it'll return immediately after the first couple bytes read, even if that's less than VMIN. The case where VTIME==0 works as it should both with lc and lc_r. I dont have access to a box with -current, so I can't say if the same applies to it. I hope somebody understands this better or could at least give me a few pointers as to where to look in the source code. Thanks, tijl -------------- next part -------------- #include #include #include #include #include extern int errno; int main(void) { int fd, len; struct termios termset; uint8_t data[256]; fd = open("/dev/cuaa0", O_RDWR | O_FSYNC); printf("%d %d\n", fd, errno); if (fd != -1) { tcgetattr(fd, &termset); cfmakeraw(&termset); cfsetspeed(&termset, B9600); termset.c_cc[VMIN] = 1; termset.c_cc[VTIME] = 0; tcsetattr(fd, TCSANOW, &termset); len = read(fd, (void *) data, 3); printf("%d\n", len); close(fd); } return 0; }