]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
terminal: Add API for flushing input buffer
authorRay Strode <rstrode@redhat.com>
Thu, 17 Nov 2022 15:01:34 +0000 (10:01 -0500)
committerRay Strode <rstrode@redhat.com>
Tue, 29 Nov 2022 14:22:06 +0000 (09:22 -0500)
In the future we're going to start reading keyboard input from
/dev/input instead of the tty. When that happens, input will
still be sent by the kernel to the tty.

This input would eventually back up and overflow.

To address that problem before it exists, this commit adds a new
API, ply_terminal_flush_input, that will drain the input buffer
on demand.

We can later use that API to keep the tty from backing up.

src/libply-splash-core/ply-terminal.c
src/libply-splash-core/ply-terminal.h

index 686b4f4f7225b93b83ddd807c0297c32201c4210..51771244e63c9e41c8ed38f0bd7204a7bc55e801 100644 (file)
@@ -1101,3 +1101,12 @@ ply_terminal_stop_watching_for_input (ply_terminal_t              *terminal,
         }
 }
 
+void
+ply_terminal_flush_input (ply_terminal_t *terminal)
+{
+        if (!terminal->is_open)
+                return;
+
+        if (tcflush (terminal->fd, TCIFLUSH) < 0)
+                ply_trace ("could not flush input buffer of terminal %s: %m", terminal->name);
+}
index c701f2caa3d91cee5002143a0028f35069f63042..a2685f5c63061ad56ab1e8552a082bb94bef47c2 100644 (file)
@@ -116,6 +116,8 @@ void ply_terminal_stop_watching_for_input (ply_terminal_t              *terminal
                                            ply_terminal_input_handler_t input_handler,
                                            void                        *user_data);
 
+void ply_terminal_flush_input (ply_terminal_t *terminal);
+
 #endif
 
 #endif /* PLY_TERMINAL_H */