Mario Charest
07/19/2010 1:38 PM
post59849
|
Check the value of errno after shm_open fail, it should give you good idea of that is going on.
-----Message d'origine-----
De : Yuan Sun [mailto:community-noreply@qnx.com]
Envoyé : 19 juillet 2010 13:29
À : ostech-core_os
Objet : shm_open & mmap
Hi everyone.
I am a newbie in C programming and QNX. I am currently working on a project based on C programming in QNX and have met
cross some problems.
There are some existing executable programs compiled in QNX 6.3.2. Now the OS has been updated to QNX 6.4.0, and a few
of the executable programs cannot run correctly. I checked the source code and found the problems probably occured when
shm_open or mmap was called. The interesting thing is that shm_open is also called in other executable programs and they
can work successfully.
In the problem program, shm_open is called like:
" shm_descr = shm_open(CMD_INTERFACE_SHM_NAME,O_RDWR, S_IRWXU); "
And in the normal program, it's called like:
" fd = shm_open(devName,O_RDWR|O_CREAT,0); "
Does the flag's difference matter? Or the problem was caused by the update of QNX OS?
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post59844
|
|
|
Gervais Mulongoy
07/19/2010 1:59 PM
post59855
|
In the first example, it fails because the file doesn't already exist (you can not logically open a file for read and
write if it is not already created).
In the second example it succeeds because you instruct it to create the file first if it doesn't already exist.
If you check the value of errno after the first exmaple fails it will indicate that the "file is not found" meaning you
need to O_CREAT it first.
Good luck!
|
|
|
Thomas Haupt
07/20/2010 3:11 AM
post59905
|
Hi,
yes, the differences do matter - but not only those in the flags.
Even if you first do
fd = shm_open(devName,O_RDWR|O_CREAT,0);
and call
shm_descr = shm_open(CMD_INTERFACE_SHM_NAME,O_RDWR, S_IRWXU);
after that (i.e., when the shared memory object already exists), it'll still fail.That is because your object's file
permissions (the third argument) are set to 0 when it is created. That means no-one will be granted read or write access
.
(BTW: I'm always assuming that devName and CMD_INTERFACE_SHM_NAME are identical... if they aren't, there's another
problem...)
Try changing the calls like this:
fd = shm_open( devName, O_RDWR|O_CREAT, S_IRWXU );
shm_descr = shm_open( CMD_INTERFACE_SHM_NAME, O_RDWR, 0 );
Regards,
- Thomas
|
|
|