index 9ed11eddd0e26309fab0bbda7333495ae86bd37c..08f639f1ac104c9a8c0527321bc92ba89070e4db 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
return;
}
+ if (sdb_client_eof(sysdb_input->client))
+ sdb_input_reconnect();
+
sdb_strbuf_append(sysdb_input->input, "%s\n", line);
free(line);
if (sysdb_input->query_len)
prompt = "sysdb-> ";
+ if (sdb_client_eof(sysdb_input->client))
+ prompt = "!-> ";
rl_callback_handler_install(prompt, handle_input);
client_fd = sdb_client_sockfd(sysdb_input->client);
while ((sdb_strbuf_len(sysdb_input->input) == len)
&& (! sysdb_input->eof)) {
- int n;
+ bool connected = !sdb_client_eof(sysdb_input->client);
+ int max_fd, n;
/* XXX: some versions of libedit don't properly reset the terminal in
* rl_callback_read_char(); detect those versions */
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
- FD_SET(client_fd, &fds);
+ max_fd = STDIN_FILENO;
+
+ if (connected) {
+ FD_SET(client_fd, &fds);
+ if (client_fd > max_fd)
+ max_fd = client_fd;
+ }
- n = select(client_fd + 1, &fds, NULL, NULL, /* timeout = */ NULL);
+ n = select(max_fd + 1, &fds, NULL, NULL, /* timeout = */ NULL);
if (n < 0)
return (ssize_t)n;
else if (! n)
continue;
}
- if (! FD_ISSET(client_fd, &fds))
+ if ((! connected) || (! 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");
sdb_command_print_reply(sysdb_input->client);
- rl_forced_update_display();
+
+ if (sdb_client_eof(sysdb_input->client)) {
+ rl_callback_handler_remove();
+ /* XXX */
+ printf("Remote side closed the connection.\n");
+ /* return EOF -> restart scanner */
+ return 0;
+ }
+ else
+ rl_forced_update_display();
}
/* new data available */
int
sdb_input_mainloop(void)
{
- yylex();
+ while (! sysdb_input->eof)
+ yylex();
return 0;
} /* sdb_input_mainloop */
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 : */