Code

client, sysdb: Improved error reporting.
authorSebastian Harl <sh@tokkee.org>
Thu, 23 Jan 2014 08:12:47 +0000 (09:12 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 23 Jan 2014 08:12:47 +0000 (09:12 +0100)
src/client/sock.c
src/tools/sysdb/command.c

index a2417ad6d872029e8c80f51d83899b65e9026a06..c722addb16d011355526d2b661919075601a28f8 100644 (file)
@@ -222,14 +222,14 @@ sdb_client_recv(sdb_client_t *client,
 
        size_t data_offset = sdb_strbuf_len(buf);
 
+       if (code)
+               *code = UINT32_MAX;
+
        if ((! client) || (! client->fd) || (! buf)) {
                errno = EBADF;
                return -1;
        }
 
-       if (code)
-               *code = UINT32_MAX;
-
        while (42) {
                ssize_t status;
 
index 30e6419e334d1b105749db8861826f2adf5f2883..f948d3aed65a5c18c78565819bdfac522b1cbe37 100644 (file)
 #include "tools/sysdb/input.h"
 
 #include "frontend/proto.h"
+#include "utils/error.h"
 #include "utils/strbuf.h"
 
+#include <errno.h>
+
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
@@ -66,6 +69,7 @@ sdb_command_exec(sdb_input_t *input)
 
        if (query_len) {
                sdb_strbuf_t *recv_buf;
+               const char *result;
                uint32_t rcode = 0;
 
                recv_buf = sdb_strbuf_create(1024);
@@ -81,7 +85,13 @@ sdb_command_exec(sdb_input_t *input)
 
                if (rcode == UINT32_MAX)
                        printf("ERROR: ");
-               printf("%s\n", sdb_strbuf_string(recv_buf));
+               result = sdb_strbuf_string(recv_buf);
+               if (result && *result)
+                       printf("%s\n", result);
+               else if (rcode == UINT32_MAX) {
+                       char errbuf[1024];
+                       printf("%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
+               }
 
                sdb_strbuf_destroy(recv_buf);
        }