Skip to content

Commit

Permalink
Support WSL1 support where memfd_create returns `ENOSYS (function not…
Browse files Browse the repository at this point in the history
… implemented)`. (#1519)

Fixes comment
#141 (comment)

Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow authored Aug 14, 2023
1 parent 6d7dfc4 commit 0c852fd
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/server/memory/malloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,30 @@ struct memfd_create_compat {
std::string file_template = "vineyard-bulk-XXXXXX";
std::vector<char> file_name(file_template.begin(), file_template.end());
file_name.push_back('\0');
return memfd_create_fn(&file_name[0], 0);
} else {
std::string file_template = "/dev/shm/vineyard-bulk-XXXXXX";
std::vector<char> file_name(file_template.begin(), file_template.end());
file_name.push_back('\0');
int fd = mkstemp(&file_name[0]);
if (fd < 0) {
return fd;
}
if (unlink(&file_name[0]) != 0) {
LOG(ERROR) << "failed to unlink file " << &file_name[0];
close(fd);
return -1;
int fd = memfd_create_fn(&file_name[0], 0);
if (fd < 0 && errno == ENOSYS) {
LOG(WARNING) << "Looks like that we are working inside WSL 1 ("
<< strerror(errno)
<< "), fallback to mkstemp(3) for shared memory";
// disable memfd_create, and fall through
memfd_create_fn = nullptr;
} else {
return fd; // propogate the error
}
}
std::string file_template = "/dev/shm/vineyard-bulk-XXXXXX";
std::vector<char> file_name(file_template.begin(), file_template.end());
file_name.push_back('\0');
int fd = mkstemp(&file_name[0]);
if (fd < 0) {
return fd;
}
if (unlink(&file_name[0]) != 0) {
LOG(ERROR) << "failed to unlink file " << &file_name[0];
close(fd);
return -1;
}
return fd;
}

~memfd_create_compat() {
Expand Down

0 comments on commit 0c852fd

Please sign in to comment.