4-stable termios diff behaviour lc/lc_r
Julian Elischer
julian at vicor.com
Tue Aug 31 11:36:11 PDT 2004
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 <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
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;
}
More information about the freebsd-stable
mailing list