From: Sebastian Harl Date: Thu, 11 Dec 2014 08:57:49 +0000 (+0100) Subject: sysdb: Do an attempt to reconnect on all user input. X-Git-Tag: sysdb-0.7.0~112^2~6 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=865b0a3b20fe3c1eb014e22e4b1f45f4fa931ce5;p=sysdb.git sysdb: Do an attempt to reconnect on all user input. --- diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index f9195a6..5044c0e 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -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) { diff --git a/src/tools/sysdb/input.c b/src/tools/sysdb/input.c index 5203602..08f639f 100644 --- a/src/tools/sysdb/input.c +++ b/src/tools/sysdb/input.c @@ -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 : */ diff --git a/src/tools/sysdb/input.h b/src/tools/sysdb/input.h index eb13043..0aeabf8 100644 --- a/src/tools/sysdb/input.h +++ b/src/tools/sysdb/input.h @@ -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 : */