valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

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

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