You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by cn...@apache.org on 2015/10/31 00:57:38 UTC

svn commit: r1711566 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/c/src/mt_adaptor.c src/c/src/st_adaptor.c src/c/src/zk_adaptor.h src/c/src/zookeeper.c

Author: cnauroth
Date: Fri Oct 30 23:57:38 2015
New Revision: 1711566

URL: http://svn.apache.org/viewvc?rev=1711566&view=rev
Log:
ZOOKEEPER-1029: C client bug in zookeeper_init (if bad hostname is given) (fpj via cnauroth)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/c/src/mt_adaptor.c
    zookeeper/branches/branch-3.4/src/c/src/st_adaptor.c
    zookeeper/branches/branch-3.4/src/c/src/zk_adaptor.h
    zookeeper/branches/branch-3.4/src/c/src/zookeeper.c

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1711566&r1=1711565&r2=1711566&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Fri Oct 30 23:57:38 2015
@@ -135,6 +135,9 @@ BUGFIXES:
   ZOOKEEPER-2296: compilation broken for 3.4
   (Raul Gutierrez Segales via cnauroth)
 
+  ZOOKEEPER-1029: C client bug in zookeeper_init (if bad hostname is given)
+  (fpj via cnauroth)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1575. adding .gitattributes to prevent CRLF and LF mismatches for

Modified: zookeeper/branches/branch-3.4/src/c/src/mt_adaptor.c
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/c/src/mt_adaptor.c?rev=1711566&r1=1711565&r2=1711566&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/c/src/mt_adaptor.c (original)
+++ zookeeper/branches/branch-3.4/src/c/src/mt_adaptor.c Fri Oct 30 23:57:38 2015
@@ -44,30 +44,30 @@
 #include <sys/time.h>
 #endif
 
-void zoo_lock_auth(zhandle_t *zh)
+int zoo_lock_auth(zhandle_t *zh)
 {
-    pthread_mutex_lock(&zh->auth_h.lock);
+    return pthread_mutex_lock(&zh->auth_h.lock);
 }
-void zoo_unlock_auth(zhandle_t *zh)
+int zoo_unlock_auth(zhandle_t *zh)
 {
-    pthread_mutex_unlock(&zh->auth_h.lock);
+    return pthread_mutex_unlock(&zh->auth_h.lock);
 }
-void lock_buffer_list(buffer_head_t *l)
+int lock_buffer_list(buffer_head_t *l)
 {
-    pthread_mutex_lock(&l->lock);
+    return pthread_mutex_lock(&l->lock);
 }
-void unlock_buffer_list(buffer_head_t *l)
+int  unlock_buffer_list(buffer_head_t *l)
 {
-    pthread_mutex_unlock(&l->lock);
+    return pthread_mutex_unlock(&l->lock);
 }
-void lock_completion_list(completion_head_t *l)
+int lock_completion_list(completion_head_t *l)
 {
-    pthread_mutex_lock(&l->lock);
+    return pthread_mutex_lock(&l->lock);
 }
-void unlock_completion_list(completion_head_t *l)
+int unlock_completion_list(completion_head_t *l)
 {
     pthread_cond_broadcast(&l->cond);
-    pthread_mutex_unlock(&l->lock);
+    return pthread_mutex_unlock(&l->lock);
 }
 struct sync_completion *alloc_sync_completion(void)
 {
@@ -515,16 +515,22 @@ __attribute__((constructor)) int32_t get
     return fetch_and_add(&xid,1);
 }
 
-void enter_critical(zhandle_t* zh)
+int enter_critical(zhandle_t* zh)
 {
     struct adaptor_threads *adaptor = zh->adaptor_priv;
-    if(adaptor)
-        pthread_mutex_lock(&adaptor->zh_lock);
+    if (adaptor) {
+        return pthread_mutex_lock(&adaptor->zh_lock);
+    } else {
+        return 0;
+    }
 }
 
