Merge pull request #32369 from DaanDeMeyer/serial
terminal-util: Enable line wrapping in reset_terminal_fd()
This commit is contained in:
+4
-1
@@ -167,7 +167,10 @@ int fd_nonblock(int fd, bool nonblock) {
|
||||
if (nflags == flags)
|
||||
return 0;
|
||||
|
||||
return RET_NERRNO(fcntl(fd, F_SETFL, nflags));
|
||||
if (fcntl(fd, F_SETFL, nflags) < 0)
|
||||
return -errno;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int stdio_disable_nonblock(void) {
|
||||
|
||||
@@ -306,7 +306,29 @@ int reset_terminal_fd(int fd, bool switch_to_text) {
|
||||
termios.c_cc[VMIN] = 1;
|
||||
|
||||
r = RET_NERRNO(tcsetattr(fd, TCSANOW, &termios));
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to set terminal parameters: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!terminal_is_dumb()) {
|
||||
r = fd_nonblock(fd, true);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to set terminal to non-blocking mode: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Enable line wrapping. */
|
||||
(void) loop_write_full(fd, "\033[?7h", SIZE_MAX, 50 * USEC_PER_MSEC);
|
||||
|
||||
if (r > 0) {
|
||||
r = fd_nonblock(fd, false);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to set terminal back to blocking mode: %m");
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
}
|
||||
finish:
|
||||
/* Just in case, flush all crap out */
|
||||
(void) tcflush(fd, TCIOFLUSH);
|
||||
|
||||
Reference in New Issue
Block a user