]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ptyfwd: try to drain on exit only once 35752/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Dec 2024 08:38:54 +0000 (17:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Dec 2024 08:51:42 +0000 (17:51 +0900)
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

index 901a73dafdebb3cf4f2f05c86273145f1325ab81..d47bbccd9ec0b4774c28997fa898ed82dfa3bd06 100644 (file)
@@ -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(