commit d391ca2ddb719d2478e824dec082b849613eeda6
Author: Mattias Andrée <[email protected]>
AuthorDate: Sun Jul 23 22:55:14 2017 +0200
Commit: Mattias Andrée <[email protected]>
CommitDate: Sun Jul 23 22:55:14 2017 +0200
Fix support for using sockets insteads of pipes
Signed-off-by: Mattias Andrée <[email protected]>
diff --git a/src/blind-coordinate-field.c b/src/blind-coordinate-field.c
index d4cd390..3b8a7c6 100644
--- 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
index b8f693a..7e8c348 100644
--- 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
index c0f54c9..bfcafdb 100644
--- 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
index 03d1609..12608f8 100644
--- 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)
{