]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: when disconnected from PTY forwarder, exit event loop if not --wait
authorMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 12:10:24 +0000 (20:10 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 13:30:32 +0000 (21:30 +0800)
Follow-up for ade0789fabbf01b95bf54d32f8cab1217a753f03

The change in behavior was partly intentional, as I think
if both --wait and --pty are used, manually disconnecting
from PTY forwarder should not result in systemd-run exiting
with "Finished with ..." log. But we should check for
--wait here.

Closes #32953

src/run/run.c

index fa77c5ea78eec7339fa07771edfffe8b5d9a82b8..3732945a2ed60ef1efda797e1a002980fff86923 100644 (file)
@@ -1432,7 +1432,7 @@ static void run_context_check_done(RunContext *c) {
         else
                 done = true;
 
-        if (c->forward && done) /* If the service is gone, it's time to drain the output */
+        if (c->forward && !pty_forward_is_done(c->forward) && done) /* If the service is gone, it's time to drain the output */
                 done = pty_forward_drain(c->forward);
 
         if (done)
@@ -1506,9 +1506,14 @@ static int pty_forward_handler(PTYForward *f, int rcode, void *userdata) {
 
         assert(f);
 
-        if (rcode == -ECANCELED)
+        if (rcode == -ECANCELED) {
                 log_debug_errno(rcode, "PTY forwarder disconnected.");
-        else if (rcode < 0) {
+                if (!arg_wait)
+                        return sd_event_exit(c->event, EXIT_SUCCESS);
+
+                /* If --wait is specified, we'll only exit the pty forwarding, but will continue to wait
+                 * for the service to end. If the user hits ^C we'll exit too. */
+        } else if (rcode < 0) {
                 sd_event_exit(c->event, EXIT_FAILURE);
                 return log_error_errno(rcode, "Error on PTY forwarding logic: %m");
         }