ctdb-scripts: Avoid errors for uninitialised counters
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 15 Mar 2023 06:56:40 +0000 (17:56 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 3 Oct 2023 03:53:35 +0000 (03:53 +0000)
Uninitialised counters are treated as 0, but still produce an error.

The redirect to stderr needs to come before the redirect for a missing
counter file.

The seemingly saner alternative of moving it outside the subshell
works when dash is /bin/sh (e.g. on Debian) but does not work when
bash is /bin/sh (e.g. on Fedora).

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions

index 56105aab1655b3b75482a901ff74def1c84cec6f..5a7737ec34ab44718c5644b7f1e0f7fc441c6adb 100755 (executable)
@@ -754,7 +754,7 @@ ctdb_counter_get()
 {
        _ctdb_counter_common "$1"
        # unary counting!
-       _val=$(wc -c <"$_counter_file" 2>/dev/null || echo 0)
+       _val=$(wc -c 2>/dev/null <"$_counter_file" || echo 0)
        # Strip leading spaces from output of wc (on freebsd)
        # shellcheck disable=SC2086
        echo $_val