Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Close other side of pipe after using barrier

  • Loading branch information...
commit 5d0e79988226c681d3c0d930f2cd34a3de238a47 1 parent 8de5d03
Dmitriy Kalinin and Pieter Noordhuis authored
Showing with 12 additions and 6 deletions.
  1. +12 −6 warden/src/wsh/barrier.c
View
18 warden/src/wsh/barrier.c
@@ -40,20 +40,24 @@ void barrier_mix_cloexec(barrier_t *bar) {
void barrier_close_wait(barrier_t *bar) {
close(bar->fd[0]);
+ bar->fd[0] = -1;
}
void barrier_close_signal(barrier_t *bar) {
close(bar->fd[1]);
+ bar->fd[1] = -1;
}
int barrier_wait(barrier_t *bar) {
- char buf[1];
int nread;
+ char buf[1];
- /* Close signal side of pipe on wait */
barrier_close_signal(bar);
nread = read(bar->fd[0], buf, sizeof(buf));
+
+ barrier_close_wait(bar);
+
if (nread == -1) {
perror("read");
return -1;
@@ -65,14 +69,16 @@ int barrier_wait(barrier_t *bar) {
}
int barrier_signal(barrier_t *bar) {
- int rv;
+ int nwritten;
char byte = '\0';
- /* Close wait side of pipe on signal */
barrier_close_wait(bar);
- rv = write(bar->fd[1], &byte, 1);
- if (rv == -1) {
+ nwritten = write(bar->fd[1], &byte, 1);
+
+ barrier_close_signal(bar);
+
+ if (nwritten == -1) {
perror("write");
return -1;
}
Please sign in to comment.
Something went wrong with that request. Please try again.