*** 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

@ -7,8 +7,8 @@ typedef enum { true=1, false=0} bool;
typedef char msgSpaceId[MSGSPACE_ID_LEN];
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListElemId[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 */
/* 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

@ -2,9 +2,12 @@
#include "ids.h"
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,47 +1,58 @@
#include "libnazgul.h"
#include "ids.h"
int msgSpaceListInit(){
int descMemory;
sem_t * spacesListSemFd;
msgSpaceListSemId spacesListSemId;
msgSpaceListElemId spacesListId;
/*Creation de semaphore*/
spacesListSemFd=sem_open(msgSpaceListSemId,O_CREAT|O_EXCL,0666,0);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",msgSpaceListSemId);
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);
goto ERROR;
} else {
close(descMemory);
goto EXISTING;
}
}
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;
}
}
/*Creation de semaphore*/
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,0);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spacesListSemId);
goto ERROR;
}
msgSpaceListUnlock();
/*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);
return 0;
msgSpaceList *list;
list=msgSpaceListOpen();
strcpy(list->id,spaceListId);
strcpy(list->headId,spaceListId);
strcpy(list->tailId,spaceListId);
msgSpaceListClose(list);
msgSpaceListUnlock();
return 0;
ERROR:
return -1;
return -1;
EXISTING:
return 0;
return 0;
};

View file

@ -4,65 +4,66 @@
// 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);
goto ERROR;
}
/* 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);
goto ERROR;
}
/* 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);
return -1;
}*/
sem_close(spacesListSemFd);
/* Ferme le semaphore*/
/* if(sem_close(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_close",spaceListSemId);
return -1;
}*/
sem_close(msgSpaceListSemFd);
return 0;
return 0;
ERROR:
return -1;
return -1;
}
// deverouille le semaphore de la liste
int msgSpaceListUnlock(){
sem_t * spacesListSemFd;
msgSpaceListSemId spacesListSemId;
/*Ouverture dun semaphore*/
spacesListSemFd=sem_open(spacesListSemId,O_CREAT|O_EXCL,0666,1024);
if(spacesListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spacesListSemId);
goto ERROR;
}
sem_t * msgSpaceListSemFd;
msgSpaceListSemId spaceListSemId;
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
/*Relachement du semaphore*/
if(sem_post(spacesListSemFd)==-1){
NZG_ERROR("sem_relache",spacesListSemId);
goto ERROR;
}
/*Ouverture dun semaphore*/
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
if(msgSpaceListSemFd==SEM_FAILED){
NZG_ERROR("sem_open",spaceListSemId);
goto ERROR;
}
/* Ferme le semaphore
if(sem_close(spacesListSemFd)==-1){
NZG_ERROR("sem_close",spacesListSemId);
return -1;
}*/
/*Relachement du semaphore*/
if(sem_post(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_relache",spaceListSemId);
goto ERROR;
}
return 0;
/* Ferme le semaphore */
if(sem_close(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_close",spaceListSemId);
goto ERROR;
}
return 0;
ERROR:
return -1;
return -1;
};

View file

@ -5,10 +5,12 @@ void * msgSpaceListOpen(){
int listFd;
void * listAddr;
listFd=shm_open(msgSpaceListId,O_RDWR,SHM_DEFAULT_MODE);
msgSpaceListId spaceListId;
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
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;
}