-void leave_critical(zhandle_t* zh)
+int leave_critical(zhandle_t* zh)
 {
     struct adaptor_threads *adaptor = zh->adaptor_priv;
-    if(adaptor)
-        pthread_mutex_unlock(&adaptor->zh_lock);    
+    if (adaptor) {
+        return pthread_mutex_unlock(&adaptor->zh_lock);
+    } else {
+        return 0;
+    }
 }

Modified: zookeeper/branches/branch-3.4/src/c/src/st_adaptor.c
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/c/src/st_adaptor.c?rev=1711566&r1=1711565&r2=1711566&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/c/src/st_adaptor.c (original)
+++ zookeeper/branches/branch-3.4/src/c/src/st_adaptor.c Fri Oct 30 23:57:38 2015
@@ -24,23 +24,29 @@
 #include <stdlib.h>
 #include <time.h>
 
-void zoo_lock_auth(zhandle_t *zh)
+int zoo_lock_auth(zhandle_t *zh)
 {
+	return 0;
 }
-void zoo_unlock_auth(zhandle_t *zh)
+int zoo_unlock_auth(zhandle_t *zh)
 {
+	return 0;
 }
-void lock_buffer_list(buffer_head_t *l)
+int lock_buffer_list(buffer_head_t *l)
 {
+	return 0;
 }
-void unlock_buffer_list(buffer_head_t *l)
+int unlock_buffer_list(buffer_head_t *l)
 {
+	return 0;
 }
-void lock_completion_list(completion_head_t *l)
+int lock_completion_list(completion_head_t *l)
 {
+	return 0;
 }
-void unlock_completion_list(completion_head_t *l)
+int unlock_completion_list(completion_head_t *l)
 {
+	return 0;
 }
 struct sync_completion *alloc_sync_completion(void)
 {
@@ -95,5 +101,13 @@ int32_t get_xid()
     }
     return xid++;
 }
-void enter_critical(zhandle_t* zh){}
-void leave_critical(zhandle_t* zh){}
+
+int enter_critical(zhandle_t* zh)
+{
+	return 0;
+}
+
+int leave_critical(zhandle_t* zh)
+{
+	return 0;
+}

Modified: zookeeper/branches/branch-3.4/src/c/src/zk_adaptor.h
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/c/src/zk_adaptor.h?rev=1711566&r1=1711565&r2=1711566&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/c/src/zk_adaptor.h (original)
+++ zookeeper/branches/branch-3.4/src/c/src/zk_adaptor.h Fri Oct 30 23:57:38 2015
@@ -75,10 +75,10 @@ typedef struct _completion_head {
 #endif
 } completion_head_t;
 
