ctdb-scripts: Don't use the GNU awk gensub() function
authorMartin Schwenke <martin@meltin.net>
Fri, 19 Dec 2014 03:19:32 +0000 (14:19 +1100)
committerMichael Adam <obnox@samba.org>
Fri, 9 Jan 2015 01:03:40 +0000 (02:03 +0100)
This is a gawk extension and can't be used reliably if just running
"awk".  It is simple enough to switch to using the standard sub() and
gsub() functions.

The alternative is to switch to explicitly running "gawk".  However,
although the eventscripts aren't exactly portable, it is probably
better to move closer to portability than further away.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/config/functions
ctdb/config/statd-callout
ctdb/tests/complex/18_ctdb_reloadips.sh
ctdb/tests/scripts/integration.bash

index df818a03231932e3fdc24176cfd72f78d7a8399b..3bc9e3d29efc313d42ee0a2729cc94f8ece02985 100755 (executable)
@@ -915,7 +915,7 @@ delete_ip_from_iface()
     }
 }
 
-# If the given IP is hosted then print 2 items: maskbits and iface 
+# If the given IP is hosted then print 2 items: maskbits and iface
 ip_maskbits_iface ()
 {
     _addr="$1"
@@ -927,8 +927,9 @@ ip_maskbits_iface ()
 
     ip addr show to "${_addr}/${_bits}" 2>/dev/null | \
        awk -v family="${_family}" \
-           'NR == 1 { iface = gensub(":$", "", 1, $2) } \
-             $1 ~ /inet/ { print gensub(".*/", "", 1, $2), iface, family }'
+           'NR == 1 { iface = $2; sub(":$", "", iface) } \
+             $1 ~ /inet/ { mask = $2; sub(".*/", "", mask); \
+                           print mask, iface, family }'
 }
 
 drop_ip ()
index 5e8eb0e789ccf8aff90f4a2346f452c16c1c2ab8..e2a955eab5fa7dafc646776cb2a80e6c3aaf44ee 100755 (executable)
@@ -145,7 +145,9 @@ case "$1" in
        #   server-IP client-IP
        # but only for the server-IPs that are hosted on this node.
        sed_expr=$(ctdb ip | tail -n +2 |
-           awk -v pnn=$pnn 'pnn == $2 { printf "s/^key.*=.*statd-state@\\(%s\\)@\\([^\"]*\\).*/\\1 \\2/p\n", gensub(/\./, "\\\\.", "g", $1) }')
+           awk -v pnn=$pnn 'pnn == $2 { \
+                ip = $1; gsub(/\./, "\\\\.", ip); \
+                printf "s/^key.*=.*statd-state@\\(%s\\)@\\([^\"]*\\).*/\\1 \\2/p\n", ip }')
 
        statd_state=$(ctdb catdb ctdb.tdb | sed -n "$sed_expr" | sort)
        [ -n "$statd_state" ] || exit 0
index 13f7c213af05795fb0a7786164df62efbd23d5f2..71f997cda56c0b43d220ed98cf04b936d81a7c5f 100755 (executable)
@@ -56,7 +56,7 @@ ctdb_ip_info=$(echo "$out" | awk -F'|' 'NR > 1 { print $2, $3, $5 }')
 echo "Getting IP information from interfaces..."
 try_command_on_node all "ip addr show"
 ip_addr_info=$(echo "$out" | \
-    awk '$1 == "inet" { print gensub(/\/.*/, "", "", $2)}')
+    awk '$1 == "inet" { ip = $2; sub(/\/.*/, "", ip); print ip }')
 
 prefix=""
 for b in $(seq 0 255) ; do
index 0d27c93643fabfe460ad0e4288d7bf3495401c74..139a9a23cb2e74ae65eeddbab5f4de08ca8dabec 100644 (file)
@@ -699,8 +699,9 @@ ip_maskbits_iface ()
 
     ip addr show to "${_addr}/${_bits}" 2>/dev/null | \
        awk -v family="${_family}" \
-           'NR == 1 { iface = gensub(":$", "", 1, $2) } \
-             $1 ~ /inet/ { print gensub(".*/", "", 1, $2), iface, family }'
+           'NR == 1 { iface = $2; sub(":$", "", iface) } \
+             $1 ~ /inet/ { mask = $2; sub(".*/", "", mask); \
+                           print mask, iface, family }'
 }
 
 drop_ip ()