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