Index: /trunk/zoo-project/zoo-kernel/configure.ac
===================================================================
--- /trunk/zoo-project/zoo-kernel/configure.ac	(revision 513)
+++ /trunk/zoo-project/zoo-kernel/configure.ac	(revision 514)
@@ -446,5 +446,5 @@
 	then
 		JAVA_LDFLAGS="-framework JavaVM"
-		JAVA_CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/"
+		JAVA_CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/"
 	else
 		if test -d "$JDKHOME/jre/lib/i386";
Index: /trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.h	(revision 513)
+++ /trunk/zoo-project/zoo-kernel/service.h	(revision 514)
@@ -41,4 +41,16 @@
 #define zWrite _write
 #define zSleep Sleep
+#include <sys/timeb.h>
+struct ztimeval {
+  long tv_sec; /* seconds */
+  long tv_usec; /* and microseconds */
+};
+void zGettimeofday(struct mstimeval* tp, void* tzp)
+{
+  struct _timeb theTime;
+  _ftime(&theTime);
+  tp->tv_sec = theTime.time;
+  tp->tv_usec = theTime.millitm * 1000;
+}
 #else
 #define zStrdup strdup
@@ -47,4 +59,6 @@
 #define zWrite write
 #define zSleep sleep
+#define zGettimeofday gettimeofday
+#define ztimeval timeval
 #endif 
 
Index: /trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 513)
+++ /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 514)
@@ -125,7 +125,9 @@
 
 char* getKeyValue(maps* conf){
+  if(conf==NULL)
+     return "700666";
   map *tmpMap=getMapFromMaps(conf,"lenv","lid");
   if(tmpMap==NULL)
-    tmpMap=getMapFromMaps(conf,"lenv","sid");
+    tmpMap=getMapFromMaps(conf,"lenv","usid");
   char* key="-1";
   if(tmpMap!=NULL){
@@ -202,5 +204,5 @@
   char *s=NULL;
   map *tmpMap1;
-  map *tmpMap=getMapFromMaps(conf,"lenv","sid");
+  map *tmpMap=getMapFromMaps(conf,"lenv","usid");
   semid lockid=getShmLockId(conf,1);
   if(lockid==NULL){
@@ -337,7 +339,9 @@
 
 int getKeyValue(maps* conf){
+  if(conf==NULL)
+     return 700666;
   map *tmpMap=getMapFromMaps(conf,"lenv","lid");
   if(tmpMap==NULL)
-    tmpMap=getMapFromMaps(conf,"lenv","sid");
+    tmpMap=getMapFromMaps(conf,"lenv","usid");
   int key=-1;
   if(tmpMap!=NULL)
@@ -449,5 +453,5 @@
   void *shm;
   struct shmid_ds shmids;
-  map *tmpMap=getMapFromMaps(conf,"lenv","sid");
+  map *tmpMap=getMapFromMaps(conf,"lenv","usid");
   if(tmpMap!=NULL){
     key=atoi(tmpMap->value);
@@ -531,5 +535,7 @@
 #endif
     }else{
-      return (char*)shm;
+      char *ret=strdup((char*)shm);
+      shmdt((void *)shm);
+      return ret;
     }
   }
@@ -1718,5 +1724,5 @@
       map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
       map *tmp_lenv=NULL;
-      tmp_lenv=getMapFromMaps(m,"lenv","sid");
+      tmp_lenv=getMapFromMaps(m,"lenv","usid");
       if(tmp_lenv==NULL)
 	sprintf(currentSid,"%i",pid);
@@ -1735,17 +1741,23 @@
       }
     }else{
-      map* tmpm2=getMap(tmp_maps->content,"tmpUrl");
+      int lpid;
+      map* tmpm2=getMapFromMaps(m,"lenv","usid");
+      lpid=atoi(tmpm2->value);
+      tmpm2=getMap(tmp_maps->content,"tmpUrl");
       if(tmpm1!=NULL && tmpm2!=NULL){
 	if( strncasecmp( tmpm2->value, "http://", 7) == 0 ||
 	    strncasecmp( tmpm2->value, "https://", 8 ) == 0 ){
-	  sprintf(url,"%s/%s_%i.xml",tmpm2->value,service,pid);
+	  sprintf(url,"%s/%s_%i.xml",tmpm2->value,service,lpid);
 	}else
-	  sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid);
+	  sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,lpid);
       }
     }
     if(tmpm1!=NULL)
       sprintf(tmp,"%s",tmpm1->value);
+    int lpid;
+    tmpm1=getMapFromMaps(m,"lenv","usid");
+    lpid=atoi(tmpm1->value);
     tmpm1=getMapFromMaps(m,"main","TmpPath");
-    sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid);
+    sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,lpid);
   }
 
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 513)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 514)
@@ -2504,5 +2504,13 @@
   _tmpMaps->name=zStrdup("lenv");
   char tmpBuff[100];
-  sprintf(tmpBuff,"%i",(cpid+(int)time(NULL)));
+  int lid=getShmLockId(NULL,1);
+  lockShm(lid);
+  struct ztimeval tp;
+  if(zGettimeofday(&tp,NULL)==0)
+    sprintf(tmpBuff,"%i",(cpid+((int)tp.tv_sec+(int)tp.tv_usec)));
+  else
+    sprintf(tmpBuff,"%i",(cpid+(int)time(NULL)));
+  unlockShm(lid);
+  removeShmLock(NULL,1);
   _tmpMaps->content=createMap("usid",tmpBuff);
   _tmpMaps->next=NULL;
@@ -2575,5 +2583,5 @@
   freeMaps(&_tmpMaps);
   free(_tmpMaps);
-  
+
 #ifdef DEBUG
   dumpMap(request_inputs);
@@ -2634,4 +2642,6 @@
       zSleep(1);
 #endif
+      r_inputs=getMapFromMaps(m,"lenv","usid");
+      int cpid=atoi(r_inputs->value);
       r_inputs=getMapFromMaps(m,"main","tmpPath");
       map* r_inputs1=getMap(s1->content,"ServiceProvider");
