2 * Copyright (c) 2000-2001, 2003, 2005 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.18 2005/02/09 01:54:51 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)
108 ** SM_SHMSETOWNER -- set owner/group/mode of shared memory segment.
114 ** mode -- mode to use
122 sm_shmsetowner(shmid, uid, gid, mode)
129 struct shmid_ds shmid_ds;
131 memset(&shmid_ds, 0, sizeof(shmid_ds));
132 if ((r = shmctl(shmid, IPC_STAT, &shmid_ds)) < 0)
134 shmid_ds.shm_perm.uid = uid;
135 shmid_ds.shm_perm.gid = gid;
136 shmid_ds.shm_perm.mode = mode;
137 if ((r = shmctl(shmid, IPC_SET, &shmid_ds)) < 0)
141 #endif /* SM_CONF_SHM */