/*
* Copyright (c) 2000-2002, 2004, 2005 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
#include <stdio.h>
#if SM_CONF_SHM
# include <stdlib.h>
# include <unistd.h>
/*
** SHMINTER -- interactive testing of shared memory
**
** Parameters:
** owner -- create segment.
**
** Returns:
** 0 on success
** < 0 on failure.
*/
int
bool owner;
{
int i, t;
if (shm == (int *) 0)
{
perror("shminit failed");
return -1;
}
{
switch (t)
{
case 'c':
*shm = 0;
break;
case 'i':
++*shm;
break;
case 'd':
--*shm;
break;
case 's':
sleep(1);
break;
case 'l':
t = *shm;
for (i = 0; i < SHM_MAX; i++)
{
++*shm;
}
break;
case 'v':
break;
case 'S':
printf("sm_shmsetowner=%d\n", i);
break;
}
}
}
/*
** SHMBIG -- testing of shared memory
**
** Parameters:
** owner -- create segment.
** size -- size of segment.
**
** Returns:
** 0 on success
** < 0 on failure.
*/
int
bool owner;
int size;
{
int i;
if (shm == (int *) 0)
{
perror("shminit failed");
return -1;
}
for (i = 0; i < size / sizeof(int); i++)
shm[i] = i;
for (i = 0; i < size / sizeof(int); i++)
{
if (shm[i] != i)
{
}
}
}
/*
** SHMTEST -- test of shared memory
**
** Parameters:
** owner -- create segment.
**
** Returns:
** 0 on success
** < 0 on failure.
*/
int
int owner;
{
int cnt = 0;
if (shm == (int *) 0)
{
perror("shminit failed");
return -1;
}
if (owner)
{
int r;
SM_TEST(r == 0);
*shm = 1;
sleep(1);
/* release and re-acquire the segment */
SM_TEST(r == 0);
}
else
{
sleep(1);
*shm = 2;
/* wait a momemt so the segment is still in use */
sleep(2);
}
}
int
int argc;
char *argv[];
{
bool interactive = false;
bool owner = false;
int ch;
int r = 0;
int status;
extern char *optarg;
{
switch ((char) ch)
{
case 'b':
break;
case 'i':
interactive = true;
break;
case 'o':
owner = true;
break;
default:
break;
}
}
if (interactive)
else if (big > 0)
else
{
extern int SmTestNumErrors;
{
perror("fork failed\n");
return -1;
}
if (pid == 0)
{
/* give the parent the chance to setup data */
sleep(1);
r = shmtest(false);
}
else
{
r = shmtest(true);
}
SM_TEST(r == 0);
if (SmTestNumErrors > 0)
printf("add -DSM_CONF_SHM=0 to confENVDEF in devtools/Site/site.config.m4\nand start over.\n");
return sm_test_end();
}
return r;
}
#else /* SM_CONF_SHM */
int
int argc;
char *argv[];
{
printf("No support for shared memory configured on this machine\n");
return 0;
}
#endif /* SM_CONF_SHM */