Просмотр исходного кода

Fix compile/runtime issues for _POSIX_THREAD_PROCESS_SHARED < 1

For the case where _POSIX_THREAD_PROCESS_SHARED < 1, the code doesn't compile
for corosync v1.3.1. And when it does compile, it crashes on our system - our
version of uClibc seems to always expect a 4th arg. The man pages suggests
the 4th arg is optional, but does say: 'For greater portability it is best to
always call semctl() with four arguments', which is what this patch does.
Also removed semop as it's an unused variable.

Signed-off-by: Tim Beale <tim.beale@alliedtelesis.co.nz>
Reviewed-by: Steven Dake <sdake@redhat.com>
(cherry picked from commit 77f7e5b0fe40338e6e5760feb12768defa6b0cf9)
Tim Beale 14 лет назад
Родитель
Сommit
51bd63ad62
2 измененных файлов с 11 добавлено и 17 удалено
  1. 0 11
      exec/coroipcs.c
  2. 11 6
      include/corosync/coroipc_ipc.h

+ 0 - 11
exec/coroipcs.c

@@ -117,17 +117,6 @@ struct zcb_mapped {
 	size_t size;
 };
 
-#if _POSIX_THREAD_PROCESS_SHARED < 1
-#if defined(_SEM_SEMUN_UNDEFINED)
-union semun {
-	int val;
-	struct semid_ds *buf;
-	unsigned short int *array;
-	struct seminfo *__buf;
-};
-#endif
-#endif
-
 
 enum conn_state {
 	CONN_STATE_THREAD_INACTIVE = 0,

+ 11 - 6
include/corosync/coroipc_ipc.h

@@ -57,6 +57,15 @@
 #include <semaphore.h>
 #else
 #include <sys/sem.h>
+
+#if defined(_SEM_SEMUN_UNDEFINED)
+union semun {
+  int val;
+  struct semid_ds *buf;
+  unsigned short int *array;
+  struct seminfo *__buf;
+};
+#endif
 #endif
 
 /*
@@ -331,8 +340,8 @@ ipc_sem_getvalue (
 	int *sem_value)
 {
 #if _POSIX_THREAD_PROCESS_SHARED < 1
-	struct sembuf sop;
 	int sem_value_hold;
+	union semun semun;
 #else
 	sem_t *sem = NULL;
 	int res;
@@ -359,12 +368,8 @@ ipc_sem_getvalue (
 		return (CS_ERR_LIBRARY);
 	}
 #else
-	sop.sem_num = sem_id;
-	sop.sem_op = 1;
-	sop.sem_flg = 0;
-
 retry_semctl:
-	sem_value_hold = semctl (control_buffer->semid, sem_id, GETVAL);
+	sem_value_hold = semctl (control_buffer->semid, sem_id, GETVAL, semun);
 	if (sem_value_hold == -1 && errno == EINTR) {
 		goto retry_semctl;
 	} else