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 f9195a644057ee9b2c849f4f764f4ef6bacd65d4..5044c0e5213aac42cb4456cd9dafe465264f4010 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 52036028d2905d35555705ec026e2bc30f96c55e..08f639f1ac104c9a8c0527321bc92ba89070e4db 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 eb13043b4cea2acb948cc3ec031f075311cbb818..0aeabf8b7b653197f98ffa0678d13b769e0c21e2 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 : */