aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-04-14 02:11:03 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-04-14 02:11:03 +0200
commit6fae889a13757197c0180166c5518aea44a12a4c (patch)
tree3e7f38c75aa69baf0e85d0e87ebece9f1c5b6c5b
parent07a60a3908c70e7504e57883d19512f78d42df28 (diff)
downloadmblaze-6fae889a13757197c0180166c5518aea44a12a4c.tar.gz
filter: block SIGPIPE during filtering
-rw-r--r--filter.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/filter.c b/filter.c
index 9784573..1a03598 100644
--- a/filter.c
+++ b/filter.c
@@ -1,4 +1,5 @@
#include <poll.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -12,9 +13,16 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
ssize_t outlen;
ssize_t outalloc = 4096;
pid_t pid;
+ sigset_t mask, orig_mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGPIPE);
+ sigprocmask(SIG_BLOCK, &mask, &orig_mask);
- output = malloc(outalloc);
outlen = 0;
+ output = malloc(outalloc);
+ if (!output)
+ goto fail;
int pipe0[2];
int pipe1[2];
@@ -95,6 +103,9 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
*outputo = output;
*outleno = outlen;
+ sigwaitinfo(&mask, 0);
+ sigprocmask(SIG_SETMASK, &orig_mask, 0);
+
return WEXITSTATUS(status);
fail:
@@ -102,6 +113,9 @@ fail:
*outleno = 0;
free(output);
+ sigwaitinfo(&mask, 0);
+ sigprocmask(SIG_SETMASK, &orig_mask, 0);
+
return -1;
}