Avoid busy loop if someone nasty removes the semaphores currently in use.
authorAndre <maan@p133.(none)>
Tue, 21 Feb 2006 17:04:43 +0000 (18:04 +0100)
committerAndre <maan@p133.(none)>
Tue, 21 Feb 2006 17:04:43 +0000 (18:04 +0100)
Just die if semop failed 500 times.

ipc.c

diff --git a/ipc.c b/ipc.c
index ae9ad57..973a9ea 100644 (file)
--- a/ipc.c
+++ b/ipc.c
@@ -4,6 +4,7 @@
 #include <sys/ipc.h>
 #include <sys/shm.h>
 
+#define MAX_SEMOP_RETRIES 500
 
 int mutex_new(void)
 {
@@ -19,11 +20,13 @@ int mutex_destroy(int id)
 
 static void para_semop(int id, struct sembuf *sops, int num)
 {
-       if (semop(id, sops, num) >= 0)
-               return;
-       PARA_WARNING_LOG("semop failed (%s), retrying\n", strerror(errno));
-       while (semop(id, sops, num) < 0)
-               ; /* nothing */
+       int i;
+
+       for (i = 0; i < MAX_SEMOP_RETRIES; i++)
+               if (semop(id, sops, num) >= 0)
+                       return;
+       PARA_EMERG_LOG("semop failed %d times, aborting\n", MAX_SEMOP_RETRIES);
+       exit(EXIT_FAILURE);
 }
 
 /**