Code

sysdb: When handling a reply, base further actions on the response code.
authorSebastian Harl <sh@tokkee.org>
Thu, 1 May 2014 14:02:59 +0000 (16:02 +0200)
committerSebastian Harl <sh@tokkee.org>
Thu, 1 May 2014 14:02:59 +0000 (16:02 +0200)
This will actually enable the command handler to see whether a log message or
a query response was received.

Also, this ensures that the command handler may correctly detect errors during
query execution and exit with a non-zero code accordingly. The simple_query
integration test was updated to reflect this new, corrected behavior. Thanks
to the test for actually catching this misbehavior! :-)

src/tools/sysdb/command.c
t/integration/simple_query.sh

index 7cbde41a7e05e1bff9f6c3f0dfd5d966dda62e8f..be41b15f9d92557588df6b9fefc326a261a80844 100644 (file)
@@ -58,19 +58,19 @@ sdb_command_print_reply(sdb_client_t *client)
        if (! recv_buf)
                return -1;
 
-       if (sdb_client_recv(client, &rcode, recv_buf) < 0) {
+       if (sdb_client_recv(client, &rcode, recv_buf) < 0)
                rcode = UINT32_MAX;
-               status = -1;
-       }
 
        if (sdb_client_eof(client))
                return -1;
 
-       if (rcode == CONNECTION_ERROR)
-               status = CONNECTION_ERROR;
-
-       if (rcode == UINT32_MAX)
+       if (rcode == UINT32_MAX) {
                printf("ERROR: ");
+               status = -1;
+       }
+       else
+               status = (int)rcode;
+
        result = sdb_strbuf_string(recv_buf);
        if (result && *result)
                printf("%s\n", result);
index d413b997ea4e6d422c2747e422904bda17eed398..ec83f20199f3195b4c83f055a4cb9132b346dae4 100755 (executable)
@@ -49,7 +49,8 @@ sysdbd_pid=$!
 wait_for_sysdbd
 sleep 3
 
-output="$( $SYSDB -H "$SOCKET_FILE" -c INVALID )"
+output="$( $SYSDB -H "$SOCKET_FILE" -c INVALID )" && exit 1
+echo "$output" | grep "Failed to parse query 'INVALID'"
 echo "$output" | grep "parse error: syntax error"
 
 output="$( $SYSDB -H "$SOCKET_FILE" -c LIST )"