commit d391ca2ddb719d2478e824dec082b849613eeda6
parent 3b3646effb548d2af894422f2123dd7976d7f1af
Author: Mattias Andrée <maandree@kth.se>
Date: Sun, 23 Jul 2017 22:55:14 +0200
Fix support for using sockets insteads of pipes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/blind-coordinate-field.c b/src/blind-coordinate-field.c
@@ -64,8 +64,7 @@ PROCESS(void)
buf[1] = (TYPE)y;
for (x = 0; x < stream.width; x++) {
buf[0] = (TYPE)x;
- if (write(STDOUT_FILENO, buf, sizeof(buf)) < 0)
- eprintf("write <stdout>:");
+ ewrite(STDOUT_FILENO, buf, sizeof(buf), "<stdout>");
}
}
}
diff --git a/src/blind-single-colour.c b/src/blind-single-colour.c
@@ -86,8 +86,7 @@ PROCESS(void)
for (y = stream.height; y--;)
for (x = stream.width * sizeof(*buf); x;)
for (x -= n = MIN(sizeof(buf), x); n; n -= (size_t)r)
- if ((r = write(STDOUT_FILENO, buf, n)) < 0)
- eprintf("write <stdout>:");
+ r = ewrite(STDOUT_FILENO, buf, n, "<stdout>");
}
#endif
diff --git a/src/blind-tee.c b/src/blind-tee.c
@@ -13,6 +13,8 @@ main(int argc, char *argv[])
UNOFLAGS(0);
+ signal(SIGPIPE, SIG_IGN);
+
fds[n++] = STDOUT_FILENO;
while (argc--)
fds[n++] = eopen(*argv++, O_WRONLY | O_CREAT | O_TRUNC, 0666);
diff --git a/src/util/efunc.h b/src/util/efunc.h
@@ -64,6 +64,18 @@ epread(int fd, void *buf, size_t n, off_t off, const char *fname)
return (size_t)ret;
}
+static inline size_t
+ewrite(int fd, void *buf, size_t n, const char *fname)
+{
+ ssize_t ret = write(fd, buf, n);
+ if (ret < 0) {
+ if (errno = ECONNRESET)
+ raise(SIGPIPE);
+ eprintf("write %s:", fname);
+ }
+ return (size_t)ret;
+}
+
static inline off_t
elseek(int fd, off_t offset, int whence, const char *fname)
{