Commit 3a11398b2a1b600f235c8a856af966f671c58907

Stefan Sperling 2019-02-21T14:15:33

more specific mmap(2) failure checks

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) {