Skip to content

Commit c26ff67

Browse files
YHNdnzjbluca
authored andcommitted
run: when disconnected from PTY forwarder, exit event loop if not --wait
Follow-up for ade0789 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 (cherry picked from commit 2b4a691) (cherry picked from commit 4656130) (cherry picked from commit 4e89a41)
1 parent 93e1514 commit c26ff67

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/run/run.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ static void run_context_check_done(RunContext *c) {
10341034
else
10351035
done = true;
10361036

1037-
if (c->forward && done) /* If the service is gone, it's time to drain the output */
1037+
if (c->forward && !pty_forward_is_done(c->forward) && done) /* If the service is gone, it's time to drain the output */
10381038
done = pty_forward_drain(c->forward);
10391039

10401040
if (done)
@@ -1106,9 +1106,14 @@ static int pty_forward_handler(PTYForward *f, int rcode, void *userdata) {
11061106

11071107
assert(f);
11081108

1109-
if (rcode == -ECANCELED)
1109+
if (rcode == -ECANCELED) {
11101110
log_debug_errno(rcode, "PTY forwarder disconnected.");
1111-
else if (rcode < 0) {
1111+
if (!arg_wait)
1112+
return sd_event_exit(c->event, EXIT_SUCCESS);
1113+
1114+
/* If --wait is specified, we'll only exit the pty forwarding, but will continue to wait
1115+
* for the service to end. If the user hits ^C we'll exit too. */
1116+
} else if (rcode < 0) {
11121117
sd_event_exit(c->event, EXIT_FAILURE);
11131118
return log_error_errno(rcode, "Error on PTY forwarding logic: %m");
11141119
}

0 commit comments

Comments
 (0)