Email List: Xaustin-review-lX
[All Lists]

Bug in TC2-d2 shm_open()

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Bug in TC2-d2 shm_open()
From: yyyyyyyyy@xxxxxxx
Date: Fri, 18 Jul 2003 17:03:55 +0100 (BST)
        Bug report from : Michael Kerrisk , self

(Note that the reply-to line automatically redirects 
to yyyyyyyyyyyyyy@xxxxxxxxxxxxx for further discussion on bug reports)

@ page 1 line 41250 section shm_open() comment {example for shm_open()}

Problem:

This is an EXAMPLE for the shm_open() man page.  Line number 
references are to TC1.  It could also be cited as an example 
for mmap() (line 25497).


Action:

Change

"None"

to the following:

The following code segment demonstrates the use of shm_open() 
to create a shared memory object which is then sized using 
ftruncate() before being mapped into the process’ address 
space using mmap():

#define MAX_LEN 10000
struct region {        /* Defines "structure" of shared memory */
    int len;
    char buf[MAX_LEN];
};
struct region *rptr;
int fd;

/* Create shared memory object and set its size */

fd = shm_open("/myregion", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1)
    /* Handle error */;

if (ftruncate(fd, sizeof(struct region)) == -1)
    /* Handle error */;

/* Map shared memory object */

rptr = mmap(NULL, sizeof(struct region),
        PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (rptr == MAP_FAILED)
    /* Handle error */;

/* Now we can refer to mapped region using fields of rptr,
   for example, rptr->len */

<Prev in Thread] Current Thread [Next in Thread>
  • Bug in TC2-d2 shm_open(), mtk-lists <=