tty: implement FLUSH on tcsetattr correctly?

This commit is contained in:
K. Lange 2023-11-02 16:59:57 +09:00
parent 2f27cce0cd
commit 938bbf51eb
3 changed files with 13 additions and 1 deletions

View File

@ -31,4 +31,5 @@ void ring_buffer_interrupt(ring_buffer_t * ring_buffer);
void ring_buffer_alert_waiters(ring_buffer_t * ring_buffer);
void ring_buffer_select_wait(ring_buffer_t * ring_buffer, void * process);
void ring_buffer_eof(ring_buffer_t * ring_buffer);
void ring_buffer_discard(ring_buffer_t * ring_buffer);

View File

@ -86,6 +86,12 @@ void ring_buffer_select_wait(ring_buffer_t * ring_buffer, void * process) {
list_insert(((process_t *)process)->node_waits, ring_buffer);
}
void ring_buffer_discard(ring_buffer_t * ring_buffer) {
spin_lock(ring_buffer->lock);
ring_buffer->read_ptr = ring_buffer->write_ptr;
spin_unlock(ring_buffer->lock);
}
size_t ring_buffer_read(ring_buffer_t * ring_buffer, size_t size, uint8_t * buffer) {
size_t collected = 0;
while (collected == 0) {

View File

@ -322,13 +322,18 @@ int pty_ioctl(pty_t * pty, unsigned long request, void * argp) {
return 0;
case TCSETS:
case TCSETSW:
case TCSETSF:
if (!argp) return -EINVAL;
validate(argp);
/* TODO wait on output for SETSW */
if (!(((struct termios *)argp)->c_lflag & ICANON) && (pty->tios.c_lflag & ICANON)) {
/* Switch out of canonical mode, the dump the input buffer */
dump_input_buffer(pty);
}
goto tcset_common;
case TCSETSF:
clear_input_buffer(pty);
ring_buffer_discard(pty->in);
tcset_common:
memcpy(&pty->tios, argp, sizeof(struct termios));
return 0;
default: