[PATCH] ctdb-scripts: Fix ss syntax in update_tickles()
Rafael David Tinoco
rafaeldtinoco at ubuntu.com
Tue Jun 4 01:44:00 UTC 2019
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13985
During CTDB execution I got the following error:
ctdbd[1000]: Starting traverse on DB ctdb.tdb (id 806)
ctdbd[1000]: Ending traverse on DB ctdb.tdb (id 806), records 0
ctdb-eventd[1002]: 60.nfq: ss: bison bellows (while parsing filter): "syntax error!" Sorry.
ctdb-eventd[1002]: 60.nfs: Usage: ss [ OPTIONS ]
ctdb-eventd[1002]: 60.nfs: ss [ OPTIONS ] [ FILTER ]
ctdb-eventd[1002]: 60.nfs: -V, --version output version information
Debug in /etc/ctdb/functions showed:
60.nfs: + _port=2049
60.nfs: + tickledir=/var/lib/ctdb/scripts/tickles
60.nfs: + mkdir -p /var/lib/ctdb/scripts/tickles
60.nfs: + ctdb_get_pnn
60.nfs: + _pnn_file=/var/lib/ctdb/scripts/my-pnn
60.nfs: + [ ! -f /var/lib/ctdb/scripts/my-pnn ]
60.nfs: + cat /var/lib/ctdb/scripts/my-pnn
60.nfs: + _pnn=0
60.nfs: + /usr/bin/ctdb -X ip
60.nfs: + awk -F| -v pnn=0 $3 == pnn {print $2}it
60.nfs: + _ips=172.16.17.3
60.nfs: + _ip_filter=
60.nfs: + _ip_filter=src [172.16.17.3]
60.nfs: + _port_filter=sport == :2049
60.nfs: + _my_connections=/var/lib/ctdb/scripts/tickles/2049.connections.12623
60.nfs: + ss -tn state established ( src [172.16.17.3] ) ( sport == :2049 )
ss syntax is wrong in update_tickles().
Instead of:
ss -tn state established ( src [172.16.17.3] ) ( sport == :2049 )
Obtained in debug mode, we should have something like:
ss -tn state established '( src [172.16.17.3] ) && sport == :2049'
or
ss -tn state established '( src [172.16.17.2] || src [172.16.17.3] ) \
&& sport == :2049'
depending on the number of _ips obtained from "ctdb -X ip command".
This script fixes the issue.
Signed-off-by: Rafael David Tinoco <rafaeldtinoco at ubuntu.com>
---
ctdb/config/functions | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/ctdb/config/functions b/ctdb/config/functions
index 1dc16532890..8c4dae6097d 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -956,6 +956,10 @@ update_tickles ()
{
_port="$1"
+ if [ "$_port" = "" ]; then
+ return 0;
+ fi
+
tickledir="${CTDB_SCRIPT_VARDIR}/tickles"
mkdir -p "$tickledir"
@@ -964,24 +968,25 @@ update_tickles ()
_ips=$($CTDB -X ip | awk -F'|' -v pnn="$_pnn" '$3 == pnn {print $2}')
# IPs and port as ss filters
- _ip_filter=""
- for _ip in $_ips ; do
- _ip_filter="${_ip_filter}${_ip_filter:+ || }src [${_ip}]"
- done
+
+ _ip_filter=$(for _ip in $_ips; do echo " src [$_ip] |" ; done | xargs)
+ _ip_filter=$(echo $_ip_filter | sed 's: |$::g')
+
+ if [ "$_ip_filter" = "" ]; then
+ return 0;
+ fi
+
_port_filter="sport == :${_port}"
# Record connections to our public IPs in a temporary file.
# This temporary file is in CTDB's private state directory and
# $$ is used to avoid a very rare race involving CTDB's script
# debugging. No security issue, nothing to see here...
+
_my_connections="${tickledir}/${_port}.connections.$$"
- # Parentheses are needed around the filters for precedence but
- # the parentheses can't be empty!
- ss -tn state established \
- "${_ip_filter:+( ${_ip_filter} )}" \
- "${_port_filter:+( ${_port_filter} )}" |
- awk 'NR > 1 {print $4, $3}' |
- sort >"$_my_connections"
+
+ ss -tn state established "( $_ip_filter ) && $_port_filter" | \
+ awk 'NR > 1 {print $4, $3}' | sort >"$_my_connections"
# Record our current tickles in a temporary file
_my_tickles="${tickledir}/${_port}.tickles.$$"
--
2.20.1
More information about the samba-technical
mailing list