more specific mmap(2) failure checks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
diff --git a/lib/pack.c b/lib/pack.c
index ca197e1..92c3db0 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -394,8 +394,13 @@ got_packidx_open(struct got_packidx **packidx, const char *path, int verify)
#ifndef GOT_PACK_NO_MMAP
p->map = mmap(NULL, p->len, PROT_READ, MAP_PRIVATE, p->fd, 0);
- if (p->map == MAP_FAILED)
+ if (p->map == MAP_FAILED) {
+ if (errno != ENOMEM) {
+ err = got_error_from_errno();
+ goto done;
+ }
p->map = NULL; /* fall back to read(2) */
+ }
#endif
err = got_packidx_init_hdr(p, verify);
diff --git a/lib/repository.c b/lib/repository.c
index 18ad2bb..96c0dad 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -763,8 +763,13 @@ got_repo_cache_pack(struct got_pack **packp, struct got_repository *repo,
#ifndef GOT_PACK_NO_MMAP
pack->map = mmap(NULL, pack->filesize, PROT_READ, MAP_PRIVATE,
pack->fd, 0);
- if (pack->map == MAP_FAILED)
+ if (pack->map == MAP_FAILED) {
+ if (errno != ENOMEM) {
+ err = got_error_from_errno();
+ goto done;
+ }
pack->map = NULL; /* fall back to read(2) */
+ }
#endif
done:
if (err) {