Warn about broken pipes in filters instead of exiting abruptly

This commit is contained in:
Eric Fischer 2016-12-21 10:10:22 -08:00
parent 6a5461763c
commit 71ac6596af
3 changed files with 24 additions and 7 deletions

View File

@ -24,6 +24,7 @@
#include <sys/resource.h>
#include <pthread.h>
#include <getopt.h>
#include <signal.h>
#include <vector>
#include <string>
#include <set>
@ -2207,6 +2208,8 @@ int main(int argc, char **argv) {
}
}
signal(SIGPIPE, SIG_IGN);
files_open_at_start = open("/dev/null", O_RDONLY | O_CLOEXEC);
if (files_open_at_start < 0) {
perror("open /dev/null");

View File

@ -12,6 +12,7 @@
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <cmath>
#include <sys/types.h>
#include <sys/wait.h>
@ -42,8 +43,6 @@ struct writer_arg {
void *run_writer(void *a) {
writer_arg *wa = (writer_arg *) a;
// XXX worry about SIGPIPE?
FILE *fp = fdopen(wa->write_to, "w");
if (fp == NULL) {
perror("fdopen (pipe writer)");
@ -53,8 +52,16 @@ void *run_writer(void *a) {
layer_to_geojson(fp, *(wa->layer), wa->z, wa->x, wa->y, false, false);
if (fclose(fp) != 0) {
perror("fclose output to filter");
exit(EXIT_FAILURE);
if (errno == EPIPE) {
static bool warned = false;
if (!warned) {
fprintf(stderr, "Warning: broken pipe in postfilter\n");
warned = true;
}
} else {
perror("fclose output to filter");
exit(EXIT_FAILURE);
}
}
return NULL;
@ -382,7 +389,6 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
}
auto fk = layermap.find(layername);
fprintf(stderr, "assign layer %zu\n", fk->second.id);
sf.layer = fk->second.id;
if (z < fk->second.minzoom) {

View File

@ -1378,8 +1378,16 @@ void *run_prefilter(void *v) {
}
if (fclose(rpa->prefilter_fp) != 0) {
perror("fclose output to prefilter");
exit(EXIT_FAILURE);
if (errno == EPIPE) {
static bool warned = false;
if (!warned) {
fprintf(stderr, "Warning: broken pipe in prefilter\n");
warned = true;
}
} else {
perror("fclose output to prefilter");
exit(EXIT_FAILURE);
}
}
return NULL;
}