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

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