1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
--- a/sem.c
+++ b/sem.c
@@ -27,6 +27,7 @@
* semaphores */
#include <stdio.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
@@ -34,6 +35,20 @@
#include <errno.h>
#include "sem.h"
+/* If we've got a version of glibc that doesn't define union semun, we do
+ * it ourseleves like in semctl(2). Otherwise, fall back to the original
+ * buffer behaviour of defining it (differetly!) only on some systems.
+ *
+ * mbuck@debian.org, 1999/08/29
+ */
+#if defined(__GNU_LIBRARY__) && defined(_SEM_SEMUN_UNDEFINED)
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ unsigned short int *array; /* array for GETALL & SETALL */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
+};
+#else
#if defined(SYS5) || defined(ultrix) || defined(_AIX)
union semun {
int val;
@@ -41,6 +56,7 @@
ushort *array;
};
#endif
+#endif
/* IMPORTS */
@@ -95,7 +111,7 @@
return sem;
}
-static
+static void
do_sem( sem_id, pbuf, err )
int sem_id;
struct sembuf *pbuf;
@@ -149,10 +165,13 @@
remove_sems( sem_id )
int sem_id;
{
+ union semun arg;
+
if( sem_id == -1 )
return;
- if( semctl( sem_id, 0, IPC_RMID, NULL ) == -1 ){
+ arg.val = 0;
+ if( semctl( sem_id, 0, IPC_RMID, arg ) == -1 ){
report_proc();
perror( "internal error, failed to remove semaphore" );
}
|