tree-wide: acquire /dev/console lock around any attempts to reset TTY

This commit is contained in:
Lennart Poettering
2024-07-19 11:44:04 +02:00
parent dffbe1d152
commit 2cd19499a0
6 changed files with 22 additions and 3 deletions
+14
View File
@@ -599,6 +599,10 @@ void reset_dev_console_fd(int fd, bool switch_to_text) {
assert(fd >= 0);
_cleanup_close_ int lock_fd = lock_dev_console();
if (lock_fd < 0)
log_debug_errno(lock_fd, "Failed to lock /dev/console, ignoring: %m");
r = terminal_reset_ioctl(fd, switch_to_text);
if (r < 0)
log_warning_errno(r, "Failed to reset /dev/console, ignoring: %m");
@@ -1592,6 +1596,16 @@ int terminal_reset_defensive(int fd, bool switch_to_text) {
return r;
}
int terminal_reset_defensive_locked(int fd, bool switch_to_text) {
assert(fd >= 0);
_cleanup_close_ int lock_fd = lock_dev_console();
if (lock_fd < 0)
log_debug_errno(lock_fd, "Failed to acquire lock for /dev/console, ignoring: %m");
return terminal_reset_defensive(fd, switch_to_text);
}
void termios_disable_echo(struct termios *termios) {
assert(termios);
+1
View File
@@ -30,6 +30,7 @@
bool isatty_safe(int fd);
int terminal_reset_defensive(int fd, bool switch_to_text);
int terminal_reset_defensive_locked(int fd, bool switch_to_text);
int terminal_set_cursor_position(int fd, unsigned row, unsigned column);