mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-27 10:25:06 +03:00
main: ignore EPERM in TIOCSTTY when opening terminal for crash shell
This commit is contained in:
parent
5b2a090372
commit
21de3988ab
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
13
src/util.c
13
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user