ctdb-tests: Avoid segfault by initializing logging
authorAmitay Isaacs <amitay@gmail.com>
Thu, 21 Jun 2018 10:00:41 +0000 (20:00 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 4 Jul 2018 21:56:42 +0000 (23:56 +0200)
Setting DEBUGLEVEL before calling debug_init() causes segmentation
violation with gcc8.  DEBUGLEVEL_CLASS is statically initialized to
debug_class_list_initial which is defined as const.  Only after
debug_init() is called, DEBUGLEVEL_CLASS becomes a talloc'd array.

So before modifying DEBUGLEVEL, ensure debug_init() is called via
setup_logging().  (debug_init is a static function.)

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
12 files changed:
ctdb/tests/src/fetch_loop.c
ctdb/tests/src/fetch_loop_key.c
ctdb/tests/src/fetch_readonly.c
ctdb/tests/src/fetch_readonly_loop.c
ctdb/tests/src/fetch_ring.c
ctdb/tests/src/g_lock_loop.c
ctdb/tests/src/message_ring.c
ctdb/tests/src/transaction_loop.c
ctdb/tests/src/tunnel_test.c
ctdb/tests/src/update_record.c
ctdb/tests/src/update_record_persistent.c
ctdb/wscript

index 6767f71207aced97bcd02a444fe6ad5b903c893f..0e1d9dadfbab351cf1d1077bfc291be4f1409861 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "client/client.h"
@@ -230,6 +231,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("fetch_loop", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
index b13784224f52431d2f8decef9efa4a163534128d..3f41ca759544a24ca99e55776163f18e7221f1fe 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "client/client.h"
@@ -155,6 +156,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("fetch_loop_key", DEBUG_STDERR);
+
        status = process_options_database(argc, argv, &opts);
        if (! status) {
                exit(1);
index 5d2972a3f09e2ca3cf808df5a9ead3549e37238c..ff126bdf5ae55c152bb4320d78fc09f1c5cf3d2c 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "client/client.h"
@@ -107,6 +108,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("fetch_readonly", DEBUG_STDERR);
+
        status = process_options_database(argc, argv, &opts);
        if (! status) {
                exit(1);
index 9d5d22e7534c4867561baec745ab1f719e6f1a4f..08cf4766659b96086158993bbbfa3a67f9695711 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "client/client.h"
@@ -214,6 +215,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("fetch_readonly_loop", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
index eb64648139e348103f811bffdb1f4bdff2225ef5..f746e789511dc571f7adb1f15d0b78450211292a 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/time.h"
 #include "lib/util/tevent_unix.h"
 
@@ -331,6 +332,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("fetch_ring", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
index f29d0f1235a63b5fa4dc2e9ef757f856bb8ddb77..3b84241ff20c3938e147b6ddede730473d35718b 100644 (file)
@@ -213,6 +213,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("glock_loop", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
@@ -230,8 +232,6 @@ int main(int argc, const char *argv[])
                exit(1);
        }
 
-       setup_logging("glock_loop", DEBUG_STDERR);
-
        ret = ctdb_client_init(mem_ctx, ev, opts->socket, &client);
        if (ret != 0) {
                fprintf(stderr, "Failed to initialize client, ret=%d\n", ret);
index dabae65ff86a7f85ed227140b4ff93e958623568..d1fcee4e35898e06cae75697550e6e0ea66edecd 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/time.h"
 #include "lib/util/tevent_unix.h"
 
@@ -317,6 +318,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("message_ring", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
index 66237512c8718e9b6efe2df71b0c24339ca64814..a423d6817fdd18e1487c12c4ce5eb9f9b924220e 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "client/client.h"
@@ -342,6 +343,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("transaction_loop", DEBUG_STDERR);
+
        status = process_options_database(argc, argv, &opts);
        if (! status) {
                exit(1);
index 53ad83057edba02ab2841aab52cfc83dd63c602c..a6d44ba19c3886938b2141da3be6ee4ebbf03a05 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "protocol/protocol_private.h"
@@ -429,6 +430,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("tunnel_test", DEBUG_STDERR);
+
        status = process_options_basic(argc, argv, &opts);
        if (! status) {
                exit(1);
index 78291d7dc8ee029a3432d635ef8285699a732089..11b6050ad812f6a7d1db829df904065c03831fec 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "protocol/protocol_api.h"
@@ -177,6 +178,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("update_record", DEBUG_STDERR);
+
        status = process_options_database(argc, argv, &opts);
        if (! status) {
                exit(1);
index 9323e3743c216cf76ce4482c5590caaefc4b7fd6..2d6d21e25cffb3ff2d5cb6799a1de62fe1c3edaa 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 
+#include "lib/util/debug.h"
 #include "lib/util/tevent_unix.h"
 
 #include "protocol/protocol_api.h"
@@ -153,6 +154,8 @@ int main(int argc, const char *argv[])
        int ret;
        bool status;
 
+       setup_logging("update_record_persistene", DEBUG_STDERR);
+
        status = process_options_database(argc, argv, &opts);
        if (! status) {
                exit(1);
index fb3f277da018482b8b68faa3904407c6508fda6f..c6883d8c3483f1d5cae6c5c001a21bfc0e77b883 100644 (file)
@@ -865,7 +865,7 @@ def build(bld):
                         source=bld.SUBDIR('tests/src',
                                           'cluster_wait.c test_options.c'),
                         includes='include',
-                        deps='replace popt talloc tevent tdb')
+                        deps='samba-util replace popt talloc tevent tdb')
 
     # Test binaries
     ctdb_tests = [