Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Confirming X02zlevi test failures



Bart wrote:
> It shouldn't be hard to write a test case though it requires a person to
> drive it.  Open /dev/tty, set icanon, sleep while the user enters some
> typeahead, set -icanon and then see if you can read the typeahead.  Then
> try the icanon flop in the opposite order.  It might even be possible to
> do it with a script and stty rather than a C program, although it might
> also require that all the frobbing and reading use the same (not a dup of
> the same) file descriptor.

I'd have thought simply checking that zsh doesn't lose typeahead would
be sufficient but since I already had a test program that was not far
from what you describe, I've modified and attached it. Is opening
/dev/tty instead of fd 0 necessary? You'll need to manually swap the
icanons. It's probably best to try to get an EOF in before the 3 seconds
have elapsed. Let me know if you see a problem on any system you use.

Oliver

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

void
gettyinfo(struct termios *ti)
{
    if (tcgetattr(0, ti) == -1)
	fprintf(stderr, "bad tcgets: %d", errno);
}

void
settyinfo(struct termios *ti)
{
    while (tcsetattr(0, TCSADRAIN, ti) == -1 && errno == EINTR)
	    ;
}

int main() {
    struct termios ti;
    char cptr[10];
    ssize_t size;

    gettyinfo(&ti);
    ti.c_lflag &= ~ICANON;
    settyinfo(&ti);
    sleep(3);
    ti.c_lflag |= ICANON;
    settyinfo(&ti);

    size = read(0, cptr, 9);
    if (size > 0) {
	cptr[size] = '\0';
	printf("\nGot: %s\n", cptr);
    }
}



Messages sorted by: Reverse Date, Date, Thread, Author