From 1f2aedf19e878c5cbf6d5bc5793ee3621fa7854c Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 1 May 2014 16:02:59 +0200 Subject: [PATCH] sysdb: When handling a reply, base further actions on the response code. 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 | 14 +++++++------- t/integration/simple_query.sh | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index 7cbde41..be41b15 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -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); diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index d413b99..ec83f20 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -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 )" -- 2.30.2