Steven Dake wrote:
> This patch looks good but I want to hold off on merging until the
> corosync shared ipc library goes in to avoid big collides in the source
> tree.
>
> Regards
> -steve
>
> On Fri, 2009-03-20 at 13:43 +0100, Jim Meyering wrote:
>> I spotted these by inspection, but Steven said on irc that this
>> sort of infloop has actually been seen in practice.
>>
>> From 8907a0affff35f6637ccd560a3e872caf1fab36d Mon Sep 17 00:00:00 2001
>> From: Jim Meyering <[email protected]>
>> Date: Fri, 20 Mar 2009 13:38:34 +0100
>> Subject: [PATCH] avoid infloop upon out-of-memory or out-of-semaphores

I rebased and resolved the conflicts.
Let me know if it's to commit, now.

>From f2f9ce52ba09b49d605ff067e6ce60b5b7f4b55b Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Tue, 24 Mar 2009 08:22:20 +0100
Subject: [PATCH] avoid infloop upon out-of-memory or out-of-semaphores

* coroipc.c (cslib_service_connect): Upon shmget failure
loop only when errno == EEXIST.  Any other error now translates
to res_setup.error.
Likewise for semget.
---
 lib/coroipcc.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/coroipcc.c b/lib/coroipcc.c
index 47937ee..3d4521f 100644
--- a/lib/coroipcc.c
+++ b/lib/coroipcc.c
@@ -323,20 +323,32 @@ coroipcc_service_connect (
        /*
         * Allocate a shared memory segment
         */
-       do {
+       while (1) {
                shmkey = random();
-               ipc_segment->shmid = shmget (shmkey, sizeof (struct 
shared_memory),
-                       IPC_CREAT|IPC_EXCL|0600);
-       } while (ipc_segment->shmid == -1);
+               if ((ipc_segment->shmid
+                    = shmget (shmkey, sizeof (struct shared_memory),
+                              IPC_CREAT|IPC_EXCL|0600)) != -1) {
+                       break;
+               }
+               if (errno != EEXIST) {
+                       goto error_exit;
+               }
+       }

        /*
         * Allocate a semaphore segment
         */
-       do {
+       while (1) {
                semkey = random();
-               ipc_segment->semid = semget (semkey, 3, 
IPC_CREAT|IPC_EXCL|0600);
                ipc_segment->euid = geteuid ();
-       } while (ipc_segment->semid == -1);
+               if ((ipc_segment->semid
+                    = semget (semkey, 3, IPC_CREAT|IPC_EXCL|0600)) != -1) {
+                     break;
+               }
+               if (errno != EEXIST) {
+                       goto error_exit;
+               }
+       }

        /*
         * Attach to shared memory segment
--
1.6.2.rc1.285.gc5f54
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to