Bug 7382 - Can't mmap a O_WRONLY fd (must be O_RDWR)
Can't mmap a O_WRONLY fd (must be O_RDWR)
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: man-pages (Show other bugs)
6.1
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Trond Eivind Glomsrxd
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 1999-11-27 21:45 EST by James Manning
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-05-29 18:00:07 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description James Manning 1999-11-27 21:45:33 EST
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);

}
Comment 1 Cristian Gafton 2000-05-22 11:02:59 EDT
assigned to teg
Comment 2 Trond Eivind Glomsrxd 2000-05-29 18:00:59 EDT
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.)

Note You need to log in before you can comment on or make changes to this bug.