*** empty log message ***

This commit is contained in:
glenux 2004-02-25 21:28:11 +00:00 committed by Glenn Y. Rolland
parent 30ca24acf8
commit 60fdcf638e
12 changed files with 154 additions and 103 deletions

View file

@ -146,7 +146,7 @@ if (mSPoolDataTabAddr==NULL){
}
if (!gotRessourceSem){
msgPoolSemIdIntern(ressourceSemId,space->id,selectedPoolIndex);
msgPoolSemIdIntern(ressourceSemId,space->externId,selectedPoolIndex);
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if(ressourceSemFd==SEM_FAILED){
NZG_ERROR("sem_open",ressourceSemId);

View file

@ -48,7 +48,7 @@ int msgFree(msgSpace * space, void * addr){
msgPoolDataTabUnlock(space);
// deverouiller semaphore ressource.
msgPoolSemIdIntern(ressourceSemId,space->id,poolIndex);
msgPoolSemIdIntern(ressourceSemId,space->externId,poolIndex);
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if (ressourceSemFd == SEM_FAILED){
NZG_ERROR("sem_open",ressourceSemId);

View file

@ -25,6 +25,19 @@
#define SEM_FAILED ((sem_t *)0)
#endif
#ifdef _NZG_REALFILEID
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
#else
#define DEFAULT_MSGSPACELISTID "/nzgSpaceList"
#endif
#ifdef _NZG_REALFILEID
#define DEFAULT_MSGSPACELISTSEMID "/tmp/nzgSpaceListSem"
#else
#define DEFAULT_MSGSPACELISTSEMID "/nzgSpaceListSem"
#endif
#define NZG_ERROR(func,str) fprintf(stderr,"*** %s: %s***\n%s in %s:%d\n",func,strerror(errno),str,__FILE__,__LINE__);
#endif

View file

@ -2,17 +2,7 @@
#define _NZG_IDS 1
#include "libnazgul.h"
#ifdef _NZG_REALFILEID
#define msgSpaceListId "/tmp/nzgSpaceList"
#else
#define msgSpaceListId "/nzgSpaceList"
#endif
#ifdef _NZG_REALFILEID
#define msgSpaceListSemId "/tmp/nzgSpaceListSem"
#else
#define msgSpaceListSemId "/nzgSpaceListSem"
#endif
/* nzg_ids.c */

View file

@ -97,6 +97,9 @@ int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace *space);
/* spaceListElemLink.c */
/* spaceListElemOpen.c */
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId);
/* spaceListFindId.c */
int msgSpaceListFindId(msgSpaceId spaceId);
int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId);
/* spaceListInit.c */
int msgSpaceListInit(void);
/* spaceListLocking.c */

View file

@ -41,6 +41,22 @@ msgSpace * msgSpaceCreate(
if (msgSpaceIdIntern(nzgId,externId) < 0){
return NULL;
}
msgSpaceListInit();
printf("spaceListInit ok\n");
msgSpaceListLock();
printf("spaceListLock ok\n");
if (msgSpaceListFindId(nzgId) < 1){
NZG_ERROR("spaceListFindId",nzgId);
// zut, il y a soit une erreur
// soit le msgSpace existe deja
// on quitte
goto ERROR;
}
printf("spaceListFind ok\n");
msgSpaceListUnlock();
printf("spaceListUnlock ok\n");
fprintf(stderr,"Creating msgSpace with id : %s\n",nzgId);
mSFd=shm_open(
nzgId,
@ -73,7 +89,7 @@ msgSpace * msgSpaceCreate(
close(mSFd);
/* on remplit la structure */
strncpy(space->id,externId,MSGSPACE_ID_LEN);
strcpy(space->id,nzgId);
space->poolNb=poolNb;
space->queueNb=queueNb;
space->pid=getpid();
@ -145,11 +161,17 @@ msgSpace * msgSpaceCreate(
msgPoolDataTabClose(space,poolDataTabAddr);
/* on ajoute spaceId a la liste des msgSpace connus */
msgSpaceListElemId listElemId;
msgSpaceListInit();
printf("spaceListInit...\n");
printf("ok\n");
msgSpaceListLock();
printf("spaceListLock...ok\n");
msgSpaceListElemCreate(listElemId,space);
printf("spaceListElemCreate...ok\n");
msgSpaceListAdd(listElemId);
printf("spaceListAdd...ok\n");
msgSpaceListUnlock();
printf("spaceListUnlock...ok\n");
/* on renvoie un pointeur sur le bon spaceId */
msgPoolDataTabUnlock(space);

View file

@ -3,8 +3,11 @@
int msgSpaceListClose(msgSpaceList * list){
msgSpaceListId spaceListId;
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
if (munmap(list,sizeof(msgSpaceList)) < 0){
NZG_ERROR("unmap",msgSpaceListId);
NZG_ERROR("unmap",spaceListId);
goto ERROR;
}

View file

@ -7,7 +7,8 @@ int msgSpaceListElemCreate(
msgSpace * space)
{
strcpy(listElemId,space->id);
msgSpaceListElemIdIntern(listElemId,space->externId);
printf("Creating ListElem %s",listElemId);
int listElemFd;
listElemFd=shm_open(listElemId,
@ -25,6 +26,11 @@ int msgSpaceListElemCreate(
}
close(listElemFd);
msgSpaceListElem * listElem;
listElem=msgSpaceListElemOpen(listElemId);
strcpy(listElem->id,listElemId);
strcpy(listElem->spaceId,space->id);
msgSpaceListElemClose(listElem);
return 0;
ERROR:
return -1;

View file

@ -1,41 +1,52 @@
#include "libnazgul.h"
#include "ids.h"
int msgSpaceListInit(){
int descMemory;
sem_t * spacesListSemFd;
msgSpaceListSemId spacesListSemId;
msgSpaceListElemId spacesListId;
int spaceListFd;
sem_t * spaceListSemFd;
/*Creation de semaphore*/
spacesListSemFd=sem_open(msgSpaceListSemId,O_CREAT|O_EXCL,0666,0);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",msgSpaceListSemId);
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*/
descMemory=shm_open(msgSpaceListId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,0600);
if (descMemory == -1){
descMemory=shm_open(msgSpaceListId,O_RDWR|O_TRUNC,0600);
if (descMemory == -1){
NZG_ERROR("shm_open",spacesListId);
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(descMemory);
close(spaceListFd);
goto EXISTING;
}
}
/*Creation de semaphore*/
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,0);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spacesListSemId);
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;

View file

@ -4,30 +4,29 @@
// verouille le semaphore de la liste
int msgSpaceListLock(){
sem_t * spacesListSemFd;
msgSpaceListSemId spacesListSemId;
sem_t * msgSpaceListSemFd;
msgSpaceListSemId spaceListSemId;
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
/*Ouverture d'un verrou d'un semafore*/
//TODO: remplacer par la bonne valeur d'initialisation du
//semaphore
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,1024);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spacesListSemId);
/* Ouverture d'un semafore */
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,1);
if(msgSpaceListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spaceListSemId);
goto ERROR;
}
/*Pose d'un semaphore et le verrouille*/
if(sem_wait(spacesListSemFd)==-1){
NZG_ERROR("sem_wait",spacesListSemId);
/* Pose d'un semaphore et le verrouille */
if(sem_wait(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_wait",spaceListSemId);
goto ERROR;
}
/* Ferme le semaphore*/
/* if(sem_close(spacesListSemFd)==-1){
NZG_ERROR("sem_close",spacesListSemId);
/* if(sem_close(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_close",spaceListSemId);
return -1;
}*/
sem_close(spacesListSemFd);
sem_close(msgSpaceListSemFd);
return 0;
ERROR:
@ -37,29 +36,31 @@ ERROR:
// deverouille le semaphore de la liste
int msgSpaceListUnlock(){
sem_t * spacesListSemFd;
msgSpaceListSemId spacesListSemId;
sem_t * msgSpaceListSemFd;
msgSpaceListSemId spaceListSemId;
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
/*Ouverture dun semaphore*/
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,1024);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spacesListSemId);
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
if(msgSpaceListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spaceListSemId);
goto ERROR;
}
/*Relachement du semaphore*/
if(sem_post(spacesListSemFd)==-1){
NZG_ERROR("sem_relache",spacesListSemId);
if(sem_post(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_relache",spaceListSemId);
goto ERROR;
}
/* Ferme le semaphore
if(sem_close(spacesListSemFd)==-1){
NZG_ERROR("sem_close",spacesListSemId);
return -1;
}*/
/* Ferme le semaphore */
if(sem_close(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_close",spaceListSemId);
goto ERROR;
}
return 0;
ERROR:

View file

@ -5,10 +5,12 @@ void * msgSpaceListOpen(){
int listFd;
void * listAddr;
msgSpaceListId spaceListId;
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
listFd=shm_open(msgSpaceListId,O_RDWR,SHM_DEFAULT_MODE);
listFd=shm_open(spaceListId,O_RDWR,SHM_DEFAULT_MODE);
if (listFd == -1 ) {
NZG_ERROR("shm_open : msgSpaceList open",msgSpaceListId);
NZG_ERROR("shm_open : msgSpaceList open",spaceListId);
goto ERROR;
}
@ -19,7 +21,7 @@ void * msgSpaceListOpen(){
listFd,
0);
if( listAddr == MAP_FAILED ) {
NZG_ERROR("mmap",msgSpaceListId);
NZG_ERROR("mmap",spaceListId);
goto ERROR;
}