2 * Copyright (c) 2000-2001, 2003, 2005 Proofpoint, 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.20 2013-11-22 20:51:43 ca Exp $")
17 # include <sm/string.h>
23 ** SM_SHMSTART -- initialize shared memory segment.
26 ** key -- key for shared memory.
27 ** size -- size of segment.
28 ** shmflag -- initial flags.
29 ** shmid -- pointer to return id.
30 ** owner -- create segment.
33 ** pointer to shared memory segment,
37 ** attaches shared memory segment.
41 sm_shmstart(key, size, shmflg, shmid, owner)
49 void *shm = SM_SHM_NULL;
51 /* default: user/group accessible */
53 shmflg = SHM_R|SHM_W|(SHM_R>>3)|(SHM_W>>3);
55 shmflg |= IPC_CREAT|IPC_EXCL;
56 *shmid = shmget(key, size, shmflg);
60 shm = shmat(*shmid, (void *) 0, 0);
61 if (shm == SM_SHM_NULL)
68 if (shm != SM_SHM_NULL || *shmid >= 0)
69 sm_shmstop(shm, *shmid, owner);
70 *shmid = SM_SHM_NO_ID;
77 ** SM_SHMSTOP -- stop using shared memory segment.
80 ** shm -- pointer to shared memory.
82 ** owner -- delete segment.
89 ** detaches (and maybe removes) shared memory segment.
94 sm_shmstop(shm, shmid, owner)
101 if (shm != SM_SHM_NULL && (r = shmdt(shm)) < 0)
103 if (owner && shmid >= 0 && (r = shmctl(shmid, IPC_RMID, NULL)) < 0)
110 ** SM_SHMSETOWNER -- set owner/group/mode of shared memory segment.
116 ** mode -- mode to use
125 sm_shmsetowner(int shmid, uid_t uid, gid_t gid, MODE_T mode)
128 sm_shmsetowner(shmid, uid, gid, mode)
133 #endif /* __STDC__ */
136 struct shmid_ds shmid_ds;
138 memset(&shmid_ds, 0, sizeof(shmid_ds));
139 if ((r = shmctl(shmid, IPC_STAT, &shmid_ds)) < 0)
141 shmid_ds.shm_perm.uid = uid;
142 shmid_ds.shm_perm.gid = gid;
143 shmid_ds.shm_perm.mode = mode;
144 if ((r = shmctl(shmid, IPC_SET, &shmid_ds)) < 0)
148 #endif /* SM_CONF_SHM */