summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-18 03:40:19 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-18 03:40:19 +0200
commit21de3988abfdf69e7c1e2d00a087e2d8b18ad758 (patch)
tree2f482b4c57d25b3a8b877f9b23e495bd19e3870c /src/util.c
parent5b2a09037232980ad42ba3611cf194078ae5e546 (diff)
main: ignore EPERM in TIOCSTTY when opening terminal for crash shell
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c13
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;
}