[systemd-commits] src/execute.c src/main.c src/util.c src/util.h

Lennart Poettering lennart at kemper.freedesktop.org
Mon May 17 18:40:26 PDT 2010


 src/execute.c |    6 ++++--
 src/main.c    |    2 +-
 src/util.c    |   13 ++++++++++---
 src/util.h    |    2 +-
 4 files changed, 16 insertions(+), 7 deletions(-)

New commits:
commit 21de3988abfdf69e7c1e2d00a087e2d8b18ad758
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 18 03:40:19 2010 +0200

    main: ignore EPERM in TIOCSTTY when opening terminal for crash shell

diff --git a/src/execute.c b/src/execute.c
index 12f5145..1076834 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 e2d2ab5..311ece6 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 f7d538a..5c1e16a 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 a77a952..84dd2bc 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);


More information about the systemd-commits mailing list