mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 6fae889a13757197c0180166c5518aea44a12a4c
parent 07a60a3908c70e7504e57883d19512f78d42df28
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Fri, 14 Apr 2017 02:11:03 +0200

filter: block SIGPIPE during filtering

Diffstat:
filter.c | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git 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; }