X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=5c1e16ab6ed49efb9c05980ea489955c04b7a608;hb=bc0f8771f23dc3952bf4b06301dc842ba625a0f2;hp=f7d538aaacf87496367661ba3822bc2f44cb6070;hpb=e99e38bbdcca3fe5956823bdb3d38544ccf93221;p=elogind.git diff --git a/src/util.c b/src/util.c index f7d538aaa..5c1e16ab6 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; }