From 0d75ebe2e9df44ba629521fbfc661b3247aae276 Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 25 Feb 2004 22:30:43 +0000 Subject: [PATCH] *** empty log message *** --- src/allocate.c | 2 +- src/spaceCreate.c | 55 +++++++++++++++++++++++++-------------- src/spaceListAdd.c | 15 +++++++---- src/spaceListElemCreate.c | 16 +++++++++--- src/spaceListInit.c | 47 ++++++++++++++++++++++----------- 5 files changed, 91 insertions(+), 44 deletions(-) diff --git a/src/allocate.c b/src/allocate.c index 477b160..5fd7093 100644 --- a/src/allocate.c +++ b/src/allocate.c @@ -188,7 +188,7 @@ if (mSPoolDataTabAddr==NULL){ int bufferFreeSize; bufferFreeSize=mSPoolDataTabAddr[selectedPoolIndex].bufferSize; - printf("BufferSize : %d", bufferFreeSize); + printf("BufferSize : %d\n", bufferFreeSize); resultAddr=msgBufferMap(mSPoolDataTabAddr,selectedPoolIndex,bufferFreeIndex); if (resultAddr==NULL){ diff --git a/src/spaceCreate.c b/src/spaceCreate.c index c88ef35..1126517 100644 --- a/src/spaceCreate.c +++ b/src/spaceCreate.c @@ -21,7 +21,7 @@ msgSpace * msgSpaceCreate( msgSpaceId nzgId; /* msgSpaceList mSList; */ int mSFd; // shm file descriptor - int i; + int i; static int mSIdNum=-1; msgSpace * space; @@ -42,19 +42,34 @@ msgSpace * msgSpaceCreate( return NULL; } - msgSpaceListInit(); + if (msgSpaceListInit() <0){ + NZG_ERROR("msgSpaceListInit",nzgId); + goto ERROR; + }; printf("spaceListInit ok\n"); - msgSpaceListLock(); + if (msgSpaceListLock() <0){ + NZG_ERROR("msgSpaceListLock",""); + goto ERROR; + } printf("spaceListLock ok\n"); - if (msgSpaceListFindId(nzgId) < 1){ - NZG_ERROR("spaceListFindId",nzgId); + int err; + if ((err=msgSpaceListFindId(nzgId)) < 1){ + if (err==0){ + NZG_ERROR("spaceListFindId : existing ",nzgId); + } else { + NZG_ERROR("spaceListFindId : error ",nzgId); + } + msgSpaceListUnlock(); // zut, il y a soit une erreur // soit le msgSpace existe deja // on quitte goto ERROR; } printf("spaceListFind ok\n"); - msgSpaceListUnlock(); + if (msgSpaceListUnlock() < 0){ + NZG_ERROR("msgSpaceListUnlock",""); + goto ERROR; + } printf("spaceListUnlock ok\n"); fprintf(stderr,"Creating msgSpace with id : %s\n",nzgId); @@ -106,8 +121,8 @@ msgSpace * msgSpaceCreate( space->poolDataTabSemId); goto ERROR; } else { - NZG_ERROR("sem_open : creation oki", - space->poolDataTabSemId); +/* NZG_ERROR("sem_open : creation oki", + space->poolDataTabSemId); */ } sem_close(mSDataTabSemFd); @@ -160,21 +175,21 @@ msgSpace * msgSpaceCreate( } msgPoolDataTabClose(space,poolDataTabAddr); /* on ajoute spaceId a la liste des msgSpace connus */ - msgSpaceListElemId listElemId; -printf("spaceListInit...\n"); + msgSpaceListElemId listElemId; + printf("spaceListInit...\n"); -printf("ok\n"); - msgSpaceListLock(); -printf("spaceListLock...ok\n"); - msgSpaceListElemCreate(listElemId,space); -printf("spaceListElemCreate...ok\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"); - + printf("spaceListAdd...ok\n"); + msgSpaceListUnlock(); + printf("spaceListUnlock...ok\n"); + /* on renvoie un pointeur sur le bon spaceId */ - msgPoolDataTabUnlock(space); + msgPoolDataTabUnlock(space); return space; ERROR: return NULL; diff --git a/src/spaceListAdd.c b/src/spaceListAdd.c index e3c96ec..3addfb5 100644 --- a/src/spaceListAdd.c +++ b/src/spaceListAdd.c @@ -6,16 +6,21 @@ int msgSpaceListAdd(msgSpaceListElemId newElemId){ msgSpaceListElem * listOldTailElem; msgSpaceListElem * listNewTailElem; - msgSpaceList * list=NULL; + msgSpaceList * list; list=msgSpaceListOpen(); - + if (list == NULL){ + NZG_ERROR("msgSpaceListOpen",""); + goto ERROR; + } // on informe l'element qui est le dernier listNewTailElem=msgSpaceListElemOpen(newElemId); if (listNewTailElem==NULL){ + NZG_ERROR("msgSpaceListElemOpen",newElemId); + goto ERROR; } - strcpy(listNewTailElem->next,newElemId); - if (msgSpaceListElemClose(listNewTailElem) <0 ){ + strcpy(listNewTailElem->next,newElemId); + if (msgSpaceListElemClose(listNewTailElem) <0 ){ NZG_ERROR("msgSpaceListElemClose",newElemId); goto ERROR; } @@ -23,7 +28,7 @@ int msgSpaceListAdd(msgSpaceListElemId newElemId){ /* verifier si la liste n'est pas vide... */ if((strcmp(list->headId,list->id)==0) && (strcmp(list->tailId,list->id)==0)) { - printf("- premier elem de queue -\n"); + printf("- premier elem de spaceList -\n"); // on donne a la queue l'id de l'element strcpy(list->headId,newElemId); strcpy(list->tailId,newElemId); diff --git a/src/spaceListElemCreate.c b/src/spaceListElemCreate.c index c701fa4..8ba9e00 100644 --- a/src/spaceListElemCreate.c +++ b/src/spaceListElemCreate.c @@ -8,7 +8,6 @@ int msgSpaceListElemCreate( { msgSpaceListElemIdIntern(listElemId,space->externId); - printf("Creating ListElem %s",listElemId); int listElemFd; listElemFd=shm_open(listElemId, @@ -20,7 +19,7 @@ int msgSpaceListElemCreate( goto ERROR; } - if (ftruncate(listElemFd, sizeof(msgQueueElem)) < 0){ + if (ftruncate(listElemFd, sizeof(msgSpaceListElem)) < 0){ NZG_ERROR("ftruncate", listElemId); goto ERROR; } @@ -28,9 +27,20 @@ int msgSpaceListElemCreate( close(listElemFd); msgSpaceListElem * listElem; listElem=msgSpaceListElemOpen(listElemId); + if (listElem ==NULL){ + NZG_ERROR("msgSpaceListElemOpen",listElemId); + goto ERROR; + } strcpy(listElem->id,listElemId); + strcpy(listElem->next,listElemId); strcpy(listElem->spaceId,space->id); - msgSpaceListElemClose(listElem); + printf("[ ListElem : id %s,next: %s, Sid: %s ]\n", + listElem->id, + listElem->next, + listElem->spaceId); + if (msgSpaceListElemClose(listElem) <0){ + NZG_ERROR("msgSpaceListElemClose",listElemId); + } return 0; ERROR: return -1; diff --git a/src/spaceListInit.c b/src/spaceListInit.c index 1353965..b1e052b 100644 --- a/src/spaceListInit.c +++ b/src/spaceListInit.c @@ -15,17 +15,19 @@ int msgSpaceListInit(){ if(spaceListSemFd==SEM_FAILED){ spaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0); if(spaceListSemFd==SEM_FAILED){ - NZG_ERROR("sem_open",spaceListSemId); - goto ERROR; + 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); + spaceListFd=shm_open(spaceListId, + O_RDWR|O_CREAT|O_EXCL|O_TRUNC, + 0666); if (spaceListFd == -1){ - spaceListFd=shm_open(spaceListId,O_RDWR|O_TRUNC,0600); + spaceListFd=shm_open(spaceListId,O_RDWR,0666); if (spaceListFd == -1){ NZG_ERROR("shm_open",spaceListId); goto ERROR; @@ -34,25 +36,40 @@ int msgSpaceListInit(){ goto EXISTING; } } -if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){ + if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){ NZG_ERROR("ftruncate",spaceListId); goto ERROR; } -close(spaceListFd); + close(spaceListFd); - msgSpaceList *list; - list=msgSpaceListOpen(); - strcpy(list->id,spaceListId); - strcpy(list->headId,spaceListId); - strcpy(list->tailId,spaceListId); - msgSpaceListClose(list); - - msgSpaceListUnlock(); + 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; + } return 0; ERROR: return -1; EXISTING: + if (msgSpaceListUnlock() < 0){ + NZG_ERROR("msgSpaceListUnlock",""); + goto ERROR; + } + return 0; };