2004-02-22 22:32:15 +00:00
|
|
|
#include "libnazgul.h"
|
2004-02-25 21:28:11 +00:00
|
|
|
#include "ids.h"
|
2004-02-22 22:32:15 +00:00
|
|
|
|
|
|
|
int msgSpaceListInit(){
|
2004-02-25 21:28:11 +00:00
|
|
|
int spaceListFd;
|
|
|
|
sem_t * spaceListSemFd;
|
|
|
|
|
|
|
|
msgSpaceListSemId spaceListSemId;
|
|
|
|
msgSpaceListId spaceListId;
|
|
|
|
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
|
|
|
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
|
|
|
|
|
|
|
|
/* Creation de semaphore */
|
|
|
|
spaceListSemFd=sem_open(spaceListSemId,O_CREAT|O_EXCL,0666,0);
|
|
|
|
if(spaceListSemFd==SEM_FAILED){
|
|
|
|
spaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
|
|
|
|
if(spaceListSemFd==SEM_FAILED){
|
2004-02-25 22:30:43 +00:00
|
|
|
NZG_ERROR("sem_open",spaceListSemId);
|
|
|
|
goto ERROR;
|
|
|
|
}
|
2004-02-25 21:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Fait un segment de memoir partager sur espace de listelement*/
|
2004-02-25 22:30:43 +00:00
|
|
|
spaceListFd=shm_open(spaceListId,
|
|
|
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
|
|
|
0666);
|
2004-02-25 21:28:11 +00:00
|
|
|
if (spaceListFd == -1){
|
2004-02-25 22:30:43 +00:00
|
|
|
spaceListFd=shm_open(spaceListId,O_RDWR,0666);
|
2004-02-25 21:28:11 +00:00
|
|
|
if (spaceListFd == -1){
|
|
|
|
NZG_ERROR("shm_open",spaceListId);
|
|
|
|
goto ERROR;
|
|
|
|
} else {
|
|
|
|
close(spaceListFd);
|
|
|
|
goto EXISTING;
|
|
|
|
}
|
|
|
|
}
|
2004-02-25 22:30:43 +00:00
|
|
|
if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){
|
2004-02-25 21:28:11 +00:00
|
|
|
NZG_ERROR("ftruncate",spaceListId);
|
|
|
|
goto ERROR;
|
|
|
|
}
|
2004-02-25 22:30:43 +00:00
|
|
|
close(spaceListFd);
|
2004-02-25 21:28:11 +00:00
|
|
|
|
2004-02-25 22:30:43 +00:00
|
|
|
msgSpaceList *list;
|
|
|
|
list=msgSpaceListOpen();
|
|
|
|
if (list == NULL){
|
|
|
|
NZG_ERROR("msgSpaceListOpen","");
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
strcpy(list->id,spaceListId);
|
|
|
|
strcpy(list->headId,spaceListId);
|
|
|
|
strcpy(list->tailId,spaceListId);
|
|
|
|
if (msgSpaceListClose(list) <0){
|
|
|
|
NZG_ERROR("msgSpaceListClose","");
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgSpaceListUnlock() < 0){
|
|
|
|
NZG_ERROR("msgSpaceListUnlock","");
|
|
|
|
goto ERROR;
|
|
|
|
}
|
2004-02-25 21:28:11 +00:00
|
|
|
|
|
|
|
return 0;
|
2004-02-25 18:51:33 +00:00
|
|
|
ERROR:
|
2004-02-25 21:28:11 +00:00
|
|
|
return -1;
|
2004-02-25 18:51:33 +00:00
|
|
|
EXISTING:
|
2004-02-25 22:30:43 +00:00
|
|
|
if (msgSpaceListUnlock() < 0){
|
|
|
|
NZG_ERROR("msgSpaceListUnlock","");
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
|
2004-02-25 21:28:11 +00:00
|
|
|
return 0;
|
2004-02-22 22:32:15 +00:00
|
|
|
};
|
|
|
|
|