2 * Copyright (c) 2000-2002, 2004, 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: t-shm.c,v 1.22 2005/01/14 02:14:10 ca Exp $")
20 # include <sys/wait.h>
23 # include <sm/string.h>
28 # define SHM_MAX 6400000
33 ** SHMINTER -- interactive testing of shared memory
36 ** owner -- create segment.
43 int shminter
__P((bool));
52 shm
= (int *) sm_shmstart(T_SHMKEY
, SHMSIZE
, 0, &shmid
, owner
);
55 perror("shminit failed");
59 while ((t
= getchar()) != EOF
)
77 for (i
= 0; i
< SHM_MAX
; i
++)
81 if (*shm
!= SHM_MAX
+ t
)
82 fprintf(stderr
, "error: %d != %d\n",
86 printf("shmval: %d\n", *shm
);
89 i
= sm_shmsetowner(shmid
, getuid(), getgid(), 0644);
90 printf("sm_shmsetowner=%d\n", i
);
94 return sm_shmstop((void *) shm
, shmid
, owner
);
99 ** SHMBIG -- testing of shared memory
102 ** owner -- create segment.
103 ** size -- size of segment.
110 int shmbig
__P((bool, int));
120 shm
= (int *) sm_shmstart(T_SHMKEY
, size
, 0, &shmid
, owner
);
121 if (shm
== (int *) 0)
123 perror("shminit failed");
127 for (i
= 0; i
< size
/ sizeof(int); i
++)
129 for (i
= 0; i
< size
/ sizeof(int); i
++)
133 fprintf(stderr
, "failed at %d: %d", i
, shm
[i
]);
137 return sm_shmstop((void *) shm
, shmid
, owner
);
142 ** SHMTEST -- test of shared memory
145 ** owner -- create segment.
154 int shmtest
__P((int));
163 shm
= (int *) sm_shmstart(T_SHMKEY
, SHMSIZE
, 0, &shmid
, owner
);
164 if (shm
== (int *) 0)
166 perror("shminit failed");
174 r
= sm_shmsetowner(shmid
, getuid(), getgid(), 0660);
177 while (*shm
== 1 && cnt
++ < MAX_CNT
)
179 SM_TEST(cnt
<= MAX_CNT
);
181 /* release and re-acquire the segment */
182 r
= sm_shmstop((void *) shm
, shmid
, owner
);
184 shm
= (int *) sm_shmstart(T_SHMKEY
, SHMSIZE
, 0, &shmid
, owner
);
185 SM_TEST(shm
!= (int *) 0);
189 while (*shm
!= 1 && cnt
++ < MAX_CNT
)
191 SM_TEST(cnt
<= MAX_CNT
);
194 /* wait a momemt so the segment is still in use */
197 return sm_shmstop((void *) shm
, shmid
, owner
);
205 bool interactive
= false;
213 # define OPTIONS "b:io"
214 while ((ch
= getopt(argc
, argv
, OPTIONS
)) != -1)
238 r
= shmbig(true, big
);
242 extern int SmTestNumErrors
;
244 if ((pid
= fork()) < 0)
246 perror("fork failed\n");
250 sm_test_begin(argc
, argv
, "test shared memory");
253 /* give the parent the chance to setup data */
260 (void) wait(&status
);
263 if (SmTestNumErrors
> 0)
264 printf("add -DSM_CONF_SHM=0 to confENVDEF in devtools/Site/site.config.m4\nand start over.\n");
265 return sm_test_end();
269 #else /* SM_CONF_SHM */
275 printf("No support for shared memory configured on this machine\n");
278 #endif /* SM_CONF_SHM */