version 1.1.1.1, 2008/08/28 13:18:30
|
version 1.1.1.1.2.3, 2010/08/26 00:06:38
|
Line 1
|
Line 1
|
|
/************************************************************************* |
|
* (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com> |
|
* by Michael Pounov <misho@openbsd-bg.org> |
|
* |
|
* $Author$ |
|
* $Id$ |
|
* |
|
*************************************************************************/ |
#include "global.h" |
#include "global.h" |
#include "aitsess.h" |
#include "aitsess.h" |
|
|
Line 63 inline int initSession(const int cnID, const char *csF
|
Line 71 inline int initSession(const int cnID, const char *csF
|
if (!access(csFName, F_OK)) |
if (!access(csFName, F_OK)) |
ret = 1; |
ret = 1; |
// Build new key & new session |
// Build new key & new session |
h = open(csFName, O_WRONLY | O_CREAT, 0640); | h = open(csFName, O_WRONLY | O_CREAT, MEM_MODE); |
if (h == -1) { |
if (h == -1) { |
LOGERR; |
LOGERR; |
free(*Sess); |
free(*Sess); |
Line 152 int map_createSession(const char *csFName, const int c
|
Line 160 int map_createSession(const char *csFName, const int c
|
memset(mem, 0, cnSize); |
memset(mem, 0, cnSize); |
|
|
// create semaphore & add 1 |
// create semaphore & add 1 |
(*Sess)->id.sid = sem_open(szSName[0], O_CREAT, 0644); | (*Sess)->id.sid = sem_open(szSName[0], O_CREAT, MEM_MODE); |
if ((*Sess)->id.sid == SEM_FAILED) { |
if ((*Sess)->id.sid == SEM_FAILED) { |
LOGERR; |
LOGERR; |
map_destroySession(csFName, Sess); |
map_destroySession(csFName, Sess); |
Line 162 int map_createSession(const char *csFName, const int c
|
Line 170 int map_createSession(const char *csFName, const int c
|
sem_post((*Sess)->id.sid); |
sem_post((*Sess)->id.sid); |
|
|
// create file for shared memory storage |
// create file for shared memory storage |
(*Sess)->mem.fd = open(szSName[1], O_RDWR | O_CREAT, 0644); | (*Sess)->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
if ((*Sess)->mem.fd == -1) { |
if ((*Sess)->mem.fd == -1) { |
LOGERR; |
LOGERR; |
map_destroySession(csFName, Sess); |
map_destroySession(csFName, Sess); |
Line 252 int ipc_createSession(const char *csFName, const int c
|
Line 260 int ipc_createSession(const char *csFName, const int c
|
} |
} |
|
|
// create semaphore |
// create semaphore |
(*Sess)->id.semid = semget((*Sess)->key, 1, 0644 | IPC_CREAT); | (*Sess)->id.semid = semget((*Sess)->key, 1, MEM_MODE | IPC_CREAT); |
if ((*Sess)->id.semid == -1) { |
if ((*Sess)->id.semid == -1) { |
LOGERR; |
LOGERR; |
ipc_destroySession(csFName, Sess); |
ipc_destroySession(csFName, Sess); |
Line 269 int ipc_createSession(const char *csFName, const int c
|
Line 277 int ipc_createSession(const char *csFName, const int c
|
} |
} |
|
|
// create shared memory object |
// create shared memory object |
(*Sess)->mem.shmid = shmget((*Sess)->key, cnSize, 0644 | IPC_CREAT); | (*Sess)->mem.shmid = shmget((*Sess)->key, cnSize, MEM_MODE | IPC_CREAT); |
if ((*Sess)->mem.shmid == -1) { |
if ((*Sess)->mem.shmid == -1) { |
LOGERR; |
LOGERR; |
ipc_destroySession(csFName, Sess); |
ipc_destroySession(csFName, Sess); |
Line 387 inline void ipc_detachSession(tagSess * __restrict s)
|
Line 395 inline void ipc_detachSession(tagSess * __restrict s)
|
shmdt(s->addr); |
shmdt(s->addr); |
s->addr = NULL; |
s->addr = NULL; |
} |
} |
|
} |
|
|
|
/* |
|
* isAttached() Check for mapped/(attached) shared memory |
|
* @s = Session item |
|
* return: -1 null session item, 0 not attached, 1 attached memory |
|
*/ |
|
inline int isAttached(tagSess * __restrict s) |
|
{ |
|
if (!s) |
|
return -1; |
|
|
|
return (s->addr ? 1 : 0); |
} |
} |
|
|
|
|