*** 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){ if (!gotRessourceSem){
msgPoolSemIdIntern(ressourceSemId,space->id,selectedPoolIndex); msgPoolSemIdIntern(ressourceSemId,space->externId,selectedPoolIndex);
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0); ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if(ressourceSemFd==SEM_FAILED){ if(ressourceSemFd==SEM_FAILED){
NZG_ERROR("sem_open",ressourceSemId); NZG_ERROR("sem_open",ressourceSemId);

View file

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

View file

@ -25,6 +25,19 @@
#define SEM_FAILED ((sem_t *)0) #define SEM_FAILED ((sem_t *)0)
#endif #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__); #define NZG_ERROR(func,str) fprintf(stderr,"*** %s: %s***\n%s in %s:%d\n",func,strerror(errno),str,__FILE__,__LINE__);
#endif #endif

View file

@ -2,17 +2,7 @@
#define _NZG_IDS 1 #define _NZG_IDS 1
#include "libnazgul.h" #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 */ /* nzg_ids.c */

View file

@ -7,8 +7,8 @@ typedef enum { true=1, false=0} bool;
typedef char msgSpaceId[MSGSPACE_ID_LEN]; typedef char msgSpaceId[MSGSPACE_ID_LEN];
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN]; typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN]; typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN]; typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN]; typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN];

View file

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

View file

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

View file

@ -2,9 +2,12 @@
#include "ids.h" #include "ids.h"
int msgSpaceListClose(msgSpaceList * list){ int msgSpaceListClose(msgSpaceList * list){
msgSpaceListId spaceListId;
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
if (munmap(list,sizeof(msgSpaceList)) < 0){ if (munmap(list,sizeof(msgSpaceList)) < 0){
NZG_ERROR("unmap",msgSpaceListId); NZG_ERROR("unmap",spaceListId);
goto ERROR; goto ERROR;
} }

View file

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

View file

@ -1,47 +1,58 @@
#include "libnazgul.h" #include "libnazgul.h"
#include "ids.h"
int msgSpaceListInit(){ int msgSpaceListInit(){
int descMemory; int spaceListFd;
sem_t * spacesListSemFd; sem_t * spaceListSemFd;
msgSpaceListSemId spacesListSemId;
msgSpaceListElemId spacesListId; msgSpaceListSemId spaceListSemId;
msgSpaceListId spaceListId;
/*Creation de semaphore*/ strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
spacesListSemFd=sem_open(msgSpaceListSemId,O_CREAT|O_EXCL,0666,0); strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",msgSpaceListSemId); /* Creation de semaphore */
goto ERROR; 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);
/*Fait un segment de memoir partager sur espace de listelement*/ goto ERROR;
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);
goto ERROR;
} else {
close(descMemory);
goto EXISTING;
}
}
/*Creation de semaphore*/ /*Fait un segment de memoir partager sur espace de listelement*/
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,0); spaceListFd=shm_open(spaceListId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,0600);
if(spacesListSemFd==SEM_FAILED){ if (spaceListFd == -1){
NZG_ERROR("sem_open",spacesListSemId); spaceListFd=shm_open(spaceListId,O_RDWR|O_TRUNC,0600);
goto ERROR; if (spaceListFd == -1){
} NZG_ERROR("shm_open",spaceListId);
msgSpaceListUnlock(); goto ERROR;
} else {
close(spaceListFd);
goto EXISTING;
}
}
if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){
NZG_ERROR("ftruncate",spaceListId);
goto ERROR;
}
close(spaceListFd);
return 0; msgSpaceList *list;
list=msgSpaceListOpen();
strcpy(list->id,spaceListId);
strcpy(list->headId,spaceListId);
strcpy(list->tailId,spaceListId);
msgSpaceListClose(list);
msgSpaceListUnlock();
return 0;
ERROR: ERROR:
return -1; return -1;
EXISTING: EXISTING:
return 0; return 0;
}; };

View file

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

View file

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