diff options
-rw-r--r-- | src/core/execute.c | 31 | ||||
-rw-r--r-- | src/core/execute.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index 1f62635196..92cf174641 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1718,6 +1718,37 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { return 0; } +static bool tty_may_match_dev_console(const char *tty) { + char *active = NULL, *console; + bool b; + + if (startswith(tty, "/dev/")) + tty += 5; + + /* trivial identity? */ + if (streq(tty, "console")) + return true; + + console = resolve_dev_console(&active); + /* if we could not resolve, assume it may */ + if (!console) + return true; + + /* "tty0" means the active VC, so it may be the same sometimes */ + b = streq(console, tty) || (streq(console, "tty0") && tty_is_vc(tty)); + free(active); + + return b; +} + +bool exec_context_may_touch_console(ExecContext *ec) { + return (ec->tty_reset || ec->tty_vhangup || ec->tty_vt_disallocate || + is_terminal_input(ec->std_input) || + is_terminal_output(ec->std_output) || + is_terminal_output(ec->std_error)) && + tty_may_match_dev_console(tty_path(ec)); +} + static void strv_fprintf(FILE *f, char **l) { char **g; diff --git a/src/core/execute.h b/src/core/execute.h index 2bcd2e1e6c..001eb0e7cc 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -198,6 +198,8 @@ void exec_context_tty_reset(const ExecContext *context); int exec_context_load_environment(const ExecContext *c, char ***l); +bool exec_context_may_touch_console(ExecContext *c); + void exec_status_start(ExecStatus *s, pid_t pid); void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status); void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix); |