Code

sysdb: Do an attempt to reconnect on all user input.
authorSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 08:57:49 +0000 (09:57 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 11 Dec 2014 08:57:49 +0000 (09:57 +0100)
src/tools/sysdb/command.c
src/tools/sysdb/input.c
src/tools/sysdb/input.h

index f9195a6..5044c0e 100644 (file)
@@ -174,13 +174,10 @@ sdb_command_exec(sdb_input_t *input)
                --query_len;
 
        if (sdb_client_eof(input->client)) {
-               sdb_client_close(input->client);
-               if (sdb_client_connect(input->client, input->user)) {
-                       printf("Failed to reconnect to SysDBd.\n");
+               if (sdb_input_reconnect()) {
                        clear_query(input);
                        return NULL;
                }
-               printf("Successfully reconnected to SysDBd.\n");
        }
 
        if (query_len) {
index 5203602..08f639f 100644 (file)
@@ -133,6 +133,9 @@ handle_input(char *line)
                return;
        }
 
+       if (sdb_client_eof(sysdb_input->client))
+               sdb_input_reconnect();
+
        sdb_strbuf_append(sysdb_input->input, "%s\n", line);
        free(line);
 
@@ -294,5 +297,17 @@ sdb_input_exec_query(void)
        return 0;
 } /* sdb_input_exec_query */
 
+int
+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");
+               return -1;
+       }
+       printf("Successfully reconnected to SysDBd.\n");
+       return 0;
+} /* sdb_input_reconnect */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */
 
index eb13043..0aeabf8 100644 (file)
@@ -92,6 +92,14 @@ sdb_input_readline(char *buf, size_t *n_chars, size_t max_chars);
 int
 sdb_input_exec_query(void);
 
+/*
+ * sdb_input_reconnect:
+ * Let the client reconnect to the server using the settings stored in
+ * sysdb_input.
+ */
+int
+sdb_input_reconnect(void);
+
 #endif /* SYSDB_INPUT_H */
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */