Skip to content

Commit d1881dc

Browse files
committed
ttypxy: fix back/front devs shared buffer dups
This was causing on further PTY device to duplicate io.
1 parent a638091 commit d1881dc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ttypxy.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ static void ttypxy_run(struct ttypxy *ctx)
451451
if (n <= 0)
452452
break;
453453

454+
for (i = 0; i < ctx->frontdev_cnt; i++) {
455+
if (!ctx->frontdevs[i].td_active)
456+
continue;
457+
458+
if (xwrite(ctx->frontdevs[i].td_fd, buffer, n) != n)
459+
warn("write(%s) front TTY failed: %s\n",
460+
ctx->frontdevs[i].td_pts_link,
461+
strerror(errno));
462+
}
463+
454464
if (verbose)
455465
hexdump(ctx->backdev.td_path, buffer, n);
456466
}
@@ -459,12 +469,6 @@ static void ttypxy_run(struct ttypxy *ctx)
459469
if (!ctx->frontdevs[i].td_active)
460470
continue;
461471

462-
if (n > 0)
463-
if (xwrite(ctx->frontdevs[i].td_fd, buffer, n) != n)
464-
warn("write(%s) front TTY failed: %s\n",
465-
ctx->frontdevs[i].td_pts_link,
466-
strerror(errno));
467-
468472
if (FD_ISSET(ctx->frontdevs[i].td_fd, &rfds)) {
469473
n = xread(ctx->frontdevs[i].td_fd, buffer, sizeof(buffer));
470474
if (n <= 0) {

0 commit comments

Comments
 (0)