-void lock_buffer_list(buffer_head_t *l);
-void unlock_buffer_list(buffer_head_t *l);
-void lock_completion_list(completion_head_t *l);
-void unlock_completion_list(completion_head_t *l);
+int lock_buffer_list(buffer_head_t *l);
+int unlock_buffer_list(buffer_head_t *l);
+int lock_completion_list(completion_head_t *l);
+int unlock_completion_list(completion_head_t *l);
 
 struct sync_completion {
     int rc;
@@ -243,12 +243,12 @@ void process_completions(zhandle_t *zh);
 int flush_send_queue(zhandle_t*zh, int timeout);
 char* sub_string(zhandle_t *zh, const char* server_path);
 void free_duplicate_path(const char* free_path, const char* path);
-void zoo_lock_auth(zhandle_t *zh);
-void zoo_unlock_auth(zhandle_t *zh);
+int zoo_lock_auth(zhandle_t *zh);
+int zoo_unlock_auth(zhandle_t *zh);
 
 // critical section guards
-void enter_critical(zhandle_t* zh);
-void leave_critical(zhandle_t* zh);
+int enter_critical(zhandle_t* zh);
+int leave_critical(zhandle_t* zh);
 // zhandle object reference counting
 void api_prolog(zhandle_t* zh);
 int api_epilog(zhandle_t *zh, int rc);

Modified: zookeeper/branches/branch-3.4/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/c/src/zookeeper.c?rev=1711566&r1=1711565&r2=1711566&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/c/src/zookeeper.c (original)
+++ zookeeper/branches/branch-3.4/src/c/src/zookeeper.c Fri Oct 30 23:57:38 2015
@@ -1150,52 +1150,57 @@ void free_completions(zhandle_t *zh,int
     void_completion_t auth_completion = NULL;
     auth_completion_list_t a_list, *a_tmp;
 
-    lock_completion_list(&zh->sent_requests);
-    tmp_list = zh->sent_requests;
-    zh->sent_requests.head = 0;
-    zh->sent_requests.last = 0;
-    unlock_completion_list(&zh->sent_requests);
-    while (tmp_list.head) {
-        completion_list_t *cptr = tmp_list.head;
+    if (lock_completion_list(&zh->sent_requests) == 0) {
+        tmp_list = zh->sent_requests;
+        zh->sent_requests.head = 0;
+        zh->sent_requests.last = 0;
+        unlock_completion_list(&zh->sent_requests);
+    
+        while (tmp_list.head) {
+            completion_list_t *cptr = tmp_list.head;
 
-        tmp_list.head = cptr->next;
-        if (cptr->c.data_result == SYNCHRONOUS_MARKER) {
-            struct sync_completion
-                        *sc = (struct sync_completion*)cptr->data;
-            sc->rc = reason;
-            notify_sync_completion(sc);
-            zh->outstanding_sync--;
-            destroy_completion_entry(cptr);
-        } else if (callCompletion) {
-            // Fake the response
-            buffer_list_t *bptr;
-            h.xid = cptr->xid;
-            h.zxid = -1;
-            h.err = reason;
-            oa = create_buffer_oarchive();
-            serialize_ReplyHeader(oa, "header", &h);
-            bptr = calloc(sizeof(*bptr), 1);
-            assert(bptr);
-            bptr->len = get_buffer_len(oa);
-            bptr->buffer = get_buffer(oa);
-            close_buffer_oarchive(&oa, 0);
-            cptr->buffer = bptr;
-            queue_completion(&zh->completions_to_process, cptr, 0);
+            tmp_list.head = cptr->next;
+            if (cptr->c.data_result == SYNCHRONOUS_MARKER) {
+                struct sync_completion
+                            *sc = (struct sync_completion*)cptr->data;
+                sc->rc = reason;
+                notify_sync_completion(sc);
+                zh->outstanding_sync--;
+                destroy_completion_entry(cptr);
+            } else if (callCompletion) {
+                // Fake the response
+                buffer_list_t *bptr;
+                h.xid = cptr->xid;
+                h.zxid = -1;
+                h.err = reason;
+                oa = create_buffer_oarchive();
+                serialize_ReplyHeader(oa, "header", &h);
+                bptr = calloc(sizeof(*bptr), 1);
+                assert(bptr);
+                bptr->len = get_buffer_len(oa);
+                bptr->buffer = get_buffer(oa);
+                close_buffer_oarchive(&oa, 0);
+                cptr->buffer = bptr;
+                queue_completion(&zh->completions_to_process, cptr, 0);
+            }
         }
     }
-    a_list.completion = NULL;
-    a_list.next = NULL;
-    zoo_lock_auth(zh);
-    get_auth_completions(&zh->auth_h, &a_list);
-    zoo_unlock_auth(zh);
-    a_tmp = &a_list;
-    // chain call user's completion function
-    while (a_tmp->completion != NULL) {
-        auth_completion = a_tmp->completion;
-        auth_completion(reason, a_tmp->auth_data);
-        a_tmp = a_tmp->next;
-        if (a_tmp == NULL)
-            break;
+    if (zoo_lock_auth(zh) == 0) {
+        a_list.completion = NULL;
+        a_list.next = NULL;
+    
+        get_auth_completions(&zh->auth_h, &a_list);
+        zoo_unlock_auth(zh);
+    
+        a_tmp = &a_list;
+        // chain call user's completion function
+        while (a_tmp->completion != NULL) {
+            auth_completion = a_tmp->completion;
+            auth_completion(reason, a_tmp->auth_data);
+            a_tmp = a_tmp->next;
+            if (a_tmp == NULL)
+                break;
+        }
     }
     free_auth_completion(&a_list);
 }