From 34e2d07f7d80d95701012ceece3c35ae52772aa1 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 17 Sep 2019 14:07:51 +0200 Subject: [PATCH] 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 --- src/Makefile | 26 +++++++++++++++++++------- src/nzg_global.h | 1 + src/nzg_list.c | 10 +++++----- src/nzg_pool.c | 8 ++++++-- src/nzg_proto.h | 2 +- src/nzg_spaces.c | 9 +++++++-- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/Makefile b/src/Makefile index 7da086b..045eca0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,6 @@ ### HEADER HERE -# @CLASSPATH=$(CLASSPATH) $(JAVAC) $(JFLAGS) $< - -#INCLUDES=-I/ -#LIBINC=-L -#LIBS= - +OS=$(shell uname -s) CC=gcc CFLAGS=-ggdb -Wall -O2 #-O2 @@ -20,6 +15,21 @@ CFILES := $(shell ls *.c) OFILES := $(patsubst %.c,%.o,$(CFILES)) 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 build : $(OFILES) @@ -32,5 +42,7 @@ clean: @rm -f *.o %.o : %.c - $(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) -o $*.o + $(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) $(DEFINES) -o $*.o +edit: + gvim *.c *.h diff --git a/src/nzg_global.h b/src/nzg_global.h index 34a84fa..57f26ab 100644 --- a/src/nzg_global.h +++ b/src/nzg_global.h @@ -11,4 +11,5 @@ #include #define PAGESIZE sysconf(_SC_PAGESIZE) + #endif diff --git a/src/nzg_list.c b/src/nzg_list.c index b270c71..005c0bb 100644 --- a/src/nzg_list.c +++ b/src/nzg_list.c @@ -1,10 +1,10 @@ -#include #include "libnazgul.h" -char ** msgSpaceIdList(){ +/* +void msgSpaceIdList(msgSpaceListId){ // i = le nombre d'id publics disponnibles int i=0; - char ** idList; - idList=(char **)malloc(i*sizeof(char *)); - return idList; + msgSpaceListId idList; + return; } +*/ diff --git a/src/nzg_pool.c b/src/nzg_pool.c index c807c3f..6bf5dd6 100644 --- a/src/nzg_pool.c +++ b/src/nzg_pool.c @@ -28,7 +28,7 @@ int msgPoolCreate( // on met le pool a la taille voulue pour qu'il // puisse contenir les buffs - if (ftruncate(poolFd, sizeof((buffSize)*buffNb)) == -1){ + if (ftruncate(poolFd, (buffSize*buffNb)) == -1){ fprintf( stderr, "msgPool resizing failed: %s\n", strerror( errno ) ); return -1; @@ -43,7 +43,11 @@ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){ if (strlen(src)>MSGSPACE_ID_LEN){ 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; } diff --git a/src/nzg_proto.h b/src/nzg_proto.h index 3ab05eb..ee3a9dd 100644 --- a/src/nzg_proto.h +++ b/src/nzg_proto.h @@ -2,7 +2,7 @@ #define _NZG_PROTO 1 /* nzg_list.c */ -char **msgSpaceIdList(void); +/* msgSpaceListId msgSpaceIdList(void); */ /* nzg_pool.c */ int msgPoolCreate(msgSpacePoolId poolId, int buffNb, int buffSize); int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num); diff --git a/src/nzg_spaces.c b/src/nzg_spaces.c index 7aa57c9..025e44c 100644 --- a/src/nzg_spaces.c +++ b/src/nzg_spaces.c @@ -27,7 +27,8 @@ msgSpace * msgSpaceCreate( /** on créee le nouvel element **/ printf("PAGESIZE : %d\n",(int)PAGESIZE); - msgSp2nzgId(spaceId,nzgId); + msgSp2nzgId(nzgId,spaceId); + printf("Id interne : %s\n",nzgId); mSFd=shm_open( nzgId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, @@ -41,7 +42,7 @@ msgSpace * msgSpaceCreate( } //on redimentionne l'element - if (ftruncate(mSFd, sizeof(PAGESIZE)) == -1){ + if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){ fprintf( stderr, "msgSpace resizing failed: %s\n", strerror( errno ) ); return NULL; @@ -116,6 +117,10 @@ int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){ return -1; } /* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */ +#ifdef _NZG_REALFILEID + sprintf(dest,"/tmp/nzgSpace%s",(char *)src); +#else sprintf(dest,"/nzgSpace%s",(char *)src); +#endif return 0; }