From: Yu Watanabe Date: Wed, 25 Dec 2024 08:38:54 +0000 (+0900) Subject: ptyfwd: try to drain on exit only once X-Git-Tag: v258-rc1~1778^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F35752%2Fhead;p=thirdparty%2Fsystemd.git 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. --- 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(