From 73a12a1261d39af88a78a88a30f47cb13f7e3a4c Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 1 Jul 2018 19:47:37 +1000 Subject: [PATCH 01/29] ctdb-tools: Improve portability by not using /bin/bash directly FreeBSD and others do not have /bin/bash, so use "/usr/bin/env bash" for better flexibility. There are still many integration tests that use /bin/bash but this at least lets FreeBSD start running tests. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 73298ac8a9a87dcf3b3699dfdd39a8e865291620) --- ctdb/tools/onnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index f94423251a8..50fc6a732d5 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Run commands on CTDB nodes. -- 2.17.1 From 02f4b5e456041073fd0219108c34087e40c7acfb Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 1 Jul 2018 13:30:06 +1000 Subject: [PATCH 02/29] ctdb-tests: Improve portability by not using /bin/bash directly FreeBSD and others do not have /bin/bash, so use "/usr/bin/env bash" for better flexibility. There are still many integration tests that use /bin/bash but this at least lets FreeBSD start running tests. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit dd9d8a20aa6948a5d1e7fb532842b7ff5bc0f550) --- ctdb/tests/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh index f1268a5f404..7e0b26deb66 100755 --- a/ctdb/tests/run_tests.sh +++ b/ctdb/tests/run_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash usage() { cat < Date: Sun, 1 Jul 2018 18:43:06 +1000 Subject: [PATCH 03/29] ctdb-tools: Avoid use of non-portable getopt in onnode getopt is being used with non-portable options. Use simpler, POSIX-compliant getopts instead. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 4a39bc4aaad541f1e89c0eb3e98d4104bcc25025) --- ctdb/tools/onnode | 53 ++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 50fc6a732d5..bef04b0fce0 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -72,39 +72,30 @@ fi parse_options () { - # $POSIXLY_CORRECT means that the command passed to onnode can - # take options and getopt won't reorder things to make them - # options ot onnode. - local temp - # Not on the previous line - local returns 0! - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvPi" -l help -- "$@") - - # No! Checking the exit code afterwards is actually clearer... - # shellcheck disable=SC2181 - [ $? -eq 0 ] || usage - - eval set -- "$temp" - - while true ; do - case "$1" in - -c) current=true ; shift ;; - -f) ctdb_nodes_file="$2" ; shift 2 ;; - -n) names_ok=true ; shift ;; - -o) prefix="$2" ; shift 2 ;; - -p) parallel=true ; shift ;; - -q) quiet=true ; shift ;; - -v) verbose=true ; shift ;; - -P) push=true ; shift ;; - -i) stdin=true ; shift ;; - --) shift ; break ;; - -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. - esac - done + local opt + + while getopts "cf:hno:pqvPi?" opt ; do + case "$opt" in + c) current=true ;; + f) ctdb_nodes_file="$OPTARG" ;; + n) names_ok=true ;; + o) prefix="$OPTARG" ;; + p) parallel=true ;; + q) quiet=true ;; + v) verbose=true ;; + P) push=true ;; + i) stdin=true ;; + \?|h) usage ;; + esac + done + shift $((OPTIND - 1)) - [ $# -lt 2 ] && usage + if [ $# -lt 2 ] ; then + usage + fi - nodespec="$1" ; shift - command="$*" + nodespec="$1" ; shift + command="$*" } echo_nth () -- 2.17.1 From 4a97e20a3b6a2be4a9566cbb39afc1a742365640 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 8 Jul 2018 21:54:40 +1000 Subject: [PATCH 04/29] ctdb-tests: Avoid use of non-portable getopt in run_tests.sh getopt is being used with non-portable options. Use simpler, POSIX-compliant getopts instead. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 56ffca3e79923a028ff96fbd50706d808b9dd215) --- ctdb/tests/run_tests.sh | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh index 7e0b26deb66..8eead527b33 100755 --- a/ctdb/tests/run_tests.sh +++ b/ctdb/tests/run_tests.sh @@ -48,33 +48,27 @@ export TEST_CLEANUP=false export TEST_TIMEOUT=3600 export TEST_SOCKET_WRAPPER_SO_PATH="" -temp=$(getopt -n "$prog" -o "AcCdDehHNqS:T:vV:xX" -l help -- "$@") - -[ $? != 0 ] && usage - -eval set -- "$temp" - -while true ; do - case "$1" in - -A) TEST_CAT_RESULTS_OPTS="-A" ; shift ;; - -c) TEST_LOCAL_DAEMONS="" ; shift ;; - -C) TEST_CLEANUP=true ; shift ;; - -d) with_desc=true ; shift ;; # 4th line of output is description - -D) TEST_DIFF_RESULTS=true ; shift ;; - -e) exit_on_fail=true ; shift ;; - -H) no_header=true ; shift ;; - -N) with_summary=false ; shift ;; - -q) quiet=true ; shift ;; - -S) TEST_SOCKET_WRAPPER_SO_PATH="$2" ; shift 2 ;; - -T) TEST_TIMEOUT="$2" ; shift 2 ;; - -v) TEST_VERBOSE=true ; shift ;; - -V) TEST_VAR_DIR="$2" ; shift 2 ;; - -x) set -x; shift ;; - -X) TEST_COMMAND_TRACE=true ; shift ;; - --) shift ; break ;; - *) usage ;; - esac +while getopts "AcCdDehHNqS:T:vV:xX?" opt ; do + case "$opt" in + A) TEST_CAT_RESULTS_OPTS="-A" ;; + c) TEST_LOCAL_DAEMONS="" ;; + C) TEST_CLEANUP=true ;; + d) with_desc=true ;; # 4th line of output is description + D) TEST_DIFF_RESULTS=true ;; + e) exit_on_fail=true ;; + H) no_header=true ;; + N) with_summary=false ;; + q) quiet=true ;; + S) TEST_SOCKET_WRAPPER_SO_PATH="$OPTARG" ;; + T) TEST_TIMEOUT="$OPTARG" ;; + v) TEST_VERBOSE=true ;; + V) TEST_VAR_DIR="$OPTARG" ;; + x) set -x ;; + X) TEST_COMMAND_TRACE=true ;; + \?|h) usage ;; + esac done +shift $((OPTIND - 1)) case $(basename "$0") in *run_cluster_tests*) -- 2.17.1 From 4f077bbb6379ebb055fb035416a80d34fe665d7f Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 1 Jul 2018 19:58:02 +1000 Subject: [PATCH 05/29] ctdb-tests: Avoid use of non-portable getopt in stubs getopt is being used with non-portable options. In most cases use simpler, POSIX-compliant getopts instead. In the case of the ctdb test stub command, options can appear after other arguments, so this requires an additional nested loop. In the case of smnotify, there are no short options, so handle the long options manually. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 896c77df1ce2645c6dd7898b59ea802e204dc7d9) --- ctdb/tests/eventscripts/stubs/ctdb | 38 +++++++++++++++----------- ctdb/tests/eventscripts/stubs/rpcinfo | 32 +++++++++------------- ctdb/tests/eventscripts/stubs/smnotify | 17 ++++++------ ctdb/tests/eventscripts/stubs/ss | 26 ++++++++---------- 4 files changed, 54 insertions(+), 59 deletions(-) diff --git a/ctdb/tests/eventscripts/stubs/ctdb b/ctdb/tests/eventscripts/stubs/ctdb index c5a6ceecce0..c3ea0d50550 100755 --- a/ctdb/tests/eventscripts/stubs/ctdb +++ b/ctdb/tests/eventscripts/stubs/ctdb @@ -27,29 +27,35 @@ not_implemented () exit $not_implemented_exit_code } -# Don't set $POSIXLY_CORRECT here. -_temp=$(getopt -n "$prog" -o "Xvhn:" -l help -- "$@") || \ - usage - -eval set -- "$_temp" - verbose=false machine_readable=false nodespec="" -args="$*" +args="" + +# Options and command argument can appear in any order, so when +# getopts thinks it is done, process any non-option arguments and go +# around again. +while [ $# -gt 0 ] ; do + while getopts "Xvhn:?" opt ; do + case "$opt" in + X) machine_readable=true ;; + v) verbose=true ;; + n) nodespec="$OPTARG" ;; + \?|*) usage ;; + esac + done + shift $((OPTIND - 1)) -while true ; do - case "$1" in - -X) machine_readable=true ; shift ;; - -v) verbose=true ; shift ;; - -n) nodespec="$2" ; shift 2 ;; - --) shift ; break ;; - -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable. - esac + # Anything left over must be a non-option arg + if [ $# -gt 0 ] ; then + args="${args}${args:+ }${1}" + shift + fi done -[ $# -ge 1 ] || usage +[ -n "$args" ] || usage +set -- $args setup_tickles () { diff --git a/ctdb/tests/eventscripts/stubs/rpcinfo b/ctdb/tests/eventscripts/stubs/rpcinfo index 1866b59560e..bf21197a9d4 100755 --- a/ctdb/tests/eventscripts/stubs/rpcinfo +++ b/ctdb/tests/eventscripts/stubs/rpcinfo @@ -16,29 +16,23 @@ EOF parse_options () { - _temp=$(getopt -n "$prog" -o "T:h" -- "$@") + while getopts "T:h?" opt ; do + case "$opt" in + T) netid="$OPTARG" ;; + \?|h) usage ;; + esac + done + shift $((OPTIND - 1)) - [ $? != 0 ] && usage + [ "$netid" = "tcp" ] || usage - eval set -- "$_temp" + host="$1" ; shift + [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage - while true ; do - case "$1" in - -T) netid="$2"; shift 2 ;; - --) shift ; break ;; - -h|*) usage ;; # * shouldn't happen, so this is reasonable. - esac - done + [ 1 -le $# -a $# -le 2 ] || usage - [ "$netid" = "tcp" ] || usage - - host="$1" ; shift - [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage - - [ 1 -le $# -a $# -le 2 ] || usage - - p="$1" - v="$2" + p="$1" + v="$2" } parse_options "$@" diff --git a/ctdb/tests/eventscripts/stubs/smnotify b/ctdb/tests/eventscripts/stubs/smnotify index 2bace779df0..78710346998 100755 --- a/ctdb/tests/eventscripts/stubs/smnotify +++ b/ctdb/tests/eventscripts/stubs/smnotify @@ -9,28 +9,27 @@ EOF exit 1 } -temp=$(getopt -n "smnotify" -o "h" -l client:,ip:,server:,stateval: -- "$@") -if [ $? != 0 ] ; then - usage -fi - -eval set -- "$temp" - cip="" sip="" mon_name="" state="" -while : ; do +while [ $# -gt 0 ] ; do case "$1" in --client) cip="$2" ; shift 2 ;; + --client=*) cip="${1#*=}" ; shift ;; --ip) sip="$2" ; shift 2 ;; + --ip=*) sip="${1#*=}" ; shift ;; --server) mon_name="$2" ; shift 2 ;; + --server=*) mon_name="${1#*=}" ; shift ;; --stateval) state="$2" ; shift 2 ;; + --stateval=*) state="${1#*=}" ; shift ;; --) shift ; break ;; - *) usage ;; + -*) usage ;; + *) break ;; esac done +[ $# -eq 0 ] || usage if [ -z "$cip" -o -z "$sip" -o -z "$mon_name" -o -z "$state" ] ; then usage diff --git a/ctdb/tests/eventscripts/stubs/ss b/ctdb/tests/eventscripts/stubs/ss index bb291b2b091..30f9b89556b 100755 --- a/ctdb/tests/eventscripts/stubs/ss +++ b/ctdb/tests/eventscripts/stubs/ss @@ -152,23 +152,19 @@ listen=false header=true orig="$*" -temp=$(getopt -n "$prog" -o "txnalHh" -l tcp -l unix -l help -- "$@") -[ $? -eq 0 ] || usage - -eval set -- "$temp" - -while true ; do - case "$1" in - --tcp|-t) tcp=true ; shift ;; - --unix|-x) unix=true ; shift ;; - -l) listen=true ; shift ;; - -a) all=true ; shift ;; - -H) header=false ; shift ;; - -n) shift ;; - --) shift ; break ;; - -h|--help|*) usage ;; + +while getopts "txnalHh?" opt ; do + case "$opt" in + t) tcp=true ;; + x) unix=true ;; + l) listen=true ;; + a) all=true ;; + H) header=false ;; + n) : ;; + \?|h) usage ;; esac done +shift $((OPTIND - 1)) $tcp || $unix || not_supported "$*" -- 2.17.1 From 18389b079f9fa23ceda1a2c9d897910bc23453fe Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 1 Jul 2018 13:28:40 +1000 Subject: [PATCH 06/29] ctdb-tests: Improve portability by not using mktemp --tmpdir option BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 2f2c35a1cb4afe38e869882e8f18a62d4daac981) --- ctdb/tests/cunit/pidfile_test_001.sh | 2 +- ctdb/tests/cunit/run_event_001.sh | 2 +- ctdb/tests/cunit/run_proc_001.sh | 6 +++--- ctdb/tests/eventscripts/13.per_ip_routing.024.sh | 2 +- ctdb/tests/scripts/integration.bash | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ctdb/tests/cunit/pidfile_test_001.sh b/ctdb/tests/cunit/pidfile_test_001.sh index 620682e5f0c..fb80d62cf6f 100755 --- a/ctdb/tests/cunit/pidfile_test_001.sh +++ b/ctdb/tests/cunit/pidfile_test_001.sh @@ -2,7 +2,7 @@ . "${TEST_SCRIPTS_DIR}/unit.sh" -pidfile=$(mktemp --tmpdir="$TEST_VAR_DIR") +pidfile=$(TMPDIR="$TEST_VAR_DIR" mktemp) ok_null unit_test pidfile_test $pidfile diff --git a/ctdb/tests/cunit/run_event_001.sh b/ctdb/tests/cunit/run_event_001.sh index f8f74fbf23a..6735fcbf33e 100755 --- a/ctdb/tests/cunit/run_event_001.sh +++ b/ctdb/tests/cunit/run_event_001.sh @@ -8,7 +8,7 @@ run_event_init() failed, ret=2 EOF unit_test run_event_test /a/b/c list -scriptdir=$(mktemp -d --tmpdir="$TEST_VAR_DIR") +scriptdir=$(TMPDIR="$TEST_VAR_DIR" mktemp -d) # Empty directory ok < "$prog" < "$prog" <"$output" 2>&1 @@ -110,7 +110,7 @@ EOF unit_test run_proc_test 1 -1 "$prog" # No zombie processes -pidfile=$(mktemp --tmpdir="$TEST_VAR_DIR") +pidfile=$(TMPDIR="$TEST_VAR_DIR" mktemp) cat > "$prog" < Date: Sun, 1 Jul 2018 13:39:57 +1000 Subject: [PATCH 07/29] ctdb-tests: Switch some test stubs to use /bin/sh They don't use any bash features. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit f13824b291fca9cdaa936c238d7e9bcb73927da7) --- ctdb/tests/eventscripts/stubs/rpcinfo | 2 +- ctdb/tests/eventscripts/stubs/ss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ctdb/tests/eventscripts/stubs/rpcinfo b/ctdb/tests/eventscripts/stubs/rpcinfo index bf21197a9d4..dd6de3b1826 100755 --- a/ctdb/tests/eventscripts/stubs/rpcinfo +++ b/ctdb/tests/eventscripts/stubs/rpcinfo @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh prog="rpcinfo" diff --git a/ctdb/tests/eventscripts/stubs/ss b/ctdb/tests/eventscripts/stubs/ss index 30f9b89556b..54ff436edd7 100755 --- a/ctdb/tests/eventscripts/stubs/ss +++ b/ctdb/tests/eventscripts/stubs/ss @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh prog="ss" -- 2.17.1 From 9d42bd61ab9ddf613a6ce23480ff7b70dcdda8f5 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 17:38:42 +1000 Subject: [PATCH 08/29] ctdb-tests: Add errno matching utility BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit af8c31ead80d6c74b0e9d057cb47dff6552178a9) --- ctdb/tests/src/errcode.c | 189 +++++++++++++++++++++++++++++++++++++++ ctdb/wscript | 5 ++ 2 files changed, 194 insertions(+) create mode 100644 ctdb/tests/src/errcode.c diff --git a/ctdb/tests/src/errcode.c b/ctdb/tests/src/errcode.c new file mode 100644 index 00000000000..90853624add --- /dev/null +++ b/ctdb/tests/src/errcode.c @@ -0,0 +1,189 @@ +/* + Portability layer for error codes + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +/* + * These errors are as listed in POSIX standard + * IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) + * + * Error codes marked obsolete are removed (ENODATA, ENOSR, ENOSTR, ETIME) + */ + +#include "replace.h" + +struct { + const char *label; + int code; +} err_codes[] = { + { "E2BIG", E2BIG }, + + { "EACCES", EACCES }, + { "EADDRINUSE", EADDRINUSE }, + { "EADDRNOTAVAIL", EADDRNOTAVAIL }, + { "EAFNOSUPPORT", EAFNOSUPPORT }, + { "EAGAIN", EAGAIN }, + { "EALREADY", EALREADY }, + + { "EBADF", EBADF }, + { "EBADMSG", EBADMSG }, + { "EBUSY", EBUSY }, + + { "ECANCELED", ECANCELED }, + { "ECHILD", ECHILD }, + { "ECONNABORTED", ECONNABORTED }, + { "ECONNREFUSED", ECONNREFUSED }, + { "ECONNRESET", ECONNRESET }, + + { "EDEADLK", EDEADLK }, + { "EDESTADDRREQ", EDESTADDRREQ }, + { "EDOM", EDOM }, + { "EDQUOT", EDQUOT }, + + { "EEXIST", EEXIST }, + + { "EFAULT", EFAULT }, + { "EFBIG", EFBIG }, + + { "EHOSTUNREACH", EHOSTUNREACH }, + + { "EIDRM", EIDRM }, + { "EILSEQ", EILSEQ }, + { "EINPROGRESS", EINPROGRESS }, + { "EINTR", EINTR }, + { "EINVAL", EINVAL }, + { "EIO", EIO }, + { "EISCONN", EISCONN }, + { "EISDIR", EISDIR }, + + { "ELOOP", ELOOP }, + + { "EMFILE", EMFILE }, + { "EMLINK", EMLINK }, + { "EMSGSIZE", EMSGSIZE }, + { "EMULTIHOP", EMULTIHOP }, + + { "ENAMETOOLONG", ENAMETOOLONG }, + { "ENETDOWN", ENETDOWN }, + { "ENETRESET", ENETRESET }, + { "ENETUNREACH", ENETUNREACH }, + { "ENFILE", ENFILE }, + { "ENOBUFS", ENOBUFS }, + { "ENODEV", ENODEV }, + { "ENOENT", ENOENT }, + { "ENOEXEC", ENOEXEC }, + { "ENOLCK", ENOLCK }, + { "ENOLINK", ENOLINK }, + { "ENOMEM", ENOMEM }, + { "ENOMSG", ENOMSG }, + { "ENOPROTOOPT", ENOPROTOOPT }, + { "ENOSPC", ENOSPC }, + { "ENOSYS", ENOSYS }, + { "ENOTCONN", ENOTCONN }, + { "ENOTDIR", ENOTDIR }, + { "ENOTEMPTY", ENOTEMPTY }, + { "ENOTSOCK", ENOTSOCK }, + { "ENOTSUP", ENOTSUP }, + { "ENOTTY", ENOTTY }, + { "ENXIO", ENXIO }, + + { "EOPNOTSUPP", EOPNOTSUPP }, + { "EOVERFLOW", EOVERFLOW }, + + { "EPERM", EPERM }, + { "EPIPE", EPIPE }, + { "EPROTO", EPROTO }, + { "EPROTONOSUPPORT", EPROTONOSUPPORT }, + { "EPROTOTYPE", EPROTOTYPE }, + + { "ERANGE", ERANGE }, + { "EROFS", EROFS }, + + { "ESPIPE", ESPIPE }, + { "ESRCH", ESRCH }, + { "ESTALE", ESTALE }, + + { "ETIMEDOUT", ETIMEDOUT }, + { "ETXTBSY", ETXTBSY }, + + { "EWOULDBLOCK", EWOULDBLOCK }, + + { "EXDEV", EXDEV }, +}; + +static void dump(void) +{ + int i; + + for (i=0; i\n", argv[0]); + exit(1); + } + + if (strcmp(argv[1], "dump") == 0) { + dump(); + } else { + code = strtol(argv[1], &endptr, 0); + if (*endptr == '\0') { + match_code(code); + } else { + match_label(argv[1]); + } + } + + exit(0); +} diff --git a/ctdb/wscript b/ctdb/wscript index 73fd5bd3d00..08c8016dd39 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -842,6 +842,11 @@ def build(bld): for d in ['volatile', 'persistent', 'state']: bld.install_dir(os.path.join(bld.env.CTDB_VARDIR, d)) + bld.SAMBA_BINARY('errcode', + source='tests/src/errcode.c', + deps='replace', + install_path='${CTDB_TEST_LIBEXECDIR}') + # Unit tests ctdb_unit_tests = [ 'db_hash_test', -- 2.17.1 From ffe698728b507211593f048dc0a406f6de33c787 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 18:47:27 +1000 Subject: [PATCH 09/29] ctdb-tests: Add required_error() to match on error codes BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit e8a1b3db7abfa9e4a53e98a0aa21dfc268a21c92) --- ctdb/tests/scripts/unit.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh index 8e72803815d..e9476aef075 100644 --- a/ctdb/tests/scripts/unit.sh +++ b/ctdb/tests/scripts/unit.sh @@ -30,6 +30,13 @@ required_result () fi } +required_error () +{ + rc=$(errcode $1) + shift + required_result $rc "$@" +} + ok () { required_result 0 "$@" -- 2.17.1 From cf45040ed00738a17f6c59c39dd03007f269b508 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 18:19:09 +1000 Subject: [PATCH 10/29] ctdb-common: Switch to ETIMEDOUT from ETIME BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit a42a7232990fa163d046fb07be351ea3e0467046) --- ctdb/common/run_event.c | 4 ++-- ctdb/common/run_proc.c | 2 +- ctdb/tests/cunit/run_event_001.sh | 6 +++--- ctdb/tests/cunit/run_proc_001.sh | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ctdb/common/run_event.c b/ctdb/common/run_event.c index 20e5be84dd2..a2155500f28 100644 --- a/ctdb/common/run_event.c +++ b/ctdb/common/run_event.c @@ -844,11 +844,11 @@ static void run_event_next_script(struct tevent_req *subreq) if (! state->continue_on_failure) { state->script_list->num_scripts = state->index + 1; - if (script->summary == -ETIME && pid != -1) { + if (script->summary == -ETIMEDOUT && pid != -1) { run_event_debug(req, pid); } D_NOTICE("%s event %s\n", state->event_str, - (script->summary == -ETIME) ? + (script->summary == -ETIMEDOUT) ? "timed out" : "failed"); run_event_stop_running(state->run_ctx); diff --git a/ctdb/common/run_proc.c b/ctdb/common/run_proc.c index ee83d86da23..97895b383b9 100644 --- a/ctdb/common/run_proc.c +++ b/ctdb/common/run_proc.c @@ -452,7 +452,7 @@ static void run_proc_timedout(struct tevent_req *subreq) return; } - state->result.err = ETIME; + state->result.err = ETIMEDOUT; if (state->proc->output != NULL) { state->output = talloc_steal(state, state->proc->output); } diff --git a/ctdb/tests/cunit/run_event_001.sh b/ctdb/tests/cunit/run_event_001.sh index 6735fcbf33e..75c51111b14 100755 --- a/ctdb/tests/cunit/run_event_001.sh +++ b/ctdb/tests/cunit/run_event_001.sh @@ -106,7 +106,7 @@ ok < Date: Tue, 10 Jul 2018 18:34:13 +1000 Subject: [PATCH 11/29] ctdb-event: Switch to ETIMEDOUT instead of ETIME BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit c8756ec17be11e40bc7e75aac7afdb323acb42e2) --- ctdb/event/event_cmd.c | 4 ++-- ctdb/event/event_tool.c | 4 ++-- ctdb/tests/eventd/eventd_001.sh | 6 +++--- ctdb/tests/eventd/eventd_002.sh | 8 +++----- ctdb/tests/eventd/eventd_003.sh | 11 +++++------ ctdb/tests/eventd/eventd_004.sh | 2 +- ctdb/tests/eventd/eventd_006.sh | 2 +- ctdb/tests/eventd/eventd_007.sh | 4 ++-- ctdb/tests/eventd/eventd_011.sh | 4 ++-- ctdb/tests/eventd/eventd_012.sh | 4 ++-- ctdb/tests/eventd/eventd_013.sh | 4 ++-- ctdb/tests/eventd/eventd_021.sh | 2 +- ctdb/tests/eventd/eventd_022.sh | 2 +- ctdb/tests/eventd/eventd_023.sh | 2 +- ctdb/tests/eventd/eventd_024.sh | 2 +- ctdb/tests/eventd/eventd_032.sh | 6 +++--- ctdb/tests/eventd/eventd_033.sh | 12 ++++++------ ctdb/tests/eventd/eventd_042.sh | 2 +- ctdb/tests/eventd/eventd_043.sh | 4 ++-- ctdb/tests/eventd/eventd_052.sh | 4 ++-- 20 files changed, 43 insertions(+), 46 deletions(-) diff --git a/ctdb/event/event_cmd.c b/ctdb/event/event_cmd.c index c1163416687..db39e4d881c 100644 --- a/ctdb/event/event_cmd.c +++ b/ctdb/event/event_cmd.c @@ -130,8 +130,8 @@ static void event_cmd_run_done(struct tevent_req *subreq) goto done; } - if (script_list->summary == -ETIME) { - state->reply->result = ETIME; + if (script_list->summary == -ETIMEDOUT) { + state->reply->result = ETIMEDOUT; } else if (script_list->summary != 0) { state->reply->result = ENOEXEC; } diff --git a/ctdb/event/event_tool.c b/ctdb/event/event_tool.c index 3a99de50ece..9f755852742 100644 --- a/ctdb/event/event_tool.c +++ b/ctdb/event/event_tool.c @@ -145,7 +145,7 @@ static int event_command_run(TALLOC_CTX *mem_ctx, if (result == ENOENT) { printf("Event dir for %s does not exist\n", argv[1]); - } else if (result == ETIME) { + } else if (result == ETIMEDOUT) { printf("Event %s in %s timed out\n", argv[2], argv[1]); } else if (result == ECANCELED) { printf("Event %s in %s got cancelled\n", argv[2], argv[1]); @@ -170,7 +170,7 @@ static double timeval_delta(struct timeval *tv2, struct timeval *tv) static void print_status_one(struct ctdb_event_script *script) { - if (script->result == -ETIME) { + if (script->result == -ETIMEDOUT) { printf("%-20s %-10s %s", script->name, "TIMEDOUT", diff --git a/ctdb/tests/eventd/eventd_001.sh b/ctdb/tests/eventd/eventd_001.sh index 106f6b8e75c..3f4e8e46857 100755 --- a/ctdb/tests/eventd/eventd_001.sh +++ b/ctdb/tests/eventd/eventd_001.sh @@ -6,17 +6,17 @@ define_test "non-existent eventscript directory" setup_eventd -required_result 2 < Date: Tue, 10 Jul 2018 18:18:33 +1000 Subject: [PATCH 12/29] ctdb-daemon: Switch to using ETIMEDOUT instead of ETIME BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit b886a95eca306d0062240e5710ae0ed4505b1068) --- ctdb/server/ctdb_client.c | 2 +- ctdb/server/ctdb_monitor.c | 2 +- ctdb/server/ctdb_recover.c | 2 +- ctdb/server/ctdb_takeover.c | 8 ++++---- ctdb/server/eventscript.c | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ctdb/server/ctdb_client.c b/ctdb/server/ctdb_client.c index 67c89dee3d0..98c61cb7452 100644 --- a/ctdb/server/ctdb_client.c +++ b/ctdb/server/ctdb_client.c @@ -1638,7 +1638,7 @@ static void async_callback(struct ctdb_client_control_state *state) } data->fail_count++; if (state->state == CTDB_CONTROL_TIMEOUT) { - res = -ETIME; + res = -ETIMEDOUT; } else { res = -1; } diff --git a/ctdb/server/ctdb_monitor.c b/ctdb/server/ctdb_monitor.c index 68884ac5c11..cfa3a6a1bfa 100644 --- a/ctdb/server/ctdb_monitor.c +++ b/ctdb/server/ctdb_monitor.c @@ -134,7 +134,7 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p) goto after_change_status; } - if (status == ETIME) { + if (status == ETIMEDOUT) { ctdb->monitor->event_script_timeouts++; if (ctdb->monitor->event_script_timeouts >= diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index f4cd5f64eee..fc64037b95f 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -1048,7 +1048,7 @@ static void ctdb_end_recovery_callback(struct ctdb_context *ctdb, int status, vo if (status != 0) { DEBUG(DEBUG_ERR,(__location__ " recovered event script failed (status %d)\n", status)); - if (status == -ETIME) { + if (status == -ETIMEDOUT) { ctdb_ban_self(ctdb); } } diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 3f5536de3bb..35e83057560 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -464,7 +464,7 @@ static void ctdb_do_takeip_callback(struct ctdb_context *ctdb, int status, TDB_DATA data; if (status != 0) { - if (status == -ETIME) { + if (status == -ETIMEDOUT) { ctdb_ban_self(ctdb); } DEBUG(DEBUG_ERR,(__location__ " Failed to takeover IP %s on interface %s\n", @@ -585,7 +585,7 @@ static void ctdb_do_updateip_callback(struct ctdb_context *ctdb, int status, talloc_get_type(private_data, struct ctdb_do_updateip_state); if (status != 0) { - if (status == -ETIME) { + if (status == -ETIMEDOUT) { ctdb_ban_self(ctdb); } DEBUG(DEBUG_ERR, @@ -884,7 +884,7 @@ static void release_ip_callback(struct ctdb_context *ctdb, int status, struct release_ip_callback_state *state = talloc_get_type(private_data, struct release_ip_callback_state); - if (status == -ETIME) { + if (status == -ETIMEDOUT) { ctdb_ban_self(ctdb); } @@ -2257,7 +2257,7 @@ static void ctdb_ipreallocated_callback(struct ctdb_context *ctdb, DEBUG(DEBUG_ERR, (" \"ipreallocated\" event script failed (status %d)\n", status)); - if (status == -ETIME) { + if (status == -ETIMEDOUT) { ctdb_ban_self(ctdb); } } diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index de05443e66c..4ef3b80706a 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -562,7 +562,7 @@ static void ctdb_event_script_run_done(int result, void *private_data) struct ctdb_event_script_run_state *state = talloc_get_type_abort( private_data, struct ctdb_event_script_run_state); - if (result == ETIME) { + if (result == ETIMEDOUT) { switch (state->event) { case CTDB_EVENT_START_RECOVERY: case CTDB_EVENT_RECOVERED: @@ -716,7 +716,7 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_event call, tevent_loop_once(ctdb->ev); } - if (state.status == ETIME) { + if (state.status == ETIMEDOUT) { /* Don't ban self if CTDB is starting up or shutting down */ if (call != CTDB_EVENT_INIT && call != CTDB_EVENT_SHUTDOWN) { DEBUG(DEBUG_ERR, -- 2.17.1 From a4c4c2b62d10ac4981c41d5afff4b9c168b4a2b2 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 18:48:53 +1000 Subject: [PATCH 13/29] ctdb-client: Switch to ETIMEDOUT instead of ETIME BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit e1236a855ffc493efb5e9cb7b295034376e56d3a) --- ctdb/client/client.h | 2 +- ctdb/client/client_connect.c | 2 +- ctdb/tests/src/dummy_client.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ctdb/client/client.h b/ctdb/client/client.h index 2eec3eaed63..d4d145045e0 100644 --- a/ctdb/client/client.h +++ b/ctdb/client/client.h @@ -184,7 +184,7 @@ void ctdb_client_wait(struct tevent_context *ev, bool *done); * @param[in] ev Tevent context * @param[in] done Boolean flag to indicate when to stop waiting * @param[in] timeout How long to wait - * @return 0 on succes, ETIME on timeout, and errno on failure + * @return 0 on succes, ETIMEDOUT on timeout, and errno on failure */ int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done, struct timeval timeout); diff --git a/ctdb/client/client_connect.c b/ctdb/client/client_connect.c index 1e4157e94ff..0977d717608 100644 --- a/ctdb/client/client_connect.c +++ b/ctdb/client/client_connect.c @@ -363,7 +363,7 @@ int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done, talloc_free(mem_ctx); if (timed_out) { - return ETIME; + return ETIMEDOUT; } return 0; diff --git a/ctdb/tests/src/dummy_client.c b/ctdb/tests/src/dummy_client.c index 6f30512ee65..cc6444de968 100644 --- a/ctdb/tests/src/dummy_client.c +++ b/ctdb/tests/src/dummy_client.c @@ -155,7 +155,7 @@ int main(int argc, const char *argv[]) ret = ctdb_client_wait_timeout(ev, &done, tevent_timeval_current_ofs(options.timelimit, 0)); - if (ret != 0 && ret == ETIME) { + if (ret != 0 && ret == ETIMEDOUT) { D_ERR("client_wait_timeout() failed, ret=%d\n", ret); talloc_free(client); exit(1); -- 2.17.1 From ccb753feda5176e42750b0af945a1acd3b9ecd12 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 18:54:11 +1000 Subject: [PATCH 14/29] ctdb-tests: Add ps output filter for freebsd BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit b7dbe9f306fda0d8f1dcc8dd81864539f6ff2632) --- ctdb/tests/cunit/run_proc_001.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ctdb/tests/cunit/run_proc_001.sh b/ctdb/tests/cunit/run_proc_001.sh index c6aee3721fa..ac0c0da6ca4 100755 --- a/ctdb/tests/cunit/run_proc_001.sh +++ b/ctdb/tests/cunit/run_proc_001.sh @@ -127,7 +127,8 @@ unit_test run_proc_test 1 -1 "$prog" result_filter () { _header=" *PID *TTY *TIME *CMD" - sed -e "s|^${_header}|HEADER|" + _header2=" *PID *TT *STAT *TIME *COMMAND" + sed -e "s|^${_header}|HEADER|" -e "s|^${_header2}|HEADER|" } pid=$(cat "$pidfile") -- 2.17.1 From cc8c825e972806536c5bffc6d75edc844e63b0e2 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 19:09:00 +1000 Subject: [PATCH 15/29] ctdb-tests: Add signal code matching utility BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit b0028dd5bf2d5466a50dfd12a82a23f30e9ccf48) --- ctdb/tests/src/sigcode.c | 120 +++++++++++++++++++++++++++++++++++++++ ctdb/wscript | 5 ++ 2 files changed, 125 insertions(+) create mode 100644 ctdb/tests/src/sigcode.c diff --git a/ctdb/tests/src/sigcode.c b/ctdb/tests/src/sigcode.c new file mode 100644 index 00000000000..1318d246891 --- /dev/null +++ b/ctdb/tests/src/sigcode.c @@ -0,0 +1,120 @@ +/* + Portability layer for signal codes + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +/* + * These signals are as listed in POSIX standard + * IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) + */ + +#include "replace.h" +#include "system/wait.h" + +struct { + const char *label; + int code; +} sig_codes[] = { + { "SIGABRT", SIGABRT }, + { "SIGALRM", SIGALRM }, + { "SIBGUS", SIGBUS }, + { "SIGCHLD", SIGCHLD }, + { "SIGCONT", SIGCONT }, + { "SIGFPE", SIGFPE }, + { "SIGHUP", SIGHUP }, + { "SIGILL", SIGILL }, + { "SIGINT", SIGINT }, + { "SIGKILL", SIGKILL }, + { "SIGPIPE", SIGPIPE }, + { "SIGQUIT", SIGQUIT }, + { "SIGSEGV", SIGSEGV }, + { "SIGSTOP", SIGSTOP }, + { "SIGTERM", SIGTERM }, + { "SIGTSTP", SIGTSTP }, + { "SIGTTIN", SIGTTIN }, + { "SIGTTOU", SIGTTOU }, + { "SIGUSR1", SIGUSR1 }, + { "SIGUSR2", SIGUSR2 }, + { "SIGTRAP", SIGTRAP }, + { "SIGURG", SIGURG }, + { "SIGXCPU", SIGXCPU }, + { "SIGXFSZ", SIGXFSZ }, + +}; + +static void dump(void) +{ + int i; + + for (i=0; i\n", argv[0]); + exit(1); + } + + if (strcmp(argv[1], "dump") == 0) { + dump(); + } else { + code = strtol(argv[1], &endptr, 0); + if (*endptr == '\0') { + match_code(code); + } else { + match_label(argv[1]); + } + } + + exit(0); +} diff --git a/ctdb/wscript b/ctdb/wscript index 08c8016dd39..c26bd8c0d9a 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -847,6 +847,11 @@ def build(bld): deps='replace', install_path='${CTDB_TEST_LIBEXECDIR}') + bld.SAMBA_BINARY('sigcode', + source='tests/src/sigcode.c', + deps='replace', + install_path='${CTDB_TEST_LIBEXECDIR}') + # Unit tests ctdb_unit_tests = [ 'db_hash_test', -- 2.17.1 From f80514c85327cd309b95a82c85fe84c55983a637 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 10 Jul 2018 19:11:18 +1000 Subject: [PATCH 16/29] ctdb-tests: Use sigcode to match signals BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 23952c9165bbdcae8f34b7dfefdbb4a499a55362) --- ctdb/tests/cunit/sock_daemon_test_001.sh | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ctdb/tests/cunit/sock_daemon_test_001.sh b/ctdb/tests/cunit/sock_daemon_test_001.sh index e5bae38d3a0..1b64c2ca9ff 100755 --- a/ctdb/tests/cunit/sock_daemon_test_001.sh +++ b/ctdb/tests/cunit/sock_daemon_test_001.sh @@ -38,20 +38,20 @@ ok < Date: Wed, 11 Jul 2018 17:23:43 +1000 Subject: [PATCH 17/29] ctdb-tests: Porting tests should ignore unsupported features BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 0273171c30a5bcfdfc0b3f74c1d5a89dbaa5b204) --- ctdb/tests/cunit/porting_tests_001.sh | 13 +++++++++---- ctdb/tests/src/porting_tests.c | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ctdb/tests/cunit/porting_tests_001.sh b/ctdb/tests/cunit/porting_tests_001.sh index ba69fb95c44..45ae6194610 100755 --- a/ctdb/tests/cunit/porting_tests_001.sh +++ b/ctdb/tests/cunit/porting_tests_001.sh @@ -11,11 +11,16 @@ remove_socket () test_cleanup remove_socket -uid=$(id -u) -if [ "$uid" -eq 0 ] ; then - ok "ctdb_sys_check_iface_exists: Interface 'fake' not found" +os=$(uname) +if [ "$os" = "Linux" ] ; then + uid=$(id -u) + if [ "$uid" -eq 0 ] ; then + ok "ctdb_sys_check_iface_exists: Interface 'fake' not found" + else + ok "ctdb_sys_check_iface_exists: Failed to open raw socket" + fi else - ok "ctdb_sys_check_iface_exists: Failed to open raw socket" + ok_null fi unit_test porting_tests --socket=${socket} diff --git a/ctdb/tests/src/porting_tests.c b/ctdb/tests/src/porting_tests.c index 74dbf0781b4..8902c34dfc2 100644 --- a/ctdb/tests/src/porting_tests.c +++ b/ctdb/tests/src/porting_tests.c @@ -192,11 +192,15 @@ static int test_ctdb_get_peer_pid(void) fd = socket_server_wait_peer(); ret = ctdb_get_peer_pid(fd, &peer_pid); - assert(ret == 0); + assert(ret == 0 || ret == ENOSYS); - assert(peer_pid == globals.helper_pid); + if (ret == 0) { + assert(peer_pid == globals.helper_pid); - kill(peer_pid, SIGTERM); + kill(peer_pid, SIGTERM); + } else { + kill(globals.helper_pid, SIGTERM); + } close(fd); return 0; -- 2.17.1 From 6cc9f2d89b80270773f62a1c46916aa9cad2abf4 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 18 Jul 2018 18:42:10 +1000 Subject: [PATCH 18/29] ctdb-common: Add line based I/O BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit c7041b0faf490661818244dd032ad413ce906e5c) --- ctdb/common/line.c | 145 ++++++++++++++++++++++++++++++ ctdb/common/line.h | 62 +++++++++++++ ctdb/tests/cunit/line_test_001.sh | 90 +++++++++++++++++++ ctdb/tests/src/line_test.c | 102 +++++++++++++++++++++ ctdb/wscript | 3 +- 5 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 ctdb/common/line.c create mode 100644 ctdb/common/line.h create mode 100755 ctdb/tests/cunit/line_test_001.sh create mode 100644 ctdb/tests/src/line_test.c diff --git a/ctdb/common/line.c b/ctdb/common/line.c new file mode 100644 index 00000000000..c4c6726875b --- /dev/null +++ b/ctdb/common/line.c @@ -0,0 +1,145 @@ +/* + Line based I/O over fds + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include "replace.h" + +#include + +#include "lib/util/sys_rw.h" + +#include "common/line.h" + +struct line_read_state { + line_process_fn_t callback; + void *private_data; + char *buf; + size_t hint, len, offset; + int num_lines; +}; + +static bool line_read_one(char *buf, size_t start, size_t len, size_t *pos) +{ + size_t i; + + for (i=start; ibuf, start, state->offset, &pos); + if (! ok) { + break; + } + + state->buf[pos] = '\0'; + state->num_lines += 1; + + ret = state->callback(state->buf + start, state->private_data); + if (ret != 0) { + return ret; + } + + start = pos+1; + } + + if (pos > 0) { + if (pos+1 < state->offset) { + memmove(state->buf, + state->buf + pos+1, + state->offset - (pos+1)); + } + state->offset -= (pos+1); + } + + return 0; +} + +int line_read(int fd, + size_t length, + TALLOC_CTX *mem_ctx, + line_process_fn_t callback, + void *private_data, + int *num_lines) +{ + struct line_read_state state; + + if (length < 32) { + length = 32; + } + + state = (struct line_read_state) { + .callback = callback, + .private_data = private_data, + .hint = length, + }; + + while (1) { + ssize_t n; + int ret; + + if (state.offset == state.len) { + state.len += state.hint; + state.buf = talloc_realloc_size(mem_ctx, + state.buf, + state.len); + if (state.buf == NULL) { + return ENOMEM; + } + } + + n = sys_read(fd, + state.buf + state.offset, + state.len - state.offset); + if (n < 0) { + return errno; + } + if (n == 0) { + break; + } + + state.offset += n; + + ret = line_read_process(&state); + if (ret != 0) { + if (num_lines != NULL) { + *num_lines = state.num_lines; + } + return ret; + } + } + + if (num_lines != NULL) { + *num_lines = state.num_lines; + } + return 0; +} diff --git a/ctdb/common/line.h b/ctdb/common/line.h new file mode 100644 index 00000000000..6b67f1e92e1 --- /dev/null +++ b/ctdb/common/line.h @@ -0,0 +1,62 @@ +/* + Line based I/O over fds + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#ifndef __CTDB_LINE_H__ +#define __CTDB_LINE_H__ + +#include + +/** + * @file line.h + * + * @brief Line based I/O over pipes and sockets + */ + +/** + * @brief The callback routine called to process a line + * + * @param[in] line The line read + * @param[in] private_data Private data for callback + * @return 0 to continue processing lines, non-zero to stop reading + */ +typedef int (*line_process_fn_t)(char *line, void *private_data); + +/** + * @brief Read a line (terminated by \n or \0) + * + * If there is any read error on fd, then errno will be returned. + * If callback function returns a non-zero value, then that value will be + * returned. + * + * @param[in] fd The file descriptor + * @param[in] length The expected length of a line (this is only a hint) + * @param[in] mem_ctx Talloc memory context + * @param[in] callback Callback function called when a line is read + * @param[in] private_data Private data for callback + * @param[out] num_lines Number of lines read so far + * @return 0 on on success, errno on failure + */ +int line_read(int fd, + size_t length, + TALLOC_CTX *mem_ctx, + line_process_fn_t callback, + void *private_data, + int *num_lines); + +#endif /* __CTDB_LINE_H__ */ diff --git a/ctdb/tests/cunit/line_test_001.sh b/ctdb/tests/cunit/line_test_001.sh new file mode 100755 index 00000000000..991d01a24e7 --- /dev/null +++ b/ctdb/tests/cunit/line_test_001.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +tfile="${TEST_VAR_DIR}/line.$$" + +remove_files () +{ + rm -f "$tfile" +} + +test_cleanup remove_files + +> "$tfile" + +ok_null +unit_test line_test "$tfile" + +printf "\0" > "$tfile" + +required_result 1 < "$tfile" + +ok_null +unit_test line_test "$tfile" + +cat < "$tfile" +hello +world +EOF + +required_result 2 << EOF +hello +world +EOF +unit_test line_test "$tfile" + +required_result 2 << EOF +hello +world +EOF +unit_test line_test "$tfile" + +cat < "$tfile" +This is a really long long line full of random words and hopefully it will be read properly by the line test program and identified as a single line +EOF + +required_result 1 < "$tfile" +line number one +line number two +line number one +line number two +line number one +EOF + +required_result 5 < "$tfile" +this is line number one +this is line number two +this is line number three +this is line number four +this is line number five +EOF + +required_result 5 <. +*/ + +#include "replace.h" +#include "system/filesys.h" + +#include +#include + +#include "common/line.c" + +static int line_print(char *line, void *private_data) +{ + printf("%s\n", line); + fflush(stdout); + + return 0; +} + +int main(int argc, const char **argv) +{ + TALLOC_CTX *mem_ctx; + size_t hint = 32; + pid_t pid; + int ret, lines = 0; + int pipefd[2]; + + if (argc < 2 || argc > 3) { + fprintf(stderr, "Usage: %s []\n", argv[0]); + exit(1); + } + + if (argc == 3) { + long value; + + value = atol(argv[2]); + assert(value > 0); + hint = value; + } + + ret = pipe(pipefd); + assert(ret == 0); + + pid = fork(); + assert(pid != -1); + + if (pid == 0) { + char buffer[16]; + ssize_t n, n2; + int fd; + + close(pipefd[0]); + + fd = open(argv[1], O_RDONLY); + assert(fd != -1); + + while (1) { + n = read(fd, buffer, sizeof(buffer)); + assert(n >= 0 && n <= sizeof(buffer)); + + if (n == 0) { + break; + } + + n2 = write(pipefd[1], buffer, n); + assert(n2 == n); + } + + close(pipefd[1]); + close(fd); + + exit(0); + } + + close(pipefd[1]); + + mem_ctx = talloc_new(NULL); + assert(mem_ctx != NULL); + + ret = line_read(pipefd[0], hint, NULL, line_print, NULL, &lines); + assert(ret == 0); + + talloc_free(mem_ctx); + + return lines; +} diff --git a/ctdb/wscript b/ctdb/wscript index c26bd8c0d9a..6d69545b6aa 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -404,7 +404,7 @@ def build(bld): pidfile.c run_proc.c hash_count.c run_event.c sock_client.c version.c - cmdline.c path.c conf.c + cmdline.c path.c conf.c line.c '''), deps='''samba-util sys_rw tevent-util replace talloc tevent tdb popt''') @@ -868,6 +868,7 @@ def build(bld): 'run_event_test', 'cmdline_test', 'conf_test', + 'line_test', ] for target in ctdb_unit_tests: -- 2.17.1 From c23f7ae19f33bcc86f5e218a4f57533aefe50f29 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 11 Jul 2018 18:35:46 +1000 Subject: [PATCH 19/29] ctdb-protocol: Avoid fgets in ctdb_connection_list_read C library buffering API can behave in unexpected fashion if underlying fd for stdin, stdout or stderr is closed and re-opened. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit c9b42d27e6cf9e6ae36f44970f0a388edc737a7a) --- ctdb/protocol/protocol_util.c | 86 ++++++++++++++++++++--------------- ctdb/wscript | 4 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index c75555fa734..45c639d747f 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -22,6 +22,8 @@ #include +#include "common/line.h" + #include "protocol.h" #include "protocol_util.h" @@ -603,56 +605,66 @@ const char *ctdb_connection_list_to_string( return out; } -int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, - struct ctdb_connection_list **conn_list) -{ +struct ctdb_connection_list_read_state { struct ctdb_connection_list *list; - char line[128]; /* long enough for IPv6 */ + bool client_first; +}; + +static int ctdb_connection_list_read_line(char *line, void *private_data) +{ + struct ctdb_connection_list_read_state *state = + (struct ctdb_connection_list_read_state *)private_data; + struct ctdb_connection conn; int ret; - if (conn_list == NULL) { - return EINVAL; + /* Skip empty lines */ + if (line[0] == '\0') { + return 0; } - list = talloc_zero(mem_ctx, struct ctdb_connection_list); - if (list == NULL) { - return ENOMEM; + /* Comment */ + if (line[0] == '#') { + return 0; } - while (fgets(line, sizeof(line), stdin) != NULL) { - char *t; - struct ctdb_connection conn; + ret = ctdb_connection_from_string(line, state->client_first, &conn); + if (ret != 0) { + return ret; + } - /* Skip empty lines */ - if (line[0] == '\n') { - continue; - } + ret = ctdb_connection_list_add(state->list, &conn); + if (ret != 0) { + return ret; + } - /* Comment */ - if (line[0] == '#') { - continue; - } + return 0; +} - t = strtok(line, "\n"); - if (t == NULL) { - goto fail; - } +int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, + struct ctdb_connection_list **conn_list) +{ + struct ctdb_connection_list_read_state state; + int ret; - ret = ctdb_connection_from_string(t, client_first, &conn); - if (ret != 0) { - goto fail; - } + if (conn_list == NULL) { + return EINVAL; + } - ret = ctdb_connection_list_add(list, &conn); - if (ret != 0) { - goto fail; - } + state.list = talloc_zero(mem_ctx, struct ctdb_connection_list); + if (state.list == NULL) { + return ENOMEM; } - *conn_list = list; - return 0; + state.client_first = client_first; + + ret = line_read(0, + 128, + mem_ctx, + ctdb_connection_list_read_line, + &state, + NULL); -fail: - talloc_free(list); - return EINVAL; + *conn_list = state.list; + + return ret; } diff --git a/ctdb/wscript b/ctdb/wscript index 6d69545b6aa..6e69e499985 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -434,7 +434,7 @@ def build(bld): bld.SAMBA_SUBSYSTEM('ctdb-protocol-util', source='protocol/protocol_util.c', - deps='replace talloc tdb') + deps='ctdb-util replace talloc tdb') bld.SAMBA_SUBSYSTEM('ctdb-client', source=bld.SUBDIR('client', @@ -938,7 +938,7 @@ def build(bld): bld.SAMBA_BINARY(target, source=src, deps='''ctdb-protocol-tests-common - samba-util talloc tdb''', + samba-util ctdb-util talloc tdb''', install_path='${CTDB_TEST_LIBEXECDIR}') bld.SAMBA_BINARY('event_protocol_test', -- 2.17.1 From 793f31edc2d735d4bc0c71ce496460a0007f7a60 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 18 Jul 2018 19:00:42 +1000 Subject: [PATCH 20/29] ctdb-common: Add fd argument to ctdb_connection_list_read() This makes testing easier. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 3bf753e830c20183ef4f3278880d3be362e53bef) --- ctdb/protocol/protocol_util.c | 6 ++++-- ctdb/protocol/protocol_util.h | 4 +++- ctdb/tests/src/protocol_util_test.c | 18 ++++++------------ ctdb/tools/ctdb.c | 6 +++--- ctdb/tools/ctdb_killtcp.c | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 45c639d747f..77e79867443 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -640,7 +640,9 @@ static int ctdb_connection_list_read_line(char *line, void *private_data) return 0; } -int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, +int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, + int fd, + bool client_first, struct ctdb_connection_list **conn_list) { struct ctdb_connection_list_read_state state; @@ -657,7 +659,7 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, state.client_first = client_first; - ret = line_read(0, + ret = line_read(fd, 128, mem_ctx, ctdb_connection_list_read_line, diff --git a/ctdb/protocol/protocol_util.h b/ctdb/protocol/protocol_util.h index 66a49136576..347fe8a275a 100644 --- a/ctdb/protocol/protocol_util.h +++ b/ctdb/protocol/protocol_util.h @@ -66,7 +66,9 @@ int ctdb_connection_list_sort(struct ctdb_connection_list *conn_list); const char *ctdb_connection_list_to_string( TALLOC_CTX *mem_ctx, struct ctdb_connection_list *conn_list, bool client_first); -int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, +int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, + int fd, + bool client_first, struct ctdb_connection_list **conn_list); #endif /* __CTDB_PROTOCOL_UTIL_H__ */ diff --git a/ctdb/tests/src/protocol_util_test.c b/ctdb/tests/src/protocol_util_test.c index eb7eb0ff88f..5608b13920c 100644 --- a/ctdb/tests/src/protocol_util_test.c +++ b/ctdb/tests/src/protocol_util_test.c @@ -153,7 +153,7 @@ static void test_connection_list_read(const char *s1, const char *s2) TALLOC_CTX *tmp_ctx; int pipefd[2]; pid_t pid; - struct ctdb_connection_list *conn_list; + struct ctdb_connection_list *conn_list = NULL; const char *t; int ret; @@ -182,14 +182,11 @@ static void test_connection_list_read(const char *s1, const char *s2) close(pipefd[1]); - ret = dup2(pipefd[0], STDIN_FILENO); - assert(ret != -1); + ret = ctdb_connection_list_read(tmp_ctx, pipefd[0], false, &conn_list); + assert(ret == 0); close(pipefd[0]); - ret = ctdb_connection_list_read(tmp_ctx, false, &conn_list); - assert(ret == 0); - ret = ctdb_connection_list_sort(conn_list); assert(ret == 0); @@ -206,7 +203,7 @@ static void test_connection_list_read_bad(const char *s1) TALLOC_CTX *tmp_ctx; int pipefd[2]; pid_t pid; - struct ctdb_connection_list *conn_list; + struct ctdb_connection_list *conn_list = NULL; int ret; tmp_ctx = talloc_new(NULL); @@ -234,14 +231,11 @@ static void test_connection_list_read_bad(const char *s1) close(pipefd[1]); - ret = dup2(pipefd[0], STDIN_FILENO); - assert(ret != -1); + ret = ctdb_connection_list_read(tmp_ctx, pipefd[0], false, &conn_list); + assert(ret == EINVAL); close(pipefd[0]); - ret = ctdb_connection_list_read(tmp_ctx, false, &conn_list); - assert(ret == EINVAL); - talloc_free(tmp_ctx); } diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 9d5d7b81056..4c0bcaf26ff 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -3029,7 +3029,7 @@ static int control_tickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, unsigned int num_failed; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } @@ -3247,7 +3247,7 @@ static int control_addtickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, struct tevent_req *req; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } @@ -3312,7 +3312,7 @@ static int control_deltickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, struct tevent_req *req; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } diff --git a/ctdb/tools/ctdb_killtcp.c b/ctdb/tools/ctdb_killtcp.c index bd5da0834b7..8537a579670 100644 --- a/ctdb/tools/ctdb_killtcp.c +++ b/ctdb/tools/ctdb_killtcp.c @@ -372,7 +372,7 @@ int main(int argc, char **argv) goto fail; } } else { - ret = ctdb_connection_list_read(mem_ctx, true, &conn_list); + ret = ctdb_connection_list_read(mem_ctx, 0, true, &conn_list); if (ret != 0) { D_ERR("Unable to parse connections (%s)\n", strerror(ret)); -- 2.17.1 From b3c456d318a8d0a7cc486c04ed3c2f69a3109420 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 19 Jul 2018 14:30:17 +1000 Subject: [PATCH 21/29] ctdb-tests: Do not try to match pstree output in eventd tests BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 4152e98c0e95a938e17f95c543c2114bbf54b136) --- ctdb/tests/eventd/etc-ctdb/debug-script.sh | 2 +- ctdb/tests/eventd/eventd_022.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ctdb/tests/eventd/etc-ctdb/debug-script.sh b/ctdb/tests/eventd/etc-ctdb/debug-script.sh index 47c75a78622..d54de7e8ca3 100755 --- a/ctdb/tests/eventd/etc-ctdb/debug-script.sh +++ b/ctdb/tests/eventd/etc-ctdb/debug-script.sh @@ -8,7 +8,7 @@ case "$2" in ;; "verbosetimeout") - (pstree $1 ; ctdb-event status random $2) > "$log" + (ctdb-event status random $2) > "$log" ;; "verbosetimeout2") diff --git a/ctdb/tests/eventd/eventd_022.sh b/ctdb/tests/eventd/eventd_022.sh index 149aa471e9e..3f1c4f66c16 100755 --- a/ctdb/tests/eventd/eventd_022.sh +++ b/ctdb/tests/eventd/eventd_022.sh @@ -15,7 +15,6 @@ simple_test run 5 random verbosetimeout sleep 5 ok < Date: Thu, 19 Jul 2018 12:08:20 +1000 Subject: [PATCH 22/29] ctdb-tests: Simplify pattern matching for ctime output On freebsd, sed does not accept multiple pattern strings. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 68542dbb5ab7b9d17b476937d1c84fe19d893255) --- ctdb/tests/eventd/scripts/local.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ctdb/tests/eventd/scripts/local.sh b/ctdb/tests/eventd/scripts/local.sh index 524420f05a6..9668632dca3 100644 --- a/ctdb/tests/eventd/scripts/local.sh +++ b/ctdb/tests/eventd/scripts/local.sh @@ -109,9 +109,9 @@ simple_test () result_filter () { _duration="\<[0-9][0-9]*\.[0-9][0-9][0-9]\>" - _day="\(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\)" - _month="\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)" - _date="\( [0-9]\|[0-9][0-9]\)" + _day="[FMSTW][aehoru][deintu]" + _month="[ADFJMNOS][aceopu][bcglnprtvy]" + _date="[ 0-9][0-9]" _time="[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" _year="[0-9][0-9][0-9][0-9]" _datetime="${_day} ${_month} ${_date} ${_time} ${_year}" -- 2.17.1 From 830633b5b841bf9e78b54af522068573f252bdc0 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 19 Jul 2018 14:43:09 +1000 Subject: [PATCH 23/29] ctdb-scripts: date "+%N" is non-portable BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 96d5c7de82f795e33e9998e0fe94ddcb50e7421d) --- ctdb/config/events/legacy/00.ctdb.script | 2 +- ctdb/tests/eventscripts/00.ctdb.init.009.sh | 1 + ctdb/tests/eventscripts/scripts/00.ctdb.sh | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ctdb/config/events/legacy/00.ctdb.script b/ctdb/config/events/legacy/00.ctdb.script index 8db4a19d184..05ce2bec14b 100755 --- a/ctdb/config/events/legacy/00.ctdb.script +++ b/ctdb/config/events/legacy/00.ctdb.script @@ -83,7 +83,7 @@ check_non_persistent_databases () for _db in "${_dir}/"*.tdb.*[0-9] ; do [ -r "$_db" ] || continue check_tdb "$_db" || { - _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt" + _backup="${_db}.$(date +'%Y%m%d.%H%M%S').corrupt" cat < Date: Thu, 19 Jul 2018 15:27:51 +1000 Subject: [PATCH 24/29] ctdb-tests: Use portable wc -c instead of stat -c "%s" BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 07844c2ec9583362594241e607d81aaead8f1a99) --- ctdb/config/functions | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ctdb/config/functions b/ctdb/config/functions index 5cc995adf3f..09b32097e01 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -750,7 +750,10 @@ ctdb_counter_incr () { ctdb_counter_get () { _ctdb_counter_common "$1" # unary counting! - stat -c "%s" "$_counter_file" 2>/dev/null || echo 0 + _val=$(wc -c < "$_counter_file" 2>/dev/null || echo 0) + # Strip leading spaces from ouput of wc (on freebsd) + # shellcheck disable=SC2086 + echo $_val } ######################################################## -- 2.17.1 From de2d5fa4ded2f48793267072c17e9aedeaee855d Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 19 Jul 2018 16:10:15 +1000 Subject: [PATCH 25/29] ctdb-tests: Replace md5sum with posix cksum BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 22c3078c8b10c88f8aff22caa7c92a06f387f17d) --- ctdb/config/functions | 4 ++-- ctdb/tests/eventscripts/scripts/11.natgw.sh | 8 ++++---- ctdb/tests/eventscripts/stubs/ip | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ctdb/config/functions b/ctdb/config/functions index 09b32097e01..7a47c9d8e79 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -867,8 +867,8 @@ if ! type mktemp >/dev/null 2>&1 ; then fi _d="${TMPDIR:-/tmp}" _hex10=$(dd if=/dev/urandom count=20 2>/dev/null | \ - md5sum | \ - sed -e 's@\(..........\).*@\1@') + cksum | \ + awk '{print $1}') _t="${_d}/tmp.${_hex10}" ( umask 077 diff --git a/ctdb/tests/eventscripts/scripts/11.natgw.sh b/ctdb/tests/eventscripts/scripts/11.natgw.sh index 1bdcb690b15..75b2771899c 100644 --- a/ctdb/tests/eventscripts/scripts/11.natgw.sh +++ b/ctdb/tests/eventscripts/scripts/11.natgw.sh @@ -46,8 +46,8 @@ EOF ok_natgw_master_ip_addr_show () { _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" | - md5sum | - sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@') + cksum | + sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') # This is based on CTDB_NATGW_PUBLIC_IP _brd="10.1.1.255" @@ -63,8 +63,8 @@ EOF ok_natgw_slave_ip_addr_show () { _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" | - md5sum | - sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@') + cksum | + sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') ok < mtu 1500 qdisc pfifo_fast state UP qlen 1000 diff --git a/ctdb/tests/eventscripts/stubs/ip b/ctdb/tests/eventscripts/stubs/ip index 1c4ad35b50a..630d0e8b433 100755 --- a/ctdb/tests/eventscripts/stubs/ip +++ b/ctdb/tests/eventscripts/stubs/ip @@ -124,7 +124,7 @@ ip_link_show () _opts=" mtu 65536 qdisc noqueue state UNKNOWN" ;; *) - _mac=$(echo $dev | md5sum | sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@') + _mac=$(echo $dev | cksum | sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@') _brd="ff:ff:ff:ff:ff:ff" _type="ether" _opts=" mtu 1500 qdisc pfifo_fast state ${_state} qlen 1000" -- 2.17.1 From 1b0e0bf164bdd69e8781b90fabf41ebc34ca33c1 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 19 Jul 2018 17:40:40 +1000 Subject: [PATCH 26/29] ctdb-tests: Use errcode to translate ETIMEDOUT BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 65cc36f24d8a92c749dbc3700802e1d83a9ceb9f) --- ctdb/tests/takeover_helper/210.sh | 6 +++--- ctdb/tests/takeover_helper/211.sh | 6 +++--- ctdb/tests/takeover_helper/220.sh | 6 +++--- ctdb/tests/takeover_helper/230.sh | 8 ++++---- ctdb/tests/takeover_helper/240.sh | 6 +++--- ctdb/tests/takeover_helper/250.sh | 6 +++--- ctdb/tests/takeover_helper/260.sh | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ctdb/tests/takeover_helper/210.sh b/ctdb/tests/takeover_helper/210.sh index 207949e1165..eacf0242a3f 100755 --- a/ctdb/tests/takeover_helper/210.sh +++ b/ctdb/tests/takeover_helper/210.sh @@ -15,11 +15,11 @@ CONTROLFAILS EOF -required_result 110 < Date: Thu, 19 Jul 2018 17:41:07 +1000 Subject: [PATCH 27/29] ctdb-tests: Fix a typo BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 6f5ed2b8b829e01fc675537e47095868ff8b5aa2) --- ctdb/tests/takeover_helper/scripts/local.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/tests/takeover_helper/scripts/local.sh b/ctdb/tests/takeover_helper/scripts/local.sh index 2bab8c7a06e..40ba617573a 100644 --- a/ctdb/tests/takeover_helper/scripts/local.sh +++ b/ctdb/tests/takeover_helper/scripts/local.sh @@ -109,5 +109,5 @@ test_takeover_helper () unit_test_notrace takeover_helper_format_outfd _ret=$? rm "$takeover_helper_out" - [ $? -eq 0 ] || exit $? + [ $_ret -eq 0 ] || exit $_ret } -- 2.17.1 From beb551e13a81422834d1207834701c2a12f666e2 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 19 Jul 2018 17:41:55 +1000 Subject: [PATCH 28/29] ctdb-tests: Strip all spaces from od output On freebsd, there are trailing spaces in od output. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 3047202ce733d1a767fbc83c7021cb83bb83e0e1) --- ctdb/tests/takeover_helper/scripts/local.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/tests/takeover_helper/scripts/local.sh b/ctdb/tests/takeover_helper/scripts/local.sh index 40ba617573a..bdbff9a4dca 100644 --- a/ctdb/tests/takeover_helper/scripts/local.sh +++ b/ctdb/tests/takeover_helper/scripts/local.sh @@ -88,7 +88,7 @@ takeover_helper_out="${TEST_VAR_DIR}/takover_helper.out" takeover_helper_format_outfd () { - od -A n -t d4 "$takeover_helper_out" | sed -e 's|^[[:space:]]*||' + od -A n -t d4 "$takeover_helper_out" | sed -e 's|[[:space:]]*||g' } test_takeover_helper () -- 2.17.1 From 5e6914560bc351567f2f2ed7dded3124d0ee1205 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 26 Jul 2018 14:51:44 +1000 Subject: [PATCH 29/29] ctdb-common: Fix the TCP packet length check BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit be43e08072ebce937ed0a02cd8d9d1c6072b178d) --- ctdb/common/system_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index d8627fd61fc..4e43805ca38 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -912,7 +912,7 @@ int ctdb_sys_read_tcp_packet(int s, /* make sure its not a short packet */ if (offsetof(struct tcphdr, th_ack) + 4 + - (ip->ip_hl*4) > ret) { + (ip->ip_hl*4) > pkthdr.len) { return -1; } /* TCP */ -- 2.17.1