Skip to content

Commit 70afa6f

Browse files
pks-tgitster
authored andcommitted
reftable/blocksource: stop using xmmap()
We use `xmmap()` to map reftables into memory. This function has two problems: - It causes us to die in case the mmap fails. - It ties us to the Git codebase. Refactor the code to use mmap(3p) instead with manual error checking. Note that this function may not be the system-provided mmap(3p), but may point to our `git_mmap()` wrapper that emulates the syscall on systems that do not have mmap(3p) available. Fix `reftable_block_source_from_file()` to properly bubble up the error code in case the map(3p) call fails. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e31db89 commit 70afa6f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

reftable/blocksource.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static struct reftable_block_source_vtable file_vtable = {
9898
int reftable_block_source_from_file(struct reftable_block_source *bs,
9999
const char *name)
100100
{
101-
struct file_block_source *p;
101+
struct file_block_source *p = NULL;
102102
struct stat st;
103103
int fd, err;
104104

@@ -122,7 +122,12 @@ int reftable_block_source_from_file(struct reftable_block_source *bs,
122122
}
123123

124124
p->size = st.st_size;
125-
p->data = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
125+
p->data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
126+
if (p->data == MAP_FAILED) {
127+
err = REFTABLE_IO_ERROR;
128+
p->data = NULL;
129+
goto out;
130+
}
126131

127132
assert(!bs->ops);
128133
bs->ops = &file_vtable;
@@ -135,5 +140,5 @@ int reftable_block_source_from_file(struct reftable_block_source *bs,
135140
close(fd);
136141
if (err < 0)
137142
reftable_free(p);
138-
return 0;
143+
return err;
139144
}

0 commit comments

Comments
 (0)