Skip to content

Commit

Permalink
Make sure that mmap'ed files smaller than a page size are written to.
Browse files Browse the repository at this point in the history
This is a test to make sure that there is actually enough memory
to back the requested shared memory.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed Nov 8, 2012
1 parent c533b24 commit 839d14f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/unix.c
Expand Up @@ -112,22 +112,23 @@ qb_sys_mmap_file_open(char *path, const char *file, size_t bytes,

if (file_flags & O_CREAT) {
long page_size = sysconf(_SC_PAGESIZE);
long write_size = QB_MIN(page_size, bytes);
if (page_size < 0) {
res = -errno;
goto unlink_exit;
}
buffer = calloc(1, page_size);
buffer = calloc(1, write_size);
if (buffer == NULL) {
res = -ENOMEM;
goto unlink_exit;
}
for (i = 0; i < (bytes / page_size); i++) {
for (i = 0; i < (bytes / write_size); i++) {
retry_write:
written = write(fd, buffer, page_size);
written = write(fd, buffer, write_size);
if (written == -1 && errno == EINTR) {
goto retry_write;
}
if (written != page_size) {
if (written != write_size) {
res = -ENOSPC;
free(buffer);
goto unlink_exit;
Expand Down

0 comments on commit 839d14f

Please sign in to comment.