mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 09:55:41 +02:00
Warn about broken pipes in filters instead of exiting abruptly
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#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);
|
files_open_at_start = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||||
if (files_open_at_start < 0) {
|
if (files_open_at_start < 0) {
|
||||||
perror("open /dev/null");
|
perror("open /dev/null");
|
||||||
|
|||||||
+11
-5
@@ -12,6 +12,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -42,8 +43,6 @@ struct writer_arg {
|
|||||||
void *run_writer(void *a) {
|
void *run_writer(void *a) {
|
||||||
writer_arg *wa = (writer_arg *) a;
|
writer_arg *wa = (writer_arg *) a;
|
||||||
|
|
||||||
// XXX worry about SIGPIPE?
|
|
||||||
|
|
||||||
FILE *fp = fdopen(wa->write_to, "w");
|
FILE *fp = fdopen(wa->write_to, "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
perror("fdopen (pipe writer)");
|
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);
|
layer_to_geojson(fp, *(wa->layer), wa->z, wa->x, wa->y, false, false);
|
||||||
|
|
||||||
if (fclose(fp) != 0) {
|
if (fclose(fp) != 0) {
|
||||||
perror("fclose output to filter");
|
if (errno == EPIPE) {
|
||||||
exit(EXIT_FAILURE);
|
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;
|
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);
|
auto fk = layermap.find(layername);
|
||||||
fprintf(stderr, "assign layer %zu\n", fk->second.id);
|
|
||||||
sf.layer = fk->second.id;
|
sf.layer = fk->second.id;
|
||||||
|
|
||||||
if (z < fk->second.minzoom) {
|
if (z < fk->second.minzoom) {
|
||||||
|
|||||||
@@ -1378,8 +1378,16 @@ void *run_prefilter(void *v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(rpa->prefilter_fp) != 0) {
|
if (fclose(rpa->prefilter_fp) != 0) {
|
||||||
perror("fclose output to prefilter");
|
if (errno == EPIPE) {
|
||||||
exit(EXIT_FAILURE);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user