From 56e8e39e704ec2743d05801e6b595da61a5ca06a Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 11 Apr 2019 16:56:32 +1000 Subject: [PATCH 1/2] ctdb-tools: Fix ctdb dumpmemory to avoid printing trailing NUL Fix ctdb rddumpmemory too. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13923 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit f78d9388fb459dc83fafb4da6e683e3137ad40e1) --- ctdb/tools/ctdb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 0fbe54c9f83..27bb4f548bc 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -2438,8 +2438,8 @@ static int control_dumpmemory(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, return ret; } - n = write(1, mem_str, strlen(mem_str)+1); - if (n < 0 || n != strlen(mem_str)+1) { + n = write(1, mem_str, strlen(mem_str)); + if (n < 0 || n != strlen(mem_str)) { fprintf(stderr, "Failed to write talloc summary\n"); return 1; } @@ -2450,10 +2450,12 @@ static int control_dumpmemory(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, static void dump_memory(uint64_t srvid, TDB_DATA data, void *private_data) { bool *done = (bool *)private_data; + size_t len; ssize_t n; - n = write(1, data.dptr, data.dsize); - if (n < 0 || n != data.dsize) { + len = strnlen((const char *)data.dptr, data.dsize); + n = write(1, data.dptr, len); + if (n < 0 || n != len) { fprintf(stderr, "Failed to write talloc summary\n"); } -- 2.20.1 From 6398db0b378a825a0772999eeaeb8eceffa87d7d Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 11 Apr 2019 16:58:10 +1000 Subject: [PATCH 2/2] ctdb-tests: Extend test to cover ctdb rddumpmemory BUG: https://bugzilla.samba.org/show_bug.cgi?id=13923 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 8108b3134c017c22d245fc5b2207a88d44ab0dd2) --- ctdb/tests/simple/25_dumpmemory.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ctdb/tests/simple/25_dumpmemory.sh b/ctdb/tests/simple/25_dumpmemory.sh index eec55b71c58..4f998bf8f3b 100755 --- a/ctdb/tests/simple/25_dumpmemory.sh +++ b/ctdb/tests/simple/25_dumpmemory.sh @@ -28,8 +28,11 @@ set -e cluster_is_healthy -try_command_on_node -v 0 "$CTDB dumpmemory" - pat='^([[:space:]].+[[:space:]]+contains[[:space:]]+[[:digit:]]+ bytes in[[:space:]]+[[:digit:]]+ blocks \(ref [[:digit:]]+\)[[:space:]]+0x[[:xdigit:]]+|[[:space:]]+reference to: .+|full talloc report on .+ \(total[[:space:]]+[[:digit:]]+ bytes in [[:digit:]]+ blocks\))$' +try_command_on_node -v 0 "$CTDB dumpmemory" +sanity_check_output 10 "$pat" "$out" + +echo +try_command_on_node -v 0 "$CTDB rddumpmemory" sanity_check_output 10 "$pat" "$out" -- 2.20.1