Commit 274b2f8c authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix a bug causing the server to crash when writing on a memory mapped

  file on Linux.

modified:
  storage/connect/maputil.cpp
parent 44efd729
...@@ -117,6 +117,7 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName, ...@@ -117,6 +117,7 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName,
MEMMAP *mm, MODE mode, bool del) MEMMAP *mm, MODE mode, bool del)
{ {
unsigned int openMode; unsigned int openMode;
int protmode;
HANDLE fd; HANDLE fd;
size_t filesize; size_t filesize;
struct stat st; struct stat st;
...@@ -127,13 +128,16 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName, ...@@ -127,13 +128,16 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName,
switch (mode) { switch (mode) {
case MODE_READ: case MODE_READ:
openMode = O_RDONLY; openMode = O_RDONLY;
protmode = PROT_READ;
break; break;
case MODE_UPDATE: case MODE_UPDATE:
case MODE_DELETE: case MODE_DELETE:
openMode = (del) ? (O_RDWR | O_TRUNC) : O_RDWR; openMode = (del) ? (O_RDWR | O_TRUNC) : O_RDWR;
protmode = PROT_WRITE;
break; break;
case MODE_INSERT: case MODE_INSERT:
openMode = (O_WRONLY | O_CREAT | O_APPEND); openMode = (O_WRONLY | O_CREAT | O_APPEND);
protmode = PROT_WRITE;
break; break;
default: default:
sprintf(g->Message, MSG(BAD_FUNC_MODE), "CreateFileMap", mode); sprintf(g->Message, MSG(BAD_FUNC_MODE), "CreateFileMap", mode);
...@@ -155,9 +159,16 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName, ...@@ -155,9 +159,16 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName,
// Now we are ready to load the file. If mmap() is available we try // Now we are ready to load the file. If mmap() is available we try
// this first. If not available or it failed we try to load it. // this first. If not available or it failed we try to load it.
mm->memory = mmap(NULL, filesize, PROT_READ, MAP_PRIVATE, fd, 0); mm->memory = mmap(NULL, filesize, protmode, MAP_PRIVATE, fd, 0);
if (mm->memory) {
mm->lenL = (mm->memory != 0) ? filesize : 0; mm->lenL = (mm->memory != 0) ? filesize : 0;
mm->lenH = 0; mm->lenH = 0;
} else {
strcpy(g->Message, "Memory mapping failed");
return INVALID_HANDLE_VALUE;
} endif // memory
} /* endif fd */ } /* endif fd */
// mmap() call was successful. ?????????? // mmap() call was successful. ??????????
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment