Updates for the debug cli interface
This commit is contained in:
27
core/dcb.c
27
core/dcb.c
@ -335,6 +335,18 @@ int saved_errno = 0;
|
|||||||
return n;
|
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
|
* Diagnostic to print a DCB
|
||||||
*
|
*
|
||||||
@ -344,13 +356,13 @@ int saved_errno = 0;
|
|||||||
void
|
void
|
||||||
printDCB(DCB *dcb)
|
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("\tDCB state: %s\n", gw_dcb_state2string(dcb->state));
|
||||||
(void)printf("\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
(void)printf("\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
||||||
(void)printf("\tStatistics:\n");
|
(void)printf("\tStatistics:\n");
|
||||||
(void)printf("\t\tNo. of Reads: %d\n", dcb->stats.n_reads);
|
(void)printf("\t\tNo. of Reads: %d\n", dcb->stats.n_reads);
|
||||||
(void)printf("\t\tNo. of Writes: %d\n", dcb->stats.n_writes);
|
(void)printf("\t\tNo. of Writes: %d\n", dcb->stats.n_writes);
|
||||||
(void)printf("\t\tNo. of Buffered Writes: %d\n", dcb->stats.n_buffered);
|
(void)printf("\t\tNo. of Buffered Writes: %d\n", dcb->stats.n_buffered);
|
||||||
(void)printf("\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts);
|
(void)printf("\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +409,7 @@ DCB *dcb;
|
|||||||
dcb = allDCBs;
|
dcb = allDCBs;
|
||||||
while (dcb)
|
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, "\tDCB state: %s\n", gw_dcb_state2string(dcb->state));
|
||||||
dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
|
||||||
dcb_printf(pdcb, "\tStatistics:\n");
|
dcb_printf(pdcb, "\tStatistics:\n");
|
||||||
@ -459,5 +471,6 @@ va_list args;
|
|||||||
vsnprintf(GWBUF_DATA(buf), 10240, fmt, args);
|
vsnprintf(GWBUF_DATA(buf), 10240, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
|
buf->end = GWBUF_DATA(buf) + strlen(GWBUF_DATA(buf)) + 1;
|
||||||
dcb->func.write(dcb, buf);
|
dcb->func.write(dcb, buf);
|
||||||
}
|
}
|
||||||
|
@ -162,11 +162,13 @@ void *handle;
|
|||||||
static MODULES *
|
static MODULES *
|
||||||
find_module(const char *module)
|
find_module(const char *module)
|
||||||
{
|
{
|
||||||
while (registered)
|
MODULES *mod = registered;
|
||||||
if (strcmp(registered->module, module) == 0)
|
|
||||||
return registered;
|
while (mod)
|
||||||
|
if (strcmp(mod->module, module) == 0)
|
||||||
|
return mod;
|
||||||
else
|
else
|
||||||
registered = registered->next;
|
mod = mod->next;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,11 +240,11 @@ printModules()
|
|||||||
{
|
{
|
||||||
MODULES *ptr = registered;
|
MODULES *ptr = registered;
|
||||||
|
|
||||||
printf("%-15s | %-10s | Version\n", "Module Name", "Module Type");
|
printf("%-15s | %-11s | Version\n", "Module Name", "Module Type");
|
||||||
printf("-----------------------------------------------------\n");
|
printf("-----------------------------------------------------\n");
|
||||||
while (ptr)
|
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;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,11 +259,11 @@ dprintAllModules(DCB *dcb)
|
|||||||
{
|
{
|
||||||
MODULES *ptr = registered;
|
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");
|
dcb_printf(dcb, "-----------------------------------------------------\n");
|
||||||
while (ptr)
|
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;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ void
|
|||||||
printServer(SERVER *server)
|
printServer(SERVER *server)
|
||||||
{
|
{
|
||||||
printf("Server %p\n", server);
|
printf("Server %p\n", server);
|
||||||
printf("\tServer: %s\n", server->name);
|
printf("\tServer: %s\n", server->name);
|
||||||
printf("\tProtocol: %s\n", server->protocol);
|
printf("\tProtocol: %s\n", server->protocol);
|
||||||
printf("\tPort: %d\n", server->port);
|
printf("\tPort: %d\n", server->port);
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ SERVER *ptr;
|
|||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Server %p\n", ptr);
|
dcb_printf(dcb, "Server %p\n", ptr);
|
||||||
dcb_printf(dcb, "\tServer: %s\n", ptr->name);
|
dcb_printf(dcb, "\tServer: %s\n", ptr->name);
|
||||||
dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol);
|
dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol);
|
||||||
dcb_printf(dcb, "\tPort: %d\n", ptr->port);
|
dcb_printf(dcb, "\tPort: %d\n", ptr->port);
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
@ -219,12 +219,12 @@ SERVER *ptr = service->databases;
|
|||||||
|
|
||||||
printf("Service %p\n", service);
|
printf("Service %p\n", service);
|
||||||
printf("\tService: %s\n", service->name);
|
printf("\tService: %s\n", service->name);
|
||||||
printf("\tRouter: %s (%p)\n", service->routerModule, service->router);
|
printf("\tRouter: %s (%p)\n", service->routerModule, service->router);
|
||||||
printf("\tStarted: %s", asctime(localtime(&service->stats.started)));
|
printf("\tStarted: %s", asctime(localtime(&service->stats.started)));
|
||||||
printf("\tBackend databases\n");
|
printf("\tBackend databases\n");
|
||||||
while (ptr)
|
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;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
printf("\tTotal connections: %d\n", service->stats.n_sessions);
|
printf("\tTotal connections: %d\n", service->stats.n_sessions);
|
||||||
@ -270,14 +270,14 @@ SERVICE *ptr;
|
|||||||
SERVER *server = ptr->databases;
|
SERVER *server = ptr->databases;
|
||||||
dcb_printf(dcb, "Service %p\n", ptr);
|
dcb_printf(dcb, "Service %p\n", ptr);
|
||||||
dcb_printf(dcb, "\tService: %s\n", ptr->name);
|
dcb_printf(dcb, "\tService: %s\n", ptr->name);
|
||||||
dcb_printf(dcb, "\tRouter: %s (%p)\n", ptr->routerModule,
|
dcb_printf(dcb, "\tRouter: %s (%p)\n", ptr->routerModule,
|
||||||
ptr->router);
|
ptr->router);
|
||||||
dcb_printf(dcb, "\tStarted: %s",
|
dcb_printf(dcb, "\tStarted: %s",
|
||||||
asctime(localtime(&ptr->stats.started)));
|
asctime(localtime(&ptr->stats.started)));
|
||||||
dcb_printf(dcb, "\tBackend databases\n");
|
dcb_printf(dcb, "\tBackend databases\n");
|
||||||
while (server)
|
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->protocol);
|
||||||
server = server->next;
|
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_read(DCB *, GWBUF **); /* Generic read routine */
|
||||||
extern int dcb_write(DCB *, GWBUF *); /* Generic write routine */
|
extern int dcb_write(DCB *, GWBUF *); /* Generic write routine */
|
||||||
extern int dcb_drain_writeq(DCB *); /* 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 printAllDCBs(); /* Debug to print all DCB in the system */
|
||||||
extern void printDCB(DCB *); /* Debug print routine */
|
extern void printDCB(DCB *); /* Debug print routine */
|
||||||
extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
|
extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
#define TELNET_IAC 255
|
||||||
|
|
||||||
static char *version_str = "V1.0.0";
|
static char *version_str = "V1.0.0";
|
||||||
|
|
||||||
@ -129,7 +130,16 @@ void *rsession = session->router_session;
|
|||||||
|
|
||||||
if ((n = dcb_read(dcb, &head)) != -1)
|
if ((n = dcb_read(dcb, &head)) != -1)
|
||||||
{
|
{
|
||||||
router->routeQuery(router_instance, rsession, head);
|
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;
|
return n;
|
||||||
@ -236,12 +246,13 @@ int n_connect = 0;
|
|||||||
* explicitly close a connection.
|
* explicitly close a connection.
|
||||||
*
|
*
|
||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
* @param event The epoll descriptor
|
* @param efd The epoll descriptor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
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);
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
pnum = atoi(port);
|
pnum = atoi(port);
|
||||||
addr.sin_port = htons(pnum);
|
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)
|
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 */
|
/** The module object definition */
|
||||||
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, execute };
|
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 SPINLOCK instlock;
|
||||||
static CLI_INSTANCE *instances;
|
static CLI_INSTANCE *instances;
|
||||||
@ -147,7 +147,7 @@ CLI_SESSION *client;
|
|||||||
}
|
}
|
||||||
client->session = session;
|
client->session = session;
|
||||||
|
|
||||||
memset(client->cmdbuf, 80, 0);
|
memset(client->cmdbuf, 0, 80);
|
||||||
|
|
||||||
spinlock_acquire(&inst->lock);
|
spinlock_acquire(&inst->lock);
|
||||||
client->next = inst->sessions;
|
client->next = inst->sessions;
|
||||||
@ -211,14 +211,18 @@ execute(ROUTER *instance, void *router_session, GWBUF *queue)
|
|||||||
CLI_SESSION *session = (CLI_SESSION *)router_session;
|
CLI_SESSION *session = (CLI_SESSION *)router_session;
|
||||||
|
|
||||||
/* Extract the characters */
|
/* Extract the characters */
|
||||||
strncat(session->cmdbuf, GWBUF_DATA(queue), GWBUF_LENGTH(queue));
|
while (queue)
|
||||||
/* Echo back to the user */
|
{
|
||||||
dcb_write(session->session->client, queue);
|
strncat(session->cmdbuf, GWBUF_DATA(queue), GWBUF_LENGTH(queue));
|
||||||
|
queue = gwbuf_consume(queue, GWBUF_LENGTH(queue));
|
||||||
|
}
|
||||||
|
|
||||||
if (strrchr(session->cmdbuf, '\n'))
|
if (strrchr(session->cmdbuf, '\n'))
|
||||||
{
|
{
|
||||||
execute_cmd(session);
|
if (execute_cmd(session))
|
||||||
dcb_printf(session->session->client, "Gateway> ");
|
dcb_printf(session->session->client, "Gateway> ");
|
||||||
|
else
|
||||||
|
session->session->client->func.close(session->session->client, 0);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -240,7 +244,7 @@ static struct {
|
|||||||
*
|
*
|
||||||
* @param cli The CLI_SESSION
|
* @param cli The CLI_SESSION
|
||||||
*/
|
*/
|
||||||
static void
|
static int
|
||||||
execute_cmd(CLI_SESSION *cli)
|
execute_cmd(CLI_SESSION *cli)
|
||||||
{
|
{
|
||||||
int i, found = 0;
|
int i, found = 0;
|
||||||
@ -254,6 +258,10 @@ int i, found = 0;
|
|||||||
}
|
}
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
|
else if (!strncmp(cli->cmdbuf, "quit", 4))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; cmds[i].cmd; i++)
|
for (i = 0; cmds[i].cmd; i++)
|
||||||
@ -268,5 +276,7 @@ int i, found = 0;
|
|||||||
if (!found)
|
if (!found)
|
||||||
dcb_printf(cli->session->client,
|
dcb_printf(cli->session->client,
|
||||||
"Command not known, type help for a list of available commands\n");
|
"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