]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/execute: determine if ExecContext may fiddle with /dev/console
authorMichal Schmidt <mschmidt@redhat.com>
Thu, 28 Feb 2013 00:36:55 +0000 (01:36 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 28 Feb 2013 01:23:57 +0000 (02:23 +0100)
There is some guesswork, but it should work satisfactorily for the
purpose of knowing when to suppress printing of status messages.

src/core/execute.c
src/core/execute.h

index 1f6263519607eb8d3e33dad7ad8fd22afc2a9a12..92cf1746417e5ab14fd517142f54b8dee3b1d843 100644 (file)
@@ -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;
 
index 2bcd2e1e6cf7e584111d73f22826743dc719904e..001eb0e7cc33aed9a4c2860bb012f52fc8f3ae19 100644 (file)
@@ -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);