Code

sysdb: Use sdb_log() instead of printf().
authorSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 23:24:20 +0000 (00:24 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 23:30:43 +0000 (00:30 +0100)
src/tools/sysdb/command.c
src/tools/sysdb/input.c
t/integration/query.sh

index 6ae4c89a981eff70cdf9fb8413f8211f6e90e9dc..9589875300d468c7b9e6b7268fef5705a9580773 100644 (file)
@@ -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);
index 898464af0b550118aa0367337a4e4b85460930c6..b6603c08ed86aef9aa7aa5ac956634f4aafd888f 100644 (file)
@@ -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 */
 
index 39522cf9be6c09928952f121b621b6121286e54a..f8287b45a645adac6798dbb611b092279e070d4f 100755 (executable)
@@ -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" \