Use real paths for msgSpace depending on NZG_REALFILEID

* PREPROCESSING : l'id differe en fonction du systeme (squash)
* Better handling of a return value (MAP_FAILED)
* Fix allocation size
This commit is contained in:
Glenn Y. Rolland 2019-09-17 14:07:51 +02:00
parent de9ff87b09
commit 34e2d07f7d
6 changed files with 39 additions and 17 deletions

View file

@ -1,11 +1,6 @@
### HEADER HERE ### HEADER HERE
# @CLASSPATH=$(CLASSPATH) $(JAVAC) $(JFLAGS) $< OS=$(shell uname -s)
#INCLUDES=-I/
#LIBINC=-L
#LIBS=
CC=gcc CC=gcc
CFLAGS=-ggdb -Wall -O2 CFLAGS=-ggdb -Wall -O2
#-O2 #-O2
@ -20,6 +15,21 @@ CFILES := $(shell ls *.c)
OFILES := $(patsubst %.c,%.o,$(CFILES)) OFILES := $(patsubst %.c,%.o,$(CFILES))
DESTFILE=libnazgul.a DESTFILE=libnazgul.a
DEFINES:=
ifeq "SunOS" "${OS}"
DEFINES:=-D_NZG_REALFILEID
endif
ifeq "HP-UX" "${OS}"
DEFINES:=-D_NZG_REALFILEID
endif
ifeq "Linux" "${OS}"
#DEFINES:=-D_NZG_REALFILEID
endif
all: build all: build
build : $(OFILES) build : $(OFILES)
@ -32,5 +42,7 @@ clean:
@rm -f *.o @rm -f *.o
%.o : %.c %.o : %.c
$(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) -o $*.o $(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) $(DEFINES) -o $*.o
edit:
gvim *.c *.h

View file

@ -11,4 +11,5 @@
#include <errno.h> #include <errno.h>
#define PAGESIZE sysconf(_SC_PAGESIZE) #define PAGESIZE sysconf(_SC_PAGESIZE)
#endif #endif

View file

@ -1,10 +1,10 @@
#include <stdlib.h>
#include "libnazgul.h" #include "libnazgul.h"
char ** msgSpaceIdList(){ /*
void msgSpaceIdList(msgSpaceListId){
// i = le nombre d'id publics disponnibles // i = le nombre d'id publics disponnibles
int i=0; int i=0;
char ** idList; msgSpaceListId idList;
idList=(char **)malloc(i*sizeof(char *)); return;
return idList;
} }
*/

View file

@ -28,7 +28,7 @@ int msgPoolCreate(
// on met le pool a la taille voulue pour qu'il // on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs // puisse contenir les buffs
if (ftruncate(poolFd, sizeof((buffSize)*buffNb)) == -1){ if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
fprintf( stderr, "msgPool resizing failed: %s\n", fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return -1; return -1;
@ -43,7 +43,11 @@ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){
if (strlen(src)>MSGSPACE_ID_LEN){ if (strlen(src)>MSGSPACE_ID_LEN){
return -1; return -1;
} }
sprintf(dest,"/nzgSpacesPool%s%d",(char *)src,num); #ifdef _NZG_REALFILEID
sprintf(dest,"/tmp/nzgSpacePool%s%d",(char *)src,num);
#else
sprintf(dest,"/nzgSpacePool%s%d",(char *)src,num);
#endif
return 0; return 0;
} }

View file

@ -2,7 +2,7 @@
#define _NZG_PROTO 1 #define _NZG_PROTO 1
/* nzg_list.c */ /* nzg_list.c */
char **msgSpaceIdList(void); /* msgSpaceListId msgSpaceIdList(void); */
/* nzg_pool.c */ /* nzg_pool.c */
int msgPoolCreate(msgSpacePoolId poolId, int buffNb, int buffSize); int msgPoolCreate(msgSpacePoolId poolId, int buffNb, int buffSize);
int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num); int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num);

View file

@ -27,7 +27,8 @@ msgSpace * msgSpaceCreate(
/** on créee le nouvel element **/ /** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE); printf("PAGESIZE : %d\n",(int)PAGESIZE);
msgSp2nzgId(spaceId,nzgId); msgSp2nzgId(nzgId,spaceId);
printf("Id interne : %s\n",nzgId);
mSFd=shm_open( mSFd=shm_open(
nzgId, nzgId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC, O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
@ -41,7 +42,7 @@ msgSpace * msgSpaceCreate(
} }
//on redimentionne l'element //on redimentionne l'element
if (ftruncate(mSFd, sizeof(PAGESIZE)) == -1){ if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){
fprintf( stderr, "msgSpace resizing failed: %s\n", fprintf( stderr, "msgSpace resizing failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return NULL;
@ -116,6 +117,10 @@ int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){
return -1; return -1;
} }
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */ /* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
#ifdef _NZG_REALFILEID
sprintf(dest,"/tmp/nzgSpace%s",(char *)src);
#else
sprintf(dest,"/nzgSpace%s",(char *)src); sprintf(dest,"/nzgSpace%s",(char *)src);
#endif
return 0; return 0;
} }