Skip to content

Commit

Permalink
terminal-util: when resetting terminals, don't wait for carrier
Browse files Browse the repository at this point in the history
In case of non-CLOCAL lines (i.e. those with carrier detect configured)
we shouldnt wait for a carrier if all we try to do is reset the TTY.
Hence, whenever we open such a TTY pass O_NONBLOCK.

Note that we continue to open ttys we intend to write to without
O_ONBLOCK, we only add it in cases we invoke ioctl()s or other terminal
operations without reading or writing to the device.

Fixes #835.

Cherry-picked from: 0a8b555
Resolves: #1266745
  • Loading branch information
poettering authored and lnykryn committed Jan 25, 2016
1 parent 1b8d3a9 commit 067fbeb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/shared/util.c
Expand Up @@ -1713,7 +1713,7 @@ bool fstype_is_network(const char *fstype) {
int chvt(int vt) {
_cleanup_close_ int fd;

fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return -errno;

Expand Down Expand Up @@ -1953,7 +1953,11 @@ int reset_terminal_fd(int fd, bool switch_to_text) {
int reset_terminal(const char *name) {
_cleanup_close_ int fd = -1;

fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
/* We open the terminal with O_NONBLOCK here, to ensure we
* don't block on carrier if this is a terminal with carrier
* configured. */

fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return fd;

Expand Down Expand Up @@ -2204,7 +2208,7 @@ int release_terminal(void) {
struct sigaction sa_old;
int r = 0;

fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC);
fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return -errno;

Expand Down Expand Up @@ -4405,7 +4409,7 @@ int terminal_vhangup_fd(int fd) {
int terminal_vhangup(const char *name) {
_cleanup_close_ int fd;

fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return fd;

Expand Down Expand Up @@ -4452,7 +4456,7 @@ int vt_disallocate(const char *name) {
return -EINVAL;

/* Try to deallocate */
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return fd;

Expand Down

0 comments on commit 067fbeb

Please sign in to comment.