anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0271-terminal-util-when-resetting-terminals-don-t-wait-fo.patch

803fb7
From 067fbebee46a376c639c9369dcaf80004047414d Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Mon, 3 Aug 2015 19:04:08 +0200
803fb7
Subject: [PATCH] terminal-util: when resetting terminals, don't wait for
803fb7
 carrier
803fb7
803fb7
In case of non-CLOCAL lines (i.e. those with carrier detect configured)
803fb7
we shouldnt wait for a carrier if all we try to do is reset the TTY.
803fb7
Hence, whenever we open such a TTY pass O_NONBLOCK.
803fb7
803fb7
Note that we continue to open ttys we intend to write to without
803fb7
O_ONBLOCK, we only add it in cases we invoke ioctl()s or other terminal
803fb7
operations without reading or writing to the device.
803fb7
803fb7
Fixes #835.
803fb7
803fb7
Cherry-picked from: 0a8b555ceb07ce916b9bd48782d1eb69a12f0f2e
803fb7
Resolves: #1266745
803fb7
---
803fb7
 src/shared/util.c | 14 +++++++++-----
803fb7
 1 file changed, 9 insertions(+), 5 deletions(-)
803fb7
803fb7
diff --git a/src/shared/util.c b/src/shared/util.c
803fb7
index 778c2b0e0..50925888d 100644
803fb7
--- a/src/shared/util.c
803fb7
+++ b/src/shared/util.c
803fb7
@@ -1713,7 +1713,7 @@ bool fstype_is_network(const char *fstype) {
803fb7
 int chvt(int vt) {
803fb7
         _cleanup_close_ int fd;
803fb7
 
803fb7
-        fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
803fb7
+        fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
803fb7
         if (fd < 0)
803fb7
                 return -errno;
803fb7
 
803fb7
@@ -1953,7 +1953,11 @@ finish:
803fb7
 int reset_terminal(const char *name) {
803fb7
         _cleanup_close_ int fd = -1;
803fb7
 
803fb7
-        fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
803fb7
+        /* We open the terminal with O_NONBLOCK here, to ensure we
803fb7
+         * don't block on carrier if this is a terminal with carrier
803fb7
+         * configured. */
803fb7
+
803fb7
+        fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
803fb7
         if (fd < 0)
803fb7
                 return fd;
803fb7
 
803fb7
@@ -2204,7 +2208,7 @@ int release_terminal(void) {
803fb7
         struct sigaction sa_old;
803fb7
         int r = 0;
803fb7
 
803fb7
-        fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC);
803fb7
+        fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
803fb7
         if (fd < 0)
803fb7
                 return -errno;
803fb7
 
803fb7
@@ -4405,7 +4409,7 @@ int terminal_vhangup_fd(int fd) {
803fb7
 int terminal_vhangup(const char *name) {
803fb7
         _cleanup_close_ int fd;
803fb7
 
803fb7
-        fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
803fb7
+        fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
803fb7
         if (fd < 0)
803fb7
                 return fd;
803fb7
 
803fb7
@@ -4452,7 +4456,7 @@ int vt_disallocate(const char *name) {
803fb7
                 return -EINVAL;
803fb7
 
803fb7
         /* Try to deallocate */
803fb7
-        fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
803fb7
+        fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
803fb7
         if (fd < 0)
803fb7
                 return fd;
803fb7