summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2013-02-28 01:36:55 +0100
committerMichal Schmidt <mschmidt@redhat.com>2013-02-28 02:23:57 +0100
commit6ac8fdc9554a40024827ad9f64d02b4d8d2ab8ba (patch)
tree4054dc5bee1dcc5260919b822fcf60e9065705a6
parent3a1286b66883ef2cf577b29364e4b5fd43a295c8 (diff)
downloadsystemd-6ac8fdc9554a40024827ad9f64d02b4d8d2ab8ba.tar.gz
core/execute: determine if ExecContext may fiddle with /dev/console
There is some guesswork, but it should work satisfactorily for the purpose of knowing when to suppress printing of status messages.
-rw-r--r--src/core/execute.c31
-rw-r--r--src/core/execute.h2
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);