From: Sebastian Harl Date: Thu, 11 Dec 2014 23:24:20 +0000 (+0100) Subject: sysdb: Use sdb_log() instead of printf(). X-Git-Tag: sysdb-0.7.0~112^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a9edb0a6423119816a466855309e54a3e769ceb3;p=sysdb.git sysdb: Use sdb_log() instead of printf(). --- diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index 6ae4c89..9589875 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -52,14 +52,13 @@ log_printer(sdb_strbuf_t *buf) uint32_t prio = sdb_proto_get_int(buf, 0); if (prio == UINT32_MAX) { - printf("ERROR: Received a LOG message with invalid " - "or missing priority\n"); - return; + sdb_log(SDB_LOG_WARNING, "Received a LOG message with invalid " + "or missing priority"); + prio = (uint32_t)SDB_LOG_ERR; } sdb_strbuf_skip(buf, 0, sizeof(prio)); - printf("%s: %s\n", SDB_LOG_PRIO_TO_STRING((int)prio), - sdb_strbuf_string(buf)); + sdb_log((int)prio, "%s", sdb_strbuf_string(buf)); } /* log_printer */ static void @@ -72,8 +71,8 @@ data_printer(sdb_strbuf_t *buf) return; } else if (len < sizeof(uint32_t)) { - printf("ERROR: Received a DATA message with invalid " - "or missing data-type\n"); + sdb_log(SDB_LOG_ERR, "Received a DATA message with invalid " + "or missing data-type"); return; } @@ -111,7 +110,7 @@ sdb_command_print_reply(sdb_client_t *client) const char *result; uint32_t rcode = 0; - int status = 0; + int status = -1; size_t i; recv_buf = sdb_strbuf_create(1024); @@ -126,11 +125,7 @@ sdb_command_print_reply(sdb_client_t *client) return -1; } - if (rcode == UINT32_MAX) { - printf("ERROR: "); - status = -1; - } - else + if (rcode != UINT32_MAX) status = (int)rcode; for (i = 0; i < SDB_STATIC_ARRAY_LEN(response_printers); ++i) { @@ -143,10 +138,11 @@ sdb_command_print_reply(sdb_client_t *client) result = sdb_strbuf_string(recv_buf); if (result && *result) - printf("%s\n", result); + sdb_log(SDB_LOG_ERR, "%s", result); else if (rcode == UINT32_MAX) { char errbuf[1024]; - printf("%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_log(SDB_LOG_ERR, "%s", + sdb_strerror(errno, errbuf, sizeof(errbuf))); } sdb_strbuf_destroy(recv_buf); diff --git a/src/tools/sysdb/input.c b/src/tools/sysdb/input.c index 898464a..b6603c0 100644 --- a/src/tools/sysdb/input.c +++ b/src/tools/sysdb/input.c @@ -208,7 +208,7 @@ input_readline(void) if (sdb_client_eof(sysdb_input->client)) { rl_callback_handler_remove(); /* XXX */ - printf("Remote side closed the connection.\n"); + sdb_log(SDB_LOG_ERR, "Remote side closed the connection."); /* return EOF -> restart scanner */ return 0; } @@ -307,10 +307,10 @@ sdb_input_reconnect(void) { sdb_client_close(sysdb_input->client); if (sdb_client_connect(sysdb_input->client, sysdb_input->user)) { - printf("Failed to reconnect to SysDBd.\n"); + sdb_log(SDB_LOG_ERR, "Failed to reconnect to SysDBd"); return -1; } - printf("Successfully reconnected to SysDBd.\n"); + sdb_log(SDB_LOG_INFO, "Successfully reconnected to SysDBd"); return 0; } /* sdb_input_reconnect */ diff --git a/t/integration/query.sh b/t/integration/query.sh index 39522cf..f8287b4 100755 --- a/t/integration/query.sh +++ b/t/integration/query.sh @@ -49,7 +49,7 @@ wait_for_sysdbd sleep 3 # On parse errors, expect a non-zero exit code. -output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID )" && exit 1 +output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID 2>&1 )" && exit 1 echo "$output" | grep "Failed to parse query 'INVALID'" echo "$output" | grep "parse error: syntax error" @@ -94,7 +94,7 @@ echo "$output" | grep -F 'other.host.name' && exit 1 echo "$output" | grep -F 'some.host.name' && exit 1 output="$( run_sysdb -H "$SOCKET_FILE" \ - -c "FETCH host 'host1.example.com' FILTER last_update < 0" )" \ + -c "FETCH host 'host1.example.com' FILTER last_update < 0" 2>&1 )" \ && exit 1 echo "$output" | grep -F 'not found' @@ -102,8 +102,8 @@ echo "$output" | grep -F 'not found' | run_sysdb -H "$SOCKET_FILE" # When requesting information for unknown hosts, expect a non-zero exit code. -output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'does.not.exist'" )" \ - && exit 1 +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "FETCH host 'does.not.exist'" 2>&1 )" && exit 1 echo "$output" | grep -F 'not found' run_sysdb -H "$SOCKET_FILE" \