--- libaitio/src/sess.c 2014/02/08 22:06:17 1.5 +++ libaitio/src/sess.c 2016/08/18 09:06:31 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sess.c,v 1.5 2014/02/08 22:06:17 misho Exp $ +* $Id: sess.c,v 1.6 2016/08/18 09:06:31 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2014 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -215,6 +215,7 @@ map_createSession(int nSeed, long nSize, sess_t * __re { char szSName[2][FILENAME_MAX]; va_list lst; + struct stat st; if (!Sess || !*Sess->sess_name) return -1; @@ -237,13 +238,13 @@ map_createSession(int nSeed, long nSize, sess_t * __re memset(szSName, 0, sizeof szSName); snprintf(szSName[0], SEMNAME_MAX, "/%X.ANS", (u_int) Sess->sess_key); #ifdef HAVE_SHM_OPEN - snprintf(szSName[1], FILENAME_MAX, "/%s-%x.ANM", Sess->sess_name, (u_int) Sess->sess_key); + snprintf(szSName[1], FILENAME_MAX, "/%X.ANM", (u_int) Sess->sess_key); #else snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->sess_name, (u_int) Sess->sess_key); #endif /* create semaphore & add 1 */ - Sess->sess_id.sid = sem_open(szSName[0], O_CREAT, SESS_MEM_MODE); + Sess->sess_id.sid = sem_open(szSName[0], O_CREAT, SESS_MEM_MODE, 0); if (Sess->sess_id.sid == SEM_FAILED) { LOGERR; map_destroySession(Sess); @@ -264,7 +265,12 @@ map_createSession(int nSeed, long nSize, sess_t * __re map_destroySession(Sess); return -1; } - if (!Sess->sess_zcpy) { + if (fstat(Sess->sess_mem.fd, &st) == -1) { + LOGERR; + map_destroySession(Sess); + return -1; + } + if (st.st_size < nSize) { /* #ifdef HAVE_SHM_OPEN */ if (ftruncate(Sess->sess_mem.fd, nSize) == -1) { LOGERR;