2 * Copyright (c) 2000-2001 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 2001/12/14 00:22:58 ca Exp $")
20 ** SM_SHMSTART -- initialize shared memory segment.
23 ** key -- key for shared memory.
24 ** size -- size of segment.
25 ** shmflag -- initial flags.
26 ** shmid -- pointer to return id.
27 ** owner -- create segment.
30 ** pointer to shared memory segment,
34 ** attaches shared memory segment.
38 sm_shmstart(key, size, shmflg, shmid, owner)
46 void *shm = SM_SHM_NULL;
48 /* default: user/group accessible */
50 shmflg = SHM_R|SHM_W|(SHM_R>>3)|(SHM_W>>3);
52 shmflg |= IPC_CREAT|IPC_EXCL;
53 *shmid = shmget(key, size, shmflg);
57 shm = shmat(*shmid, (void *) 0, 0);
58 if (shm == SM_SHM_NULL)
65 if (shm != SM_SHM_NULL || *shmid >= 0)
66 sm_shmstop(shm, *shmid, owner);
67 *shmid = SM_SHM_NO_ID;
73 ** SM_SHMSTOP -- stop using shared memory segment.
76 ** shm -- pointer to shared memory.
78 ** owner -- delete segment.
85 ** detaches (and maybe removes) shared memory segment.
89 sm_shmstop(shm, shmid, owner)
96 if (shm != SM_SHM_NULL && (r = shmdt(shm)) < 0)
98 if (owner && shmid >= 0 && (r = shmctl(shmid, IPC_RMID, NULL)) < 0)
102 #endif /* SM_CONF_SHM */