From d3218c4c80c99583d3e7a31ff2f509ffb097568e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 25 Dec 2024 17:38:54 +0900 Subject: [PATCH] ptyfwd: try to drain on exit only once Reading or writing a fd may fail with EBUSY, and the loop might run without doing mostly nothing and the event loop may finish with ELOOP. --- src/shared/ptyfwd.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index 901a73dafde..d47bbccd9ec 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -849,14 +849,8 @@ static int on_exit_event(sd_event_source *e, void *userdata) { assert(e); assert(e == f->exit_event_source); - /* Drain the buffer on exit. */ - - if (f->done) - return 0; - - for (unsigned trial = 0; trial < 1000; trial++) { - if (drained(f)) - return pty_forward_done(f, 0); + if (!pty_forward_drain(f)) { + /* If not drained, try to drain the buffer. */ if (!f->master_hangup) f->master_writable = f->master_readable = true; @@ -868,12 +862,9 @@ static int on_exit_event(sd_event_source *e, void *userdata) { r = shovel(f); if (r < 0) return r; - if (f->done) - return 0; } - /* If we could not drain, then propagate recognizable error code. */ - return pty_forward_done(f, -ELOOP); + return pty_forward_done(f, 0); } int pty_forward_new( -- 2.47.3