/*
* Copyright (c) 2000-2001, 2005, 2008 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.
*/
#if SM_CONF_SEM
# include <stdlib.h>
# include <unistd.h>
# include <errno.h>
/*
** SM_SEM_START -- initialize semaphores
**
** Parameters:
** key -- key for semaphores.
** nsem -- number of semaphores.
** semflg -- flag for semget(), if 0, use a default.
** owner -- create semaphores.
**
** Returns:
** id for semaphores.
** < 0 on failure.
*/
int
int nsem;
int semflg;
bool owner;
{
unsigned short *semvals;
if (semflg == 0)
if (owner)
if (semid < 0)
goto error;
if (owner)
{
goto error;
/* initialize semaphore values to be available */
for (i = 0; i < nsem; i++)
semvals[i] = 1;
goto error;
}
return semid;
if (semid >= 0)
}
/*
** SM_SEM_STOP -- stop using semaphores.
**
** Parameters:
** semid -- id for semaphores.
**
** Returns:
** 0 on success.
** < 0 on failure.
*/
int
int semid;
{
}
/*
** SM_SEM_ACQ -- acquire semaphore.
**
** Parameters:
** semid -- id for semaphores.
** semnum -- number of semaphore.
** timeout -- how long to wait for operation to succeed.
**
** Returns:
** 0 on success.
** < 0 on failure.
*/
int
int semid;
int semnum;
int timeout;
{
int r;
do
{
if (r == 0)
return r;
sleep(1);
--timeout;
} while (timeout > 0);
return r;
}
/*
** SM_SEM_REL -- release semaphore.
**
** Parameters:
** semid -- id for semaphores.
** semnum -- number of semaphore.
** timeout -- how long to wait for operation to succeed.
**
** Returns:
** 0 on success.
** < 0 on failure.
*/
int
int semid;
int semnum;
int timeout;
{
int r;
#if PARANOID
/* XXX should we check whether the value is already 0 ? */
#endif /* PARANOID */
do
{
if (r == 0)
return r;
sleep(1);
--timeout;
} while (timeout > 0);
return r;
}
/*
** SM_SEM_GET -- get semaphore value.
**
** Parameters:
** semid -- id for semaphores.
** semnum -- number of semaphore.
**
** Returns:
** value of semaphore on success.
** < 0 on failure.
*/
int
int semid;
int semnum;
{
int semval;
return -1;
return semval;
}
/*
**
** Parameters:
** semid -- id for semaphores.
** uid -- uid to use
** gid -- gid to use
** mode -- mode to use
**
** Returns:
** 0 on success.
** < 0 on failure.
*/
int
int semid;
{
int r;
union semun {
int val;
} arg;
return r;
return r;
return 0;
}
#endif /* SM_CONF_SEM */