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.
10 #pragma ident "%Z%%M% %I% %E% SMI"
13 SM_RCSID("@(#)$Id: shm.c,v 1.19 2005/07/14 22:34:28 ca Exp $")
19 # include <sm/string.h>
24 ** SM_SHMSTART -- initialize shared memory segment.
27 ** key -- key for shared memory.
28 ** size -- size of segment.
29 ** shmflag -- initial flags.
30 ** shmid -- pointer to return id.
31 ** owner -- create segment.
34 ** pointer to shared memory segment,
38 ** attaches shared memory segment.
42 sm_shmstart(key
, size
, shmflg
, shmid
, owner
)
50 void *shm
= SM_SHM_NULL
;
52 /* default: user/group accessible */
54 shmflg
= SHM_R
|SHM_W
|(SHM_R
>>3)|(SHM_W
>>3);
56 shmflg
|= IPC_CREAT
|IPC_EXCL
;
57 *shmid
= shmget(key
, size
, shmflg
);
61 shm
= shmat(*shmid
, (void *) 0, 0);
62 if (shm
== SM_SHM_NULL
)
69 if (shm
!= SM_SHM_NULL
|| *shmid
>= 0)
70 sm_shmstop(shm
, *shmid
, owner
);
71 *shmid
= SM_SHM_NO_ID
;
78 ** SM_SHMSTOP -- stop using shared memory segment.
81 ** shm -- pointer to shared memory.
83 ** owner -- delete segment.
90 ** detaches (and maybe removes) shared memory segment.
95 sm_shmstop(shm
, shmid
, owner
)
102 if (shm
!= SM_SHM_NULL
&& (r
= shmdt(shm
)) < 0)
104 if (owner
&& shmid
>= 0 && (r
= shmctl(shmid
, IPC_RMID
, NULL
)) < 0)
111 ** SM_SHMSETOWNER -- set owner/group/mode of shared memory segment.
117 ** mode -- mode to use
125 sm_shmsetowner(shmid
, uid
, gid
, mode
)
132 struct shmid_ds shmid_ds
;
134 memset(&shmid_ds
, 0, sizeof(shmid_ds
));
135 if ((r
= shmctl(shmid
, IPC_STAT
, &shmid_ds
)) < 0)
137 shmid_ds
.shm_perm
.uid
= uid
;
138 shmid_ds
.shm_perm
.gid
= gid
;
139 shmid_ds
.shm_perm
.mode
= mode
;
140 if ((r
= shmctl(shmid
, IPC_SET
, &shmid_ds
)) < 0)
144 #endif /* SM_CONF_SHM */