From 71ac6596afae91aa9c27bb931b14e63a9384c52d Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 21 Dec 2016 10:10:22 -0800 Subject: [PATCH] Warn about broken pipes in filters instead of exiting abruptly --- main.cpp | 3 +++ plugin.cpp | 16 +++++++++++----- tile.cpp | 12 ++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 18f4602..866d895 100644 --- a/main.cpp +++ b/main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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"); diff --git a/plugin.cpp b/plugin.cpp index db623a6..db06357 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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) { diff --git a/tile.cpp b/tile.cpp index abce83e..e92d23b 100644 --- a/tile.cpp +++ b/tile.cpp @@ -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; }