Updates for the debug cli interface
This commit is contained in:
17
core/dcb.c
17
core/dcb.c
@ -335,6 +335,18 @@ int saved_errno = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a DCB
|
||||
*
|
||||
* Generic, non-protocol specific close funcitonality
|
||||
* @param dcb The DCB to close
|
||||
*/
|
||||
void
|
||||
dcb_close(DCB *dcb, int efd)
|
||||
{
|
||||
close(dcb->fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Diagnostic to print a DCB
|
||||
*
|
||||
@ -344,7 +356,7 @@ int saved_errno = 0;
|
||||
void
|
||||
printDCB(DCB *dcb)
|
||||
{
|
||||
(void)printf("DCB: 0x%p\n", (void *)dcb);
|
||||
(void)printf("DCB: %p\n", (void *)dcb);
|
||||
(void)printf("\tDCB state: %s\n", gw_dcb_state2string(dcb->state));
|
||||
(void)printf("\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
||||
(void)printf("\tStatistics:\n");
|
||||
@ -397,7 +409,7 @@ DCB *dcb;
|
||||
dcb = allDCBs;
|
||||
while (dcb)
|
||||
{
|
||||
dcb_printf(pdcb, "DCB: 0x%p\n", (void *)dcb);
|
||||
dcb_printf(pdcb, "DCB: %p\n", (void *)dcb);
|
||||
dcb_printf(pdcb, "\tDCB state: %s\n", gw_dcb_state2string(dcb->state));
|
||||
dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
||||
dcb_printf(pdcb, "\tStatistics:\n");
|
||||
@ -459,5 +471,6 @@ va_list args;
|
||||
vsnprintf(GWBUF_DATA(buf), 10240, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
buf->end = GWBUF_DATA(buf) + strlen(GWBUF_DATA(buf)) + 1;
|
||||
dcb->func.write(dcb, buf);
|
||||
}
|
||||
|
@ -162,11 +162,13 @@ void *handle;
|
||||
static MODULES *
|
||||
find_module(const char *module)
|
||||
{
|
||||
while (registered)
|
||||
if (strcmp(registered->module, module) == 0)
|
||||
return registered;
|
||||
MODULES *mod = registered;
|
||||
|
||||
while (mod)
|
||||
if (strcmp(mod->module, module) == 0)
|
||||
return mod;
|
||||
else
|
||||
registered = registered->next;
|
||||
mod = mod->next;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -238,11 +240,11 @@ printModules()
|
||||
{
|
||||
MODULES *ptr = registered;
|
||||
|
||||
printf("%-15s | %-10s | Version\n", "Module Name", "Module Type");
|
||||
printf("%-15s | %-11s | Version\n", "Module Name", "Module Type");
|
||||
printf("-----------------------------------------------------\n");
|
||||
while (ptr)
|
||||
{
|
||||
printf("%-15s | %-10s | %s\n", ptr->module, ptr->type, ptr->version);
|
||||
printf("%-15s | %-11s | %s\n", ptr->module, ptr->type, ptr->version);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
@ -257,11 +259,11 @@ dprintAllModules(DCB *dcb)
|
||||
{
|
||||
MODULES *ptr = registered;
|
||||
|
||||
dcb_printf(dcb, "%-15s | %-10s | Version\n", "Module Name", "Module Type");
|
||||
dcb_printf(dcb, "%-15s | %-11s | Version\n", "Module Name", "Module Type");
|
||||
dcb_printf(dcb, "-----------------------------------------------------\n");
|
||||
while (ptr)
|
||||
{
|
||||
dcb_printf(dcb, "%-15s | %-10s | %s\n", ptr->module, ptr->type, ptr->version);
|
||||
dcb_printf(dcb, "%-15s | %-11s | %s\n", ptr->module, ptr->type, ptr->version);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ SERVER *ptr = service->databases;
|
||||
printf("\tBackend databases\n");
|
||||
while (ptr)
|
||||
{
|
||||
printf("\t\t%s:%d %s\n", ptr->name, ptr->port, ptr->protocol);
|
||||
printf("\t\t%s:%d Protocol: %s\n", ptr->name, ptr->port, ptr->protocol);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
printf("\tTotal connections: %d\n", service->stats.n_sessions);
|
||||
@ -277,7 +277,7 @@ SERVICE *ptr;
|
||||
dcb_printf(dcb, "\tBackend databases\n");
|
||||
while (server)
|
||||
{
|
||||
dcb_printf(dcb, "\t\t%s:%d %s\n", server->name, server->port,
|
||||
dcb_printf(dcb, "\t\t%s:%d Protocol: %s\n", server->name, server->port,
|
||||
server->protocol);
|
||||
server = server->next;
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ extern DCB *connect_dcb(struct server *, struct session *, const char *);
|
||||
extern int dcb_read(DCB *, GWBUF **); /* Generic read routine */
|
||||
extern int dcb_write(DCB *, GWBUF *); /* Generic write routine */
|
||||
extern int dcb_drain_writeq(DCB *); /* Generic write routine */
|
||||
extern void dcb_close(DCB *, int); /* Generic close functionality */
|
||||
extern void printAllDCBs(); /* Debug to print all DCB in the system */
|
||||
extern void printDCB(DCB *); /* Debug print routine */
|
||||
extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
|
||||
|
@ -48,6 +48,7 @@
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
#define TELNET_IAC 255
|
||||
|
||||
static char *version_str = "V1.0.0";
|
||||
|
||||
@ -129,8 +130,17 @@ void *rsession = session->router_session;
|
||||
|
||||
if ((n = dcb_read(dcb, &head)) != -1)
|
||||
{
|
||||
if (head)
|
||||
{
|
||||
char *ptr = GWBUF_DATA(head);
|
||||
ptr = GWBUF_DATA(head);
|
||||
if (*ptr == TELNET_IAC)
|
||||
{
|
||||
GWBUF_CONSUME(head, 2);
|
||||
}
|
||||
router->routeQuery(router_instance, rsession, head);
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
@ -236,12 +246,13 @@ int n_connect = 0;
|
||||
* explicitly close a connection.
|
||||
*
|
||||
* @param dcb The descriptor control block
|
||||
* @param event The epoll descriptor
|
||||
* @param efd The epoll descriptor
|
||||
*/
|
||||
|
||||
static int
|
||||
telnetd_close(DCB *dcb, int event)
|
||||
telnetd_close(DCB *dcb, int efd)
|
||||
{
|
||||
dcb_close(dcb, efd);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +282,6 @@ short pnum;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
pnum = atoi(port);
|
||||
addr.sin_port = htons(pnum);
|
||||
printf("telnetd listen on port %d from %s from %s\n", pnum, port, config);
|
||||
|
||||
if ((listener->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ static int execute(ROUTER *instance, void *router_session, GWBUF *queue);
|
||||
/** The module object definition */
|
||||
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, execute };
|
||||
|
||||
static void execute_cmd(CLI_SESSION *cli);
|
||||
static int execute_cmd(CLI_SESSION *cli);
|
||||
|
||||
static SPINLOCK instlock;
|
||||
static CLI_INSTANCE *instances;
|
||||
@ -147,7 +147,7 @@ CLI_SESSION *client;
|
||||
}
|
||||
client->session = session;
|
||||
|
||||
memset(client->cmdbuf, 80, 0);
|
||||
memset(client->cmdbuf, 0, 80);
|
||||
|
||||
spinlock_acquire(&inst->lock);
|
||||
client->next = inst->sessions;
|
||||
@ -211,14 +211,18 @@ execute(ROUTER *instance, void *router_session, GWBUF *queue)
|
||||
CLI_SESSION *session = (CLI_SESSION *)router_session;
|
||||
|
||||
/* Extract the characters */
|
||||
while (queue)
|
||||
{
|
||||
strncat(session->cmdbuf, GWBUF_DATA(queue), GWBUF_LENGTH(queue));
|
||||
/* Echo back to the user */
|
||||
dcb_write(session->session->client, queue);
|
||||
queue = gwbuf_consume(queue, GWBUF_LENGTH(queue));
|
||||
}
|
||||
|
||||
if (strrchr(session->cmdbuf, '\n'))
|
||||
{
|
||||
execute_cmd(session);
|
||||
if (execute_cmd(session))
|
||||
dcb_printf(session->session->client, "Gateway> ");
|
||||
else
|
||||
session->session->client->func.close(session->session->client, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -240,7 +244,7 @@ static struct {
|
||||
*
|
||||
* @param cli The CLI_SESSION
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
execute_cmd(CLI_SESSION *cli)
|
||||
{
|
||||
int i, found = 0;
|
||||
@ -254,6 +258,10 @@ int i, found = 0;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
else if (!strncmp(cli->cmdbuf, "quit", 4))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; cmds[i].cmd; i++)
|
||||
@ -268,5 +276,7 @@ int i, found = 0;
|
||||
if (!found)
|
||||
dcb_printf(cli->session->client,
|
||||
"Command not known, type help for a list of available commands\n");
|
||||
memset(cli->cmdbuf, 80, 0);
|
||||
memset(cli->cmdbuf, 0, 80);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user