index 08f639f1ac104c9a8c0527321bc92ba89070e4db..a1e7b714b689a85e946587624948a6d237eef78c 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);
return (ssize_t)(sdb_strbuf_len(sysdb_input->input) - len);
}
- if (sysdb_input->query_len)
- prompt = "sysdb-> ";
+ if (sysdb_input->have_input)
+ prompt = " -> ";
if (sdb_client_eof(sysdb_input->client))
prompt = "!-> ";
if (sdb_client_eof(sysdb_input->client)) {
rl_callback_handler_remove();
/* XXX */
- printf("Remote side closed the connection.\n");
+ sdb_log(SDB_LOG_ERR, "Remote side closed the connection.");
/* return EOF -> restart scanner */
return 0;
}
int
sdb_input_exec_query(void)
{
- char *query = sdb_command_exec(sysdb_input);
+ char *query = NULL;
- HIST_ENTRY *current_hist;
- const char *hist_line = NULL;
+ HIST_ENTRY *hist;
+ const char *prev = NULL;
+
+ if (! sysdb_input->have_input) {
+ /* empty line */
+ if (sdb_client_eof(sysdb_input->client))
+ sdb_input_reconnect();
+ return 0;
+ }
+ query = sdb_command_exec(sysdb_input);
if (! query)
return -1;
- current_hist = current_history();
- if (current_hist)
- hist_line = current_hist->line;
+ hist = history_get(history_length);
+ if (hist)
+ prev = hist->line;
if (*query != ' ')
- if ((! hist_line) || strcmp(hist_line, query))
+ if ((! prev) || strcmp(prev, query))
add_history(query);
free(query);
return 0;
{
sdb_client_close(sysdb_input->client);
if (sdb_client_connect(sysdb_input->client, sysdb_input->user)) {
- printf("Failed to reconnect to SysDBd.\n");
+ sdb_log(SDB_LOG_ERR, "Failed to reconnect to SysDBd");
return -1;
}
- printf("Successfully reconnected to SysDBd.\n");
+ sdb_log(SDB_LOG_INFO, "Successfully reconnected to SysDBd");
return 0;
} /* sdb_input_reconnect */