diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/util.c b/src/util.c index f7d538aaac..5c1e16ab6e 100644 --- a/src/util.c +++ b/src/util.c @@ -1598,7 +1598,7 @@ int flush_fd(int fd) { } } -int acquire_terminal(const char *name, bool fail, bool force) { +int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm) { int fd = -1, notify = -1, r, wd = -1; assert(name); @@ -1640,8 +1640,15 @@ int acquire_terminal(const char *name, bool fail, bool force) { return -errno; /* First, try to get the tty */ - if ((r = ioctl(fd, TIOCSCTTY, force)) < 0 && - (force || fail || errno != EPERM)) { + r = ioctl(fd, TIOCSCTTY, force); + + /* Sometimes it makes sense to ignore TIOCSCTTY + * returning EPERM, i.e. when very likely we already + * are have this controlling terminal. */ + if (r < 0 && errno == EPERM && ignore_tiocstty_eperm) + r = 0; + + if (r < 0 && (force || fail || errno != EPERM)) { r = -errno; goto fail; } |