summaryrefslogtreecommitdiffstats
path: root/src/sh_sem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sh_sem.c')
-rw-r--r--src/sh_sem.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/sh_sem.c b/src/sh_sem.c
index 3de83b4..66c21db 100644
--- a/src/sh_sem.c
+++ b/src/sh_sem.c
@@ -43,11 +43,12 @@ typedef enum {
exit_err = 3
} sh_estat;
-#if 0
+
/* FreeBSD 6.1 defines this in <sys/sem.h> too... */
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* union semun is defined by including <sys/sem.h> */
#else
+#if !defined(HAVE_UNION_SEMUN)
/* according to X/OPEN we have to define it ourselves */
union semun {
int val;
@@ -57,6 +58,7 @@ union semun {
#endif
#endif
+
#define SH_SEMVMX 32767
static int get_semaphore (void)
@@ -74,8 +76,12 @@ static int get_semaphore (void)
static void sem_purge(int sem_id)
{
+ union semun tmp;
+
+ tmp.val = 0;
+
if (sem_id != -1)
- semctl(sem_id, 0, IPC_RMID, (int)0);
+ semctl(sem_id, 0, IPC_RMID, tmp);
return;
}
@@ -102,6 +108,7 @@ static int init_semaphore (int nsems)
mode_t mask;
int semid;
int errnum;
+ union semun tmp;
key_t key = ftok(DEFAULT_DATAROOT, '#');
if (key < 0)
@@ -111,11 +118,13 @@ static int init_semaphore (int nsems)
semid = semget (key, nsems, IPC_CREAT | IPC_EXCL | 0660);
errnum = errno;
umask(mask);
+
+ tmp.val = 1;
if (semid < 0)
return report_err(errnum, FIL__, __LINE__, _("semget"));
for (i=0; i<nsems; ++i)
- if (semctl (semid, i, SETVAL, (int) 1) == -1)
+ if (semctl (semid, i, SETVAL, tmp) == -1)
return report_err(errnum, FIL__, __LINE__, _("semclt"));
return semid;
}
@@ -123,18 +132,24 @@ static int init_semaphore (int nsems)
static int sem_set(int semid, int sem_no, int val)
{
+ union semun tmp;
+
+ tmp.val = val;
+
if (semid < 0)
return -1;
- if (semctl (semid, sem_no, SETVAL, val) == -1)
+ if (semctl (semid, sem_no, SETVAL, tmp) == -1)
return -1;
return 0;
}
static int sem_get(int semid, int sem_no)
{
+ union semun tmp;
if (semid < 0)
return -1;
- return semctl (semid, sem_no, GETVAL, (int) 0);
+ tmp.val = 0;
+ return semctl (semid, sem_no, GETVAL, tmp);
}