2 * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
11 SM_RCSID("@(#)$Id: shm.c,v 1.10.2.6 2003/06/13 21:17:48 ca Exp $")
21 ** SM_SHMSTART -- initialize shared memory segment.
24 ** key -- key for shared memory.
25 ** size -- size of segment.
26 ** shmflag -- initial flags.
27 ** shmid -- pointer to return id.
28 ** owner -- create segment.
31 ** pointer to shared memory segment,
35 ** attaches shared memory segment.
39 sm_shmstart(key
, size
, shmflg
, shmid
, owner
)
47 void *shm
= SM_SHM_NULL
;
49 /* default: user/group accessible */
51 shmflg
= SHM_R
|SHM_W
|(SHM_R
>>3)|(SHM_W
>>3);
53 shmflg
|= IPC_CREAT
|IPC_EXCL
;
54 *shmid
= shmget(key
, size
, shmflg
);
58 shm
= shmat(*shmid
, (void *) 0, 0);
59 if (shm
== SM_SHM_NULL
)
66 if (shm
!= SM_SHM_NULL
|| *shmid
>= 0)
67 sm_shmstop(shm
, *shmid
, owner
);
68 *shmid
= SM_SHM_NO_ID
;
75 ** SM_SHMSTOP -- stop using shared memory segment.
78 ** shm -- pointer to shared memory.
80 ** owner -- delete segment.
87 ** detaches (and maybe removes) shared memory segment.
92 sm_shmstop(shm
, shmid
, owner
)
99 if (shm
!= SM_SHM_NULL
&& (r
= shmdt(shm
)) < 0)
101 if (owner
&& shmid
>= 0 && (r
= shmctl(shmid
, IPC_RMID
, NULL
)) < 0)
107 #endif /* SM_CONF_SHM */