summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/execute.c6
-rw-r--r--src/main.c2
-rw-r--r--src/util.c13
-rw-r--r--src/util.h2
4 files changed, 16 insertions, 7 deletions
diff --git a/src/execute.c b/src/execute.c
index 12f514504c..1076834702 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -274,7 +274,8 @@ static int setup_input(const ExecContext *context, int socket_fd) {
if ((fd = acquire_terminal(
tty_path(context),
i == EXEC_INPUT_TTY_FAIL,
- i == EXEC_INPUT_TTY_FORCE)) < 0)
+ i == EXEC_INPUT_TTY_FORCE,
+ false)) < 0)
return fd;
if (fd != STDIN_FILENO) {
@@ -429,7 +430,8 @@ static int setup_confirm_stdio(const ExecContext *context,
if ((fd = acquire_terminal(
tty_path(context),
context->std_input == EXEC_INPUT_TTY_FAIL,
- context->std_input == EXEC_INPUT_TTY_FORCE)) < 0) {
+ context->std_input == EXEC_INPUT_TTY_FORCE,
+ false)) < 0) {
r = EXIT_STDIN;
goto fail;
}
diff --git a/src/main.c b/src/main.c
index e2d2ab5e64..311ece6b57 100644
--- a/src/main.c
+++ b/src/main.c
@@ -138,7 +138,7 @@ _noreturn static void crash(int sig) {
else if (pid == 0) {
int fd, r;
- if ((fd = acquire_terminal("/dev/console", false, true)) < 0)
+ if ((fd = acquire_terminal("/dev/console", false, true, true)) < 0)
log_error("Failed to acquire terminal: %s", strerror(-fd));
else if ((r = make_stdio(fd)) < 0)
log_error("Failed to duplicate terminal fd: %s", strerror(-r));
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;
}
diff --git a/src/util.h b/src/util.h
index a77a952ed6..84dd2bc8d1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -218,7 +218,7 @@ int ask(char *ret, const char *replies, const char *text, ...);
int reset_terminal(int fd);
int open_terminal(const char *name, int mode);
-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 release_terminal(void);
int flush_fd(int fd);