Code

sysdb: Clear the current command from the buffer after error.
[sysdb.git] / src / tools / sysdb / command.c
index d30ec6084179a614fcf386cf87e3a9dcad9e0079..7737a2e15e35e6c9084227669f6f40471ea463e3 100644 (file)
@@ -65,7 +65,13 @@ log_printer(sdb_strbuf_t *buf)
 static void
 data_printer(sdb_strbuf_t *buf)
 {
-       if (sdb_strbuf_len(buf) <= sizeof(uint32_t)) {
+       size_t len = sdb_strbuf_len(buf);
+
+       if ((! len) || (len == sizeof(uint32_t))) {
+               /* empty command or empty reply */
+               return;
+       }
+       else if (len < sizeof(uint32_t)) {
                printf("ERROR: Received a DATA message with invalid "
                                "or missing data-type\n");
                return;
@@ -81,8 +87,8 @@ static struct {
        int status;
        void (*printer)(sdb_strbuf_t *);
 } response_printers[] = {
-       { CONNECTION_LOG,  log_printer },
-       { CONNECTION_DATA, data_printer },
+       { SDB_CONNECTION_LOG,  log_printer },
+       { SDB_CONNECTION_DATA, data_printer },
 };
 
 /*
@@ -163,17 +169,18 @@ sdb_command_exec(sdb_input_t *input)
                data = strndup(query, query_len);
                /* ignore errors; we'll only hide the command from the caller */
 
-               sdb_client_send(input->client, CONNECTION_QUERY, query_len, query);
+               sdb_client_send(input->client, SDB_CONNECTION_QUERY, query_len, query);
 
                /* The server will send back *something*, either error/log messages
                 * and/or the reply to the query. Here, we don't care about what it
                 * sends back. We'll wait for the first reply and then return to the
                 * main loop which will handle any subsequent replies, including
                 * eventually the reply to the query (if it's not the first reply). */
+               /* TODO: wait for the actual reply instead */
                if (sdb_command_print_reply(input->client) < 0) {
                        if (data)
                                free(data);
-                       return NULL;
+                       data = NULL;
                }
        }