mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-02 01:08:14 +00:00
Close some file descriptors that were left dangling before
This commit is contained in:
parent
b10b436ac9
commit
4a572b810b
88
geojson.c
88
geojson.c
@ -1151,57 +1151,55 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexst.st_size == 0) {
|
if (indexst.st_size != 0) {
|
||||||
continue; // no indices from this input
|
struct index *indexmap = mmap(NULL, indexst.st_size, PROT_READ, MAP_PRIVATE, indexfds_in[i], 0);
|
||||||
}
|
if (indexmap == MAP_FAILED) {
|
||||||
|
fprintf(stderr, "fd %lld, len %lld\n", (long long) indexfds_in[i], (long long) indexst.st_size);
|
||||||
|
perror("map index");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
madvise(indexmap, indexst.st_size, MADV_SEQUENTIAL);
|
||||||
|
madvise(indexmap, indexst.st_size, MADV_WILLNEED);
|
||||||
|
char *geommap = mmap(NULL, geomst.st_size, PROT_READ, MAP_PRIVATE, geomfds_in[i], 0);
|
||||||
|
if (geommap == MAP_FAILED) {
|
||||||
|
perror("map geom");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
madvise(geommap, geomst.st_size, MADV_SEQUENTIAL);
|
||||||
|
madvise(geommap, geomst.st_size, MADV_WILLNEED);
|
||||||
|
|
||||||
struct index *indexmap = mmap(NULL, indexst.st_size, PROT_READ, MAP_PRIVATE, indexfds_in[i], 0);
|
long long a;
|
||||||
if (indexmap == MAP_FAILED) {
|
for (a = 0; a < indexst.st_size / sizeof(struct index); a++) {
|
||||||
fprintf(stderr, "fd %lld, len %lld\n", (long long) indexfds_in[i], (long long) indexst.st_size);
|
struct index ix = indexmap[a];
|
||||||
perror("map index");
|
unsigned long long which = (ix.index << prefix) >> (64 - splitbits);
|
||||||
exit(EXIT_FAILURE);
|
long long pos = sub_geompos[which];
|
||||||
}
|
|
||||||
madvise(indexmap, indexst.st_size, MADV_SEQUENTIAL);
|
|
||||||
madvise(indexmap, indexst.st_size, MADV_WILLNEED);
|
|
||||||
char *geommap = mmap(NULL, geomst.st_size, PROT_READ, MAP_PRIVATE, geomfds_in[i], 0);
|
|
||||||
if (geommap == MAP_FAILED) {
|
|
||||||
perror("map geom");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
madvise(geommap, geomst.st_size, MADV_SEQUENTIAL);
|
|
||||||
madvise(geommap, geomst.st_size, MADV_WILLNEED);
|
|
||||||
|
|
||||||
long long a;
|
fwrite_check(geommap + ix.start, ix.end - ix.start, 1, geomfiles[which], "geom");
|
||||||
for (a = 0; a < indexst.st_size / sizeof(struct index); a++) {
|
sub_geompos[which] += ix.end - ix.start;
|
||||||
struct index ix = indexmap[a];
|
|
||||||
unsigned long long which = (ix.index << prefix) >> (64 - splitbits);
|
|
||||||
long long pos = sub_geompos[which];
|
|
||||||
|
|
||||||
fwrite_check(geommap + ix.start, ix.end - ix.start, 1, geomfiles[which], "geom");
|
// Count this as a 25%-accomplishment, since we will copy again
|
||||||
sub_geompos[which] += ix.end - ix.start;
|
*progress += (ix.end - ix.start) / 4;
|
||||||
|
if (!quiet && 100 * *progress / *progress_max != *progress_reported) {
|
||||||
|
fprintf(stderr, "Reordering geometry: %lld%% \r", 100 * *progress / *progress_max);
|
||||||
|
*progress_reported = 100 * *progress / *progress_max;
|
||||||
|
}
|
||||||
|
|
||||||
// Count this as a 25%-accomplishment, since we will copy again
|
ix.start = pos;
|
||||||
*progress += (ix.end - ix.start) / 4;
|
ix.end = sub_geompos[which];
|
||||||
if (!quiet && 100 * *progress / *progress_max != *progress_reported) {
|
|
||||||
fprintf(stderr, "Reordering geometry: %lld%% \r", 100 * *progress / *progress_max);
|
fwrite_check(&ix, sizeof(struct index), 1, indexfiles[which], "index");
|
||||||
*progress_reported = 100 * *progress / *progress_max;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ix.start = pos;
|
madvise(indexmap, indexst.st_size, MADV_DONTNEED);
|
||||||
ix.end = sub_geompos[which];
|
if (munmap(indexmap, indexst.st_size) < 0) {
|
||||||
|
perror("unmap index");
|
||||||
fwrite_check(&ix, sizeof(struct index), 1, indexfiles[which], "index");
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
madvise(geommap, geomst.st_size, MADV_DONTNEED);
|
||||||
madvise(indexmap, indexst.st_size, MADV_DONTNEED);
|
if (munmap(geommap, geomst.st_size) < 0) {
|
||||||
if (munmap(indexmap, indexst.st_size) < 0) {
|
perror("unmap geom");
|
||||||
perror("unmap index");
|
exit(EXIT_FAILURE);
|
||||||
exit(EXIT_FAILURE);
|
}
|
||||||
}
|
|
||||||
madvise(geommap, geomst.st_size, MADV_DONTNEED);
|
|
||||||
if (munmap(geommap, geomst.st_size) < 0) {
|
|
||||||
perror("unmap geom");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(geomfds_in[i]) < 0) {
|
if (close(geomfds_in[i]) < 0) {
|
||||||
|
11
tile.cc
11
tile.cc
@ -1343,6 +1343,17 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < TEMP_FILES; j++) {
|
||||||
|
// Can be < 0 if there is only one source file, at z0
|
||||||
|
if (geomfd[j] >= 0) {
|
||||||
|
if (close(geomfd[j]) != 0) {
|
||||||
|
perror("close geom");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user