ctdb-common: CID 1507498: Control flow issues (DEADCODE)
authorMartin Schwenke <martin@meltin.net>
Sat, 30 Jul 2022 00:19:56 +0000 (10:19 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 1 Aug 2022 09:19:55 +0000 (09:19 +0000)
Fix typo in error checking.  While here adjust the bottom of the
range, making errno 0 invalid.

Add corresponding test cases using an alternative syntax for errno packets
(#nnn[;] - trailing ';' is optional).

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Mon Aug  1 09:19:55 UTC 2022 on sn-devel-184

ctdb/common/tmon.c
ctdb/tests/UNIT/cunit/tmon_test_002.sh
ctdb/tests/src/tmon_test.c

index 87a55e3b1e9539b05f33003b343f8dd79c53801a..04bad1f3bf48f07e6bb85787ecd5cd950d9989e0 100644 (file)
@@ -97,7 +97,7 @@ bool tmon_set_exit(struct tmon_pkt *pkt)
 
 bool tmon_set_errno(struct tmon_pkt *pkt, int err)
 {
-       if (err < 0 && err > UINT16_MAX) {
+       if (err <= 0 || err > UINT16_MAX) {
                return false;
        }
 
index 97a17a188e53b60a5010e1141605eb7b1e3ce74f..e4118a3d09af81c02b58f0477f659b89eb4fd42a 100755 (executable)
@@ -4,6 +4,7 @@
 
 epipe=$(errcode EPIPE)
 etimedout=$(errcode ETIMEDOUT)
+edom=$(errcode EDOM)
 
 test_cases()
 {
@@ -35,6 +36,34 @@ WRITER OK
 EOF
        unit_test tmon_test "7" false 0 false
 
+       test_case "errno 110 packet @ 1s, no timeout"
+       ok <<EOF
+READER ERR=110
+WRITER OK
+EOF
+       unit_test tmon_test "#110" false 0 false
+
+       test_case "errno 0 error causes EDOM @ 1s, no timeout"
+       ok <<EOF
+WRITER ERR=$edom
+READER ERR=$epipe
+EOF
+       unit_test tmon_test "#0;" false 0 false
+
+       test_case "errno -1 error causes EDOM @ 1s, no timeout"
+       ok <<EOF
+WRITER ERR=$edom
+READER ERR=$epipe
+EOF
+       unit_test tmon_test "#-1;" false 0 false
+
+       test_case "errno 70000 error causes EDOM @ 1s, no timeout"
+       ok <<EOF
+WRITER ERR=$edom
+READER ERR=$epipe
+EOF
+       unit_test tmon_test "#70000;!0" false 0 false
+
        test_case "Exit packet @ 3s, no timeout"
        ok <<EOF
 READER OK
index 651c24b741413065207b0fb459472b219928b715..fb1f5eb9d3049140c51b259b672402ee142960df 100644 (file)
@@ -45,6 +45,7 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt)
                private_data, struct test_write_state);
        bool status;
        size_t len;
+       char *end;
        int err;
        char c;
        const char *t;
@@ -75,6 +76,16 @@ static int test_write_callback(void *private_data, struct tmon_pkt *pkt)
                case '!':
                        status = tmon_set_ping(pkt);
                        break;
+               case '#':
+                       /* Additional errno syntax: #nnn[;] */
+                       t = &state->write_data[state->offset];
+                       err = (int)strtol(t, &end, 10);
+                       state->offset += (end - t);
+                       if (state->write_data[state->offset] == ';') {
+                               state->offset++;
+                       }
+                       status = tmon_set_errno(pkt, err);
+                       break;
                default:
                        status = false;
                }