open("/tmp/newfile", O_WRONLY) = 3 mmap(0, 4096, PROT_WRITE, MAP_SHARED, 3, 0) = -1 EACCES (Permission denied) open("/tmp/newfile", O_RDWR) = 3 mmap(0, 4096, PROT_WRITE, MAP_SHARED, 3, 0) = 0x40013000 According to the mmap man page, EACCES when MAP_SHARED was asked and PROT_WRITE is set means that the fd was not open for writing (O_WRONLY obviously is) Since expecting O_RDWR seems reasonable, maybe the man page could simply better reflect this requirement. --- /usr/man/man2/mmap.2.orig Sat Nov 27 22:51:15 1999 +++ /usr/man/man2/mmap.2 Sat Nov 27 22:51:41 1999 @@ -128 +128 @@ -is not open for writing. +is not open in read/write (O_RDWR) mode. Sample code: #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *newfile="/tmp/newfile",*newptr; int newfd,size=getpagesize(); // guaranteed to be page-sized :) if (atoi(argv[1])) newfd=open(newfile,O_RDWR,0777); else newfd=open(newfile,O_WRONLY,0777); newptr=(char *)mmap(NULL,size,PROT_WRITE,MAP_SHARED,newfd,(int)NULL); if (newptr == MAP_FAILED) { perror("We had an mmap error"); return(1); } printf("mapped file %s size %d at %p.\n", newfile, size, newptr); strcpy(newptr,"Mary had a little lamb\n"); return(0); }
assigned to teg
Should be fixed in the next rawhide. Please note that glibc doesn't come with man pages, so you should use the info pages are a better reference. The GNU project considers man-pages obsolete (bah - much more convenient IMHO. I don't like info.)