1 |
|
|
2 |
/* Copyright (C) 1999 Beau Kuiper |
/* Copyright (C) 1999 Beau Kuiper |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
20 |
void shmem_finish(int shmemnum) |
void shmem_finish(int shmemnum) |
21 |
{ |
{ |
22 |
struct shmid_ds buffer; |
struct shmid_ds buffer; |
23 |
|
|
24 |
if (shmemnum != -1) |
if (shmemnum != -1) |
25 |
{ |
{ |
26 |
if (shmctl(shmemnum, IPC_RMID, &buffer) == -1); |
if (shmctl(shmemnum, IPC_RMID, &buffer) == -1); |
27 |
|
|
28 |
/* close(shmem_lockfd); */ |
/* close(shmem_lockfd); */ |
29 |
} |
} |
30 |
} |
} |
31 |
|
|
32 |
void *shmem_get(char *ipcfile, int size, int *shmemnum, int *isnew, int *lockfd) |
void *shmem_get(char *ipcfile, |
33 |
|
int size, |
34 |
|
int *shmemnum, |
35 |
|
int *isnew, |
36 |
|
int *lockfd) |
37 |
{ |
{ |
38 |
key_t ipckey = ftok(ipcfile, '/'); |
key_t ipckey = ftok(ipcfile, '/'); |
39 |
void *shmemarea; |
void *shmemarea; |
40 |
|
|
41 |
*isnew = TRUE; |
*isnew = TRUE; |
42 |
*shmemnum = shmget(ipckey, size, |
*shmemnum = shmget(ipckey, size, IPC_CREAT | IPC_EXCL | 0600); |
|
IPC_CREAT | IPC_EXCL | 0600); |
|
43 |
if (*shmemnum == -1) |
if (*shmemnum == -1) |
44 |
{ |
{ |
45 |
*isnew = FALSE; |
*isnew = FALSE; |
46 |
*shmemnum = shmget(ipckey, size, |
*shmemnum = shmget(ipckey, size, IPC_CREAT | /* IPC_EXCL | */ 0600); |
|
IPC_CREAT |/* IPC_EXCL |*/ 0600); |
|
47 |
} |
} |
48 |
if (*shmemnum == -1) |
if (*shmemnum == -1) |
49 |
ERRORMSGFATAL(strerror(errno)); |
ERRORMSGFATAL(strerror(errno)); |
50 |
|
|
51 |
shmemarea = shmat(*shmemnum, NULL, 0); |
shmemarea = shmat(*shmemnum, NULL, 0); |
52 |
|
|
53 |
/* get semaphores. Using the config file so others can join in (we use file locks for portability, simplicity |
/* |
54 |
and usability. */ |
* get semaphores. Using the config file so others can join in (we use file locks for portability, simplicity |
55 |
|
* and usability. |
56 |
|
*/ |
57 |
|
|
58 |
*lockfd = open(ipcfile, O_RDWR); |
*lockfd = open(ipcfile, O_RDWR); |
59 |
if (*lockfd == -1) |
if (*lockfd == -1) |
60 |
ERRORMSGFATAL(strerror(errno)); |
ERRORMSGFATAL(strerror(errno)); |
61 |
return(shmemarea); |
return (shmemarea); |
62 |
} |
} |