commit 21301645b3c52b55d6636662066b01919716f102
parent 746e6ae0a5fae46502e345f556a13ec0cb63df94
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Sun, 27 Feb 2022 15:57:08 -0600
waycopy: handle longer read/writes properly
Rather than checking for a shortcount in copyfd, we check if read
returns 0 which indicates that the pipe has been closed.
In order to make read return 0, we close the write end of the pipe
in waypaste so waycopy has the only open write end of the pipe.
Diffstat:
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/util.c b/util.c
@@ -44,7 +44,7 @@ copyfd(int out, int in)
ptr += len;
wcount += len;
}
- if (rcount < BUFSIZ)
+ if (!rcount)
break;
} while (1);
}
diff --git a/waypaste.c b/waypaste.c
@@ -23,14 +23,13 @@ offer_offer(void *data, struct zwlr_data_control_offer_v1 *offer, const char *mi
zwlr_data_control_offer_v1_receive(offer, mime_type, pipes[1]);
wl_display_roundtrip(display);
- } else {
- return;
- }
+ close(pipes[1]);
- copyfd(STDOUT_FILENO, pipes[0]);
- close(pipes[0]);
+ copyfd(STDOUT_FILENO, pipes[0]);
+ close(pipes[0]);
- exit(0);
+ exit(0);
+ }
}
static const struct zwlr_data_control_offer_v1_listener offer_listener = {