From: Andre Date: Tue, 21 Feb 2006 17:04:43 +0000 (+0100) Subject: Avoid busy loop if someone nasty removes the semaphores currently in use. X-Git-Tag: v0.2.11~61 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;ds=inline;h=746589429fb545c096837fe59c9d9199f01070a1;p=paraslash.git Avoid busy loop if someone nasty removes the semaphores currently in use. Just die if semop failed 500 times. --- diff --git a/ipc.c b/ipc.c index ae9ad574..973a9eaf 100644 --- a/ipc.c +++ b/ipc.c @@ -4,6 +4,7 @@ #include #include +#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); } /**