Code

sysdb: Handle EOF from the server.
authorSebastian Harl <sh@tokkee.org>
Thu, 6 Feb 2014 19:11:45 +0000 (20:11 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 6 Feb 2014 19:11:45 +0000 (20:11 +0100)
src/tools/sysdb/command.c
src/tools/sysdb/input.c

index 0abf381e95527234d8e2ef8aa608e25d3446c9ad..1128c388e8bbd827f63e63cb2cd2628137e146fd 100644 (file)
@@ -60,6 +60,9 @@ sdb_command_print_reply(sdb_input_t *input)
        if (sdb_client_recv(input->client, &rcode, recv_buf) < 0)
                rcode = UINT32_MAX;
 
+       if (sdb_client_eof(input->client))
+               return -1;
+
        if (rcode == UINT32_MAX)
                printf("ERROR: ");
        result = sdb_strbuf_string(recv_buf);
index f115e3e2a51088efdf2dec9e5547ffa1a60642cc..3814f0c2def7a239d8397d9cad4558cbd52112ae 100644 (file)
@@ -47,6 +47,7 @@
 #include "tools/sysdb/input.h"
 #include "tools/sysdb/command.h"
 
+#include "utils/error.h"
 #include "utils/strbuf.h"
 
 #include <sys/select.h>
@@ -178,6 +179,14 @@ input_readline(void)
                if (! FD_ISSET(client_fd, &fds))
                        continue;
 
+               if (sdb_client_eof(sysdb_input->client)) {
+                       /* XXX: try to reconnect */
+                       printf("\n");
+                       sdb_log(SDB_LOG_ERR, "Remote side closed the connection.");
+                       /* return EOF */
+                       return 0;
+               }
+
                /* some response / error message from the server pending */
                /* XXX: clear current line */
                printf("\n");