From: Andre Noll Date: Sat, 8 Sep 2007 07:22:05 +0000 (+0200) Subject: ipc.c: Improve para_semop(). X-Git-Tag: v0.2.17~12 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=1da7031d6e7ac088291934c8ceef5cad9b92ccb3;hp=77264e47dcd6a606ecff2f86f14359f25ab0eba0 ipc.c: Improve para_semop(). It's kind of silly to retry the semop 500 times. Just check if sempop() was interrupted and retry in this case. Otherwise, error out. --- diff --git a/ipc.c b/ipc.c index 833ba1a4..debf9d11 100644 --- a/ipc.c +++ b/ipc.c @@ -13,9 +13,6 @@ #include #include -/** abort if semget() failed that many times */ -#define MAX_SEMOP_RETRIES 500 - /** * define a new mutex * @@ -45,14 +42,17 @@ int mutex_destroy(int id) return ret < 0? -E_SEM_REMOVE : 1; } -static void para_semop(int id, struct sembuf *sops, unsigned num) +static void para_semop(int id, struct sembuf *sops, int num) { - int i; - - for (i = 0; i < MAX_SEMOP_RETRIES; i++) + do { if (semop(id, sops, num) >= 0) return; - PARA_EMERG_LOG("semop failed %d times, aborting\n", MAX_SEMOP_RETRIES); + } while (errno == EINTR); + if (errno == EIDRM) { + PARA_NOTICE_LOG("semaphore set %d was removed\n", id); + return; + } + PARA_EMERG_LOG("fatal semop error %s: pid %d\n", strerror(errno), getpid()); exit(EXIT_FAILURE); }