]> git.tue.mpg.de Git - paraslash.git/commitdiff
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 ae9ad574bbd5840be8cee0c034c8f9e0e48cc7cc..973a9eaf4ffee1e69eb5a5e5460f7060f654b433 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);
 }
 
 /**