]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - ipc.c
typo
[paraslash.git] / ipc.c
diff --git a/ipc.c b/ipc.c
index 9ae2b3a09d1e1d98617e4502c16f7af2f0f54742..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)
 {
@@ -11,7 +12,7 @@ int mutex_new(void)
        return ret < 0?  -E_SEM_GET : ret;
 }
 
-int mutex_remove(int id)
+int mutex_destroy(int id)
 {
        int ret = semctl(id, 0, IPC_RMID);
        return ret < 0? -E_SEM_REMOVE : 1;
@@ -19,11 +20,13 @@ int mutex_remove(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);
 }
 
 /**
@@ -92,12 +95,16 @@ int shm_destroy(int id)
  *
  * \sa semop(2)
  */
-void *shm_attach(int id, enum shm_attach_mode mode)
+int shm_attach(int id, enum shm_attach_mode mode, void **result)
 {
-       if (mode == ATTACH_RW)
-               return shmat(id, NULL, 0);
-       return shmat(id, NULL, SHM_RDONLY);
+       if (mode == ATTACH_RW) {
+               *result = shmat(id, NULL, 0);
+               return *result? 1 : -E_SHM_ATTACH;
+       }
+       *result = shmat(id, NULL, SHM_RDONLY);
+       return *result? 1 : -E_SHM_ATTACH;
 }
+
 int shm_detach(void *addr)
 {
        int ret = shmdt(addr);