Skip to content

Commit

Permalink
fixed #492
Browse files Browse the repository at this point in the history
  • Loading branch information
garryyan committed Dec 4, 2018
1 parent ad6d3ac commit 58dc05f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mars/comm/mmap_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ bool OpenMmapFile(const char* _filepath, unsigned int _size, boost::iostreams::m
return false;
}

boost::iostreams::mapped_file_params param;
param.path = _filepath;
boost::iostreams::basic_mapped_file_params<boost::filesystem::path> param;
param.path = boost::filesystem::path(_filepath);
param.flags = boost::iostreams::mapped_file_base::readwrite;

bool file_exist = boost::filesystem::exists(_filepath);
Expand All @@ -54,15 +54,15 @@ bool OpenMmapFile(const char* _filepath, unsigned int _size, boost::iostreams::m
_mmmap_file.open(param);

bool is_open = IsMmapFileOpenSucc(_mmmap_file);

#ifndef _WIN32
if (!file_exist && is_open) {

//Extending a file with ftruncate, thus creating a big hole, and then filling the hole by mod-ifying a shared mmap() can lead to SIGBUS when no space left
//the boost library uses ftruncate, so we pre-allocate the file's backing store by writing zero.
FILE* file = fopen(_filepath, "rb+");
if (NULL == file) {
_mmmap_file.close();
remove(_filepath);
boost::filesystem::remove(_filepath);
return false;
}

Expand All @@ -72,14 +72,14 @@ bool OpenMmapFile(const char* _filepath, unsigned int _size, boost::iostreams::m
if (_size != fwrite(zero_data, sizeof(char), _size, file)) {
_mmmap_file.close();
fclose(file);
remove(_filepath);
boost::filesystem::remove(_filepath);
delete[] zero_data;
return false;
}
fclose(file);
delete[] zero_data;
}

#endif
return is_open;
}

Expand Down

0 comments on commit 58dc05f

Please sign in to comment.