run: run pty forwarder at higher event priority than the bus
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Dec 2017 17:31:32 +0000 (18:31 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Dec 2017 17:33:24 +0000 (18:33 +0100)
We want any tty I/O to happen before we look at service messages, hence
let's set priorities on them, and give tty I/O a higher priority.

src/run/run.c
src/shared/ptyfwd.c
src/shared/ptyfwd.h

index db833c2..bd9a6b2 100644 (file)
@@ -1085,6 +1085,9 @@ static int start_transient_service(
                                 return log_error_errno(r, "Failed to create PTY forwarder: %m");
 
                         pty_forward_set_handler(c.forward, pty_forward_handler, &c);
+
+                        /* Make sure to process any TTY events before we process bus events */
+                        (void) pty_forward_set_priority(c.forward, SD_EVENT_PRIORITY_IMPORTANT);
                 }
 
                 path = unit_dbus_path_from_name(service);
@@ -1100,7 +1103,7 @@ static int start_transient_service(
                 if (r < 0)
                         return log_error_errno(r, "Failed to add properties changed signal.");
 
-                r = sd_bus_attach_event(bus, c.event, 0);
+                r = sd_bus_attach_event(bus, c.event, SD_EVENT_PRIORITY_NORMAL);
                 if (r < 0)
                         return log_error_errno(r, "Failed to attach bus to event loop.");
 
index 3cc2e18..94a4dd5 100644 (file)
@@ -573,3 +573,26 @@ bool pty_forward_drain(PTYForward *f) {
         f->drain = true;
         return drained(f);
 }
+
+int pty_forward_set_priority(PTYForward *f, int64_t priority) {
+        int r;
+        assert(f);
+
+        r = sd_event_source_set_priority(f->stdin_event_source, priority);
+        if (r < 0)
+                return r;
+
+        r = sd_event_source_set_priority(f->stdout_event_source, priority);
+        if (r < 0)
+                return r;
+
+        r = sd_event_source_set_priority(f->master_event_source, priority);
+        if (r < 0)
+                return r;
+
+        r = sd_event_source_set_priority(f->sigwinch_event_source, priority);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
index ee04fca..6a0e0c6 100644 (file)
@@ -54,4 +54,6 @@ void pty_forward_set_handler(PTYForward *f, PTYForwardHandler handler, void *use
 
 bool pty_forward_drain(PTYForward *f);
 
+int pty_forward_set_priority(PTYForward *f, int64_t priority);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);