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){
|
|
|
|
NZG_ERROR("sem_open",spaceListSemId);
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Fait un segment de memoir partager sur espace de listelement*/
|
|
|
|
spaceListFd=shm_open(spaceListId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,0600);
|
|
|
|
if (spaceListFd == -1){
|
|
|
|
spaceListFd=shm_open(spaceListId,O_RDWR|O_TRUNC,0600);
|
|
|
|
if (spaceListFd == -1){
|
|
|
|
NZG_ERROR("shm_open",spaceListId);
|
|
|
|
goto ERROR;
|
|
|
|
} else {
|
|
|
|
close(spaceListFd);
|
|
|
|
goto EXISTING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){
|
|
|
|
NZG_ERROR("ftruncate",spaceListId);
|
|
|
|
goto ERROR;
|
|
|
|
}
|
|
|
|
close(spaceListFd);
|
|
|
|
|
|
|
|
msgSpaceList *list;
|
|
|
|
list=msgSpaceListOpen();
|
|
|
|
strcpy(list->id,spaceListId);
|
|
|
|
strcpy(list->headId,spaceListId);
|
|
|
|
strcpy(list->tailId,spaceListId);
|
|
|
|
msgSpaceListClose(list);
|
|
|
|
|
|
|
|
msgSpaceListUnlock();
|
|
|
|
|
|
|
|
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 21:28:11 +00:00
|
|
|
return 0;
|
2004-02-22 22:32:15 +00:00
|
|
|
};
|
|
|
|
|