From 2c932cb2db712f417953c527cbda8f5aa89af6d6 Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 25 Feb 2004 10:32:41 +0000 Subject: [PATCH] *** empty log message *** --- src/allocate.c | 4 ++++ src/poolCreate.c | 4 +++- src/poolDataTabCreate.c | 42 +++++++++++++++++++++++++++++++++++++++++ src/proto.h | 2 +- src/put.c | 5 ++++- src/queueInit.c | 6 ++++-- src/spaceCreate.c | 30 ++++++++++++++++++++--------- test/create_delete.c | 6 +++++- test/put_get.c | 7 ++++++- 9 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 src/poolDataTabCreate.c diff --git a/src/allocate.c b/src/allocate.c index 7c64673..0f00688 100644 --- a/src/allocate.c +++ b/src/allocate.c @@ -36,6 +36,10 @@ void * msgAllocate(msgSpace *space, mSPoolDataTabAddr=msgPoolDataTabOpen(space); +if (mSPoolDataTabAddr==NULL){ + NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId); + goto ERROR; +} /* // verifier le premier arg du shm_open mSPoolDataTabFd=shm_open(space->poolDataTabId, diff --git a/src/poolCreate.c b/src/poolCreate.c index f23d218..99c60af 100644 --- a/src/poolCreate.c +++ b/src/poolCreate.c @@ -41,7 +41,7 @@ int msgPoolCreate( ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL,SEM_DEFAULT_MODE, buffNb); if (ressourceSemFd == SEM_FAILED){ NZG_ERROR("sem_open : creation de la ressource",poolRessourceSemId); - return -1; + goto ERROR; } else { NZG_ERROR("sem_open : creation oki",poolRessourceSemId); } @@ -55,5 +55,7 @@ int msgPoolCreate( close(poolFd); return 0; +ERROR: + return -1; } diff --git a/src/poolDataTabCreate.c b/src/poolDataTabCreate.c new file mode 100644 index 0000000..c6adfda --- /dev/null +++ b/src/poolDataTabCreate.c @@ -0,0 +1,42 @@ +#include "libnazgul.h" +#include "ids.h" + +void * msgPoolDataTabCreate(msgSpace * space){ + int poolDataFd; // shm file descriptor + msgPoolData * poolDataTabAddr; + poolDataFd=shm_open( + space->poolDataTabId, + O_RDWR|O_CREAT|O_EXCL|O_TRUNC, + MSGSPACE_DEFAULT_MODE + ); + if (poolDataFd == -1 ) { + NZG_ERROR("shm_open :create",space->poolDataTabId); + goto ERROR; + } + + /* allocation de la bonne zone mémoire pour le poolData */ + if (ftruncate(poolDataFd, (space->poolNb)*sizeof(msgPoolData)) == -1){ + NZG_ERROR("ftruncate",space->poolDataTabId); + goto ERROR; + } + + close(poolDataFd); + poolDataTabAddr = msgPoolDataTabOpen(space); + if (poolDataTabAddr == NULL){ + NZG_ERROR("msgPoolDataTabOpen : create",space->poolDataTabId); + goto ERROR; + } + /*mmap( 0, sizeof( *mSAddr ), + PROT_READ | PROT_WRITE, + MAP_SHARED, mSFd, 0 ); + if( poolDataAddr == MAP_FAILED ) { + NZG_ERROR("mmap",poolDataTabId); + goto ERROR; + }*/ + + return poolDataTabAddr; +ERROR: + return NULL; +} + + diff --git a/src/proto.h b/src/proto.h index e748f47..b5ea101 100644 --- a/src/proto.h +++ b/src/proto.h @@ -67,7 +67,7 @@ int msgQueueElemDelete(msgQueueElemId queueElemId); /* queueElemOpen.c */ void *msgQueueElemOpen(msgQueueElemId queueElemId); /* queueInit.c */ -msgQueue *queueInit(msgSpaceId externId, int queueIdx); +msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx); /* queueOpen.c */ void *msgQueueOpen(msgQueueId queueId); /* queueProtLock.c */ diff --git a/src/put.c b/src/put.c index 3c0eb79..50cab6e 100644 --- a/src/put.c +++ b/src/put.c @@ -8,7 +8,10 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ int err; msgPoolDataTabLock(space); poolDataTabAddr=msgPoolDataTabOpen(space); - + if (poolDataTabAddr == NULL){ + NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId); + goto ERROR; + } err=msgBufferGetProcAttach( poolDataTabAddr, space->poolNb, diff --git a/src/queueInit.c b/src/queueInit.c index 13d7fb7..ef524df 100644 --- a/src/queueInit.c +++ b/src/queueInit.c @@ -1,7 +1,7 @@ #include "libnazgul.h" #include "ids.h" -msgQueue * queueInit(msgSpaceId externId, int queueIdx) { +msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) { int queueFd; msgQueue * queue; sem_t * semProtectFd; @@ -12,9 +12,11 @@ msgQueue * queueInit(msgSpaceId externId, int queueIdx) { queue = NULL; + printf("ploped init queue ?\n"); + msgQueueProtSemIdIntern(queueSemProtectId,externId,queueIdx); msgQueueReadSemIdIntern(queueSemReadableId,externId,queueIdx); - + // creation du semaphore de lecture semReadableFd = sem_open(queueSemReadableId, O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0); diff --git a/src/spaceCreate.c b/src/spaceCreate.c index c8b676a..7dacd25 100644 --- a/src/spaceCreate.c +++ b/src/spaceCreate.c @@ -49,14 +49,13 @@ msgSpace * msgSpaceCreate( ); if (mSFd == -1 ) { NZG_ERROR("shm_open : msgSpace creation",nzgId); - return NULL; + goto ERROR; } /* on redimentionne l'element */ if (ftruncate(mSFd, sizeof(* space)) == -1){ - fprintf( stderr, "msgSpace resizing failed: %s\n", - strerror( errno ) ); - return NULL; + NZG_ERROR("ftruncate",nzgId); + goto ERROR; } /* Map the memory object */ @@ -64,9 +63,8 @@ msgSpace * msgSpaceCreate( PROT_READ | PROT_WRITE, MAP_SHARED, mSFd, 0 ); if( space == MAP_FAILED ) { - fprintf( stderr, "mmap failed: %s\n", - strerror( errno ) ); - return NULL; + NZG_ERROR("mmap",nzgId); + goto ERROR; } printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)space,(int)getpid()); @@ -90,7 +88,7 @@ msgSpace * msgSpaceCreate( if (mSDataTabSemFd == SEM_FAILED){ NZG_ERROR("sem_open : creation de la ressource", space->poolDataTabSemId); - return NULL; + goto ERROR; } else { NZG_ERROR("sem_open : creation oki", space->poolDataTabSemId); @@ -100,7 +98,11 @@ msgSpace * msgSpaceCreate( // msgPoolDataTabLock(space); /* attacher le tableau des msgPoolData */ - poolDataTabAddr=msgPoolDataTabCreate(space); + poolDataTabAddr=msgPoolDataTabCreate(space); + if (poolDataTabAddr == NULL){ + NZG_ERROR("msgPoolDataTabCreate",space->poolDataTabId); + goto ERROR; + } for (i=0;iexternId,i) < 0){ + printf("fail.\n"); + NZG_ERROR("msgQueueInit : queue ?? for",space->externId); + goto ERROR; + } + printf("ok.\n"); + } msgPoolDataTabClose(space,poolDataTabAddr); /* TODO: on ajoute spaceId a la liste des msgSpace connus */ /* TODO: on crée queueNb files de messages */ diff --git a/test/create_delete.c b/test/create_delete.c index 3fd2fe6..d0e6572 100644 --- a/test/create_delete.c +++ b/test/create_delete.c @@ -22,7 +22,11 @@ int main(void) { printf("RequestedId: %s\n",testId); printf("Void size: %d\n",sizeof(void)); mSPAC=msgSpaceCreate(testId,0,3,poolInfos); - + if (mSPAC ==NULL) { + NZG_ERROR("msgSpaceCreate",testId); + exit(0); + } + pid_t pid=fork(); diff --git a/test/put_get.c b/test/put_get.c index 0b9230b..8bfe94c 100644 --- a/test/put_get.c +++ b/test/put_get.c @@ -20,7 +20,12 @@ int main(void) { printf("Void size: %d\n",sizeof(void)); //creation de l'espace de messages mSPAC=msgSpaceCreate(testId,1,2,poolInfos); - + if (mSPAC ==NULL) { + NZG_ERROR("msgSpaceCreate",testId); + exit(0); + } + + printf("CREATION ------------------ ok\n"); pid_t pid=fork(); if (pid ==0){