You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2019/09/27 13:43:42 UTC

[zookeeper] branch branch-3.5 updated: ZOOKEEPER-2282: C Client: chroot not stripped in asynchronous callbacks

This is an automated email from the ASF dual-hosted git repository.

andor pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new c93f6a8  ZOOKEEPER-2282: C Client: chroot not stripped in asynchronous callbacks
c93f6a8 is described below

commit c93f6a88e565669a9d4f3d2f9c7e6f15297a5dae
Author: Damien Diederen <dd...@crosstwine.com>
AuthorDate: Fri Sep 27 15:43:19 2019 +0200

    ZOOKEEPER-2282: C Client: chroot not stripped in asynchronous callbacks
    
    This is related to ZOOKEEPER-1027, which adjusted the result of `create` calls to account for the chroot path.  It did not, however, correct the problem for asynchronous calls:
    
        $ cli_st $ENSEMBLE_HOSTS/rt-46444
    
        create /x/fred
        Creating [/x/fred] node (mode: 0)
        [/x/fred]: rc = 0
                name = /rt-46444/x/fred
    
        create2 /x/wilma
        Creating [/x/wilma] node (mode: 0)
        [/x/wilma]: rc = 0
                name = /rt-46444/x/wilma
                ctime = Wed Aug 28 18:14:16 2019
                czxid=1f00000041
                mtime=Wed Aug 28 18:14:16 2019
                mzxid=1f00000041
                version=0	aversion=0
                ephemeralOwner = 0
    
    (It turns out that there was already a ticket, with a patch, for this issue.  I am mentioning Andrew Grasso as a co-author.  This commit also avoids the test failure, however.)
    
    Co-authored-by: Andrew Grasso <andrew-grassousers.noreply.github.com>
    
    Author: Damien Diederen <dd...@crosstwine.com>
    
    Reviewers: eolivelli@apache.org, andor@apache.org
    
    Closes #1066 from ztzg/ZOOKEEPER-2282-c-client-async-chroot-paths
    
    (cherry picked from commit 1e7fae31af634ccfb85cde17fa634d188145b9b7)
    Signed-off-by: Andor Molnar <an...@apache.org>
---
 zookeeper-client/zookeeper-client-c/src/zookeeper.c     | 10 ++++++++--
 zookeeper-client/zookeeper-client-c/tests/TestClient.cc | 10 ++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/zookeeper-client/zookeeper-client-c/src/zookeeper.c b/zookeeper-client/zookeeper-client-c/src/zookeeper.c
index 6e9e8c6..373787b 100644
--- a/zookeeper-client/zookeeper-client-c/src/zookeeper.c
+++ b/zookeeper-client/zookeeper-client-c/src/zookeeper.c
@@ -2730,9 +2730,12 @@ static void deserialize_response(zhandle_t *zh, int type, int xid, int failed, i
             cptr->c.string_result(rc, 0, cptr->data);
         } else {
             struct CreateResponse res;
+            const char *client_path;
             memset(&res, 0, sizeof(res));
             deserialize_CreateResponse(ia, "reply", &res);
-            cptr->c.string_result(rc, res.path, cptr->data);
+            client_path = sub_string(zh, res.path);
+            cptr->c.string_result(rc, client_path, cptr->data);
+            free_duplicate_path(client_path, res.path);
             deallocate_CreateResponse(&res);
         }
         break;
@@ -2743,8 +2746,11 @@ static void deserialize_response(zhandle_t *zh, int type, int xid, int failed, i
             cptr->c.string_stat_result(rc, 0, 0, cptr->data);
         } else {
             struct Create2Response res;
+            const char *client_path;
             deserialize_Create2Response(ia, "reply", &res);
-            cptr->c.string_stat_result(rc, res.path, &res.stat, cptr->data);
+            client_path = sub_string(zh, res.path);
+            cptr->c.string_stat_result(rc, client_path, &res.stat, cptr->data);
+            free_duplicate_path(client_path, res.path);
             deallocate_Create2Response(&res);
         }
         break;
diff --git a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
index 178d548..ec8dbb4 100644
--- a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
+++ b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
@@ -439,6 +439,10 @@ public:
 
     static void create_completion_fn(int rc, const char* value, const void *data) {
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+        if (data) {
+            const char *expected_value = (const char *)data;
+            CPPUNIT_ASSERT_EQUAL(string(expected_value), string(value));
+        }
         count++;
     }
 
@@ -980,6 +984,12 @@ public:
         rc = zoo_create(zk_ch, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, path_buffer, path_buffer_len);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL(string(path), string(path_buffer));
+
+        const char* path2282 = "/zookeeper2282";
+        rc = zoo_acreate(zk_ch, path2282, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
+                         create_completion_fn, path2282);
+        waitForCreateCompletion(3);
+        CPPUNIT_ASSERT(count == 0);
     }
 
     // Test creating normal handle via zookeeper_init then explicitly setting callback