2004-02-22 22:32:15 +00:00
|
|
|
#include "libnazgul.h"
|
|
|
|
|
|
|
|
int msgSpaceListInit(){
|
|
|
|
int descMemory;
|
2004-02-22 22:46:09 +00:00
|
|
|
sem_t * spacesListSemFd;
|
|
|
|
msgSpaceListSemId spacesListSemId;
|
|
|
|
msgSpaceListElemId spacesListId;
|
2004-02-25 18:51:33 +00:00
|
|
|
|
|
|
|
/*Creation de semaphore*/
|
|
|
|
spacesListSemFd=sem_open(msgSpaceListSemId,O_CREAT|O_EXCL,0666,0);
|
|
|
|
if(spacesListSemFd==SEM_FAILED){
|
|
|
|
NZG_ERROR("sem_open",msgSpaceListSemId);
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-02-22 22:46:09 +00:00
|
|
|
/*Fait un segment de memoir partager sur espace de listelement*/
|
2004-02-25 18:51:33 +00:00
|
|
|
descMemory=shm_open(msgSpaceListId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,0600);
|
2004-02-22 22:46:09 +00:00
|
|
|
if (descMemory == -1){
|
2004-02-25 18:51:33 +00:00
|
|
|
descMemory=shm_open(msgSpaceListId,O_RDWR|O_TRUNC,0600);
|
|
|
|
if (descMemory == -1){
|
|
|
|
NZG_ERROR("shm_open",spacesListId);
|
|
|
|
goto ERROR;
|
|
|
|
} else {
|
|
|
|
close(descMemory);
|
|
|
|
goto EXISTING;
|
|
|
|
}
|
2004-02-22 22:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:51:33 +00:00
|
|
|
|
2004-02-22 22:32:15 +00:00
|
|
|
/*Creation de semaphore*/
|
2004-02-25 18:51:33 +00:00
|
|
|
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,0);
|
2004-02-22 22:46:09 +00:00
|
|
|
if(spacesListSemFd==SEM_FAILED){
|
2004-02-25 18:51:33 +00:00
|
|
|
NZG_ERROR("sem_open",spacesListSemId);
|
|
|
|
goto ERROR;
|
2004-02-22 22:32:15 +00:00
|
|
|
}
|
2004-02-25 18:51:33 +00:00
|
|
|
msgSpaceListUnlock();
|
2004-02-22 22:32:15 +00:00
|
|
|
|
2004-02-25 18:51:33 +00:00
|
|
|
return 0;
|
|
|
|
ERROR:
|
|
|
|
return -1;
|
|
|
|
EXISTING:
|
2004-02-22 22:32:15 +00:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|