Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 7382

Summary: Can't mmap a O_WRONLY fd (must be O_RDWR)
Product: [Retired] Red Hat Linux Reporter: James Manning <jmm>
Component: man-pagesAssignee: Trond Eivind Glomsrxd <teg>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-05-29 22:00:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description James Manning 1999-11-28 02:45:33 UTC
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");
   printf("mapped file %s size %d at %p.\n", newfile, size, newptr);
   strcpy(newptr,"Mary had a little lamb\n");


Comment 1 Cristian Gafton 2000-05-22 15:02:59 UTC
assigned to teg

Comment 2 Trond Eivind Glomsrxd 2000-05-29 22:00:59 UTC
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.)