ryantimwilson / rpms / systemd

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