]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - ipc.c
Avoid busy loop if someone nasty removes the semaphores currently in use.
[paraslash.git] / 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);
 }
 
 /**