Misc fixes for unitialised data reads

This commit is contained in:
Mark Riddoch 2013-06-27 01:56:30 +02:00
parent c1981b4dc6
commit 3b8ebfd215
10 changed files with 48 additions and 14 deletions

View File

@ -48,6 +48,7 @@
#include <errno.h>
#include <gw.h>
#include <poll.h>
#include <atomic.h>
static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */
static SPINLOCK *dcbspin = NULL;

View File

@ -262,7 +262,7 @@ dcb.o: dcb.c /usr/include/stdio.h /usr/include/features.h \
/usr/include/arpa/inet.h \
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdbool.h \
../include/gateway_mysql.h ../include/mysql_protocol.h ../include/dcb.h \
../include/poll.h
../include/poll.h ../include/atomic.h
load_utils.o: load_utils.c /usr/include/sys/param.h \
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/limits.h \
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/syslimits.h \

View File

@ -145,6 +145,11 @@ int i, nfds;
atomic_add(&pollStats.n_hup, 1);
dcb->func.hangup(dcb);
}
if (ev & EPOLLOUT)
{
atomic_add(&pollStats.n_write, 1);
dcb->func.write_ready(dcb);
}
if (ev & EPOLLIN)
{
if (dcb->state == DCB_STATE_LISTENING)
@ -158,11 +163,6 @@ int i, nfds;
dcb->func.read(dcb);
}
}
if (ev & EPOLLOUT)
{
atomic_add(&pollStats.n_write, 1);
dcb->func.write_ready(dcb);
}
}
}
if (shutdown)

View File

@ -58,7 +58,7 @@ SERVER *server;
server->name = strdup(servname);
server->protocol = strdup(protocol);
server->port = port;
memset(&server->stats, sizeof(SERVER_STATS), 0);
memset(&server->stats, 0, sizeof(SERVER_STATS));
server->status = SERVER_RUNNING;
server->nextdb = NULL;

View File

@ -67,7 +67,7 @@ SERVICE *service;
}
service->name = strdup(servname);
service->routerModule = strdup(router);
memset(&service->stats, sizeof(SERVICE_STATS), 0);
memset(&service->stats, 0, sizeof(SERVICE_STATS));
service->ports = NULL;
service->stats.started = time(0);
service->state = SERVICE_STATE_ALLOC;
@ -75,6 +75,8 @@ SERVICE *service;
service->credentials.authdata = NULL;
service->users = users_alloc();
service->routerOptions = NULL;
service->databases = NULL;
spinlock_init(&service->spin);
spinlock_acquire(&service_spin);
service->next = allServices;

View File

@ -61,7 +61,7 @@ SESSION *session;
return NULL;
session->service = service;
session->client = client;
memset(&session->stats, sizeof(SESSION_STATS), 0);
memset(&session->stats, 0, sizeof(SESSION_STATS));
session->stats.connect = time(0);
session->state = SESSION_STATE_ALLOC;
client->session = session;

View File

@ -51,6 +51,15 @@ typedef struct client_session {
*next;
} CLIENT_SESSION;
/**
* The statistics for this router instance
*/
typedef struct {
int n_sessions; /**< Number sessions created */
int n_queries; /**< Number of queries forwarded */
} ROUTER_STATS;
/**
* The per instance data for the router.
*/
@ -61,6 +70,7 @@ typedef struct instance {
BACKEND **servers; /**< The set of backend servers for this instance */
unsigned int bitmask; /**< Bitmask to apply to server->status */
unsigned int bitvalue; /**< Required value of server->status */
ROUTER_STATS stats; /**< Statistics for this router */
struct instance *next;
} INSTANCE;
#endif

View File

@ -773,6 +773,7 @@ int gw_read_client_event(DCB* dcb) {
ROUTER *router_instance = NULL;
void *rsession = NULL;
MySQLProtocol *protocol = NULL;
//uint8_t buffer[MAX_BUFFER_SIZE] = "";
int b = -1;
if (dcb) {
@ -997,7 +998,7 @@ int gw_MySQLListener(DCB *listener, char *config_bind) {
char *p;
char address[1024]="";
int port=0;
int one;
int one = 1;
// this gateway, as default, will bind on port 4404 for localhost only
(config_bind != NULL) ? (bind_address_and_port = config_bind) : (bind_address_and_port = "127.0.0.1:4406");

View File

@ -134,6 +134,8 @@ int i, n;
if ((inst = malloc(sizeof(INSTANCE))) == NULL)
return NULL;
memset(&inst->stats, 0, sizeof(ROUTER_STATS));
inst->service = service;
spinlock_init(&inst->lock);
inst->connections = NULL;
@ -291,6 +293,8 @@ int i;
return NULL;
}
inst->stats.n_sessions++;
/* Add this session to the list of active sessions */
spinlock_acquire(&inst->lock);
client->next = inst->connections;
@ -353,8 +357,10 @@ CLIENT_SESSION *session = (CLIENT_SESSION *)router_session;
static int
routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
{
INSTANCE *inst = (INSTANCE *)instance;
CLIENT_SESSION *session = (CLIENT_SESSION *)router_session;
inst->stats.n_queries++;
return session->dcb->func.write(session->dcb, queue);
}
@ -380,5 +386,7 @@ int i = 0;
}
spinlock_release(&inst->lock);
dcb_printf(dcb, "Number of router sessions: %d\n", i);
dcb_printf(dcb, "\tNumber of router sessions: %d\n", inst->stats.n_sessions);
dcb_printf(dcb, "\tCurrent no. of router sessions: %d\n", i);
dcb_printf(dcb, "\tNumber of queries forwarded: %d\n", inst->stats.n_queries);
}

View File

@ -20,12 +20,13 @@
static char *version_str = "V1.0.0";
static ROUTER *createInstance(SERVICE *service);
static ROUTER *createInstance(SERVICE *service, char **options);
static void *newSession(ROUTER *instance, SESSION *session);
static void closeSession(ROUTER *instance, void *session);
static int routeQuery(ROUTER *instance, void *session, GWBUF *queue);
static void diagnostic(ROUTER *instance, DCB *dcb);
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery };
static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery, diagnostic };
/**
* Implementation of the mandatory version entry point
@ -72,7 +73,7 @@ GetModuleObject()
* @return The instance data for this new instance
*/
static ROUTER *
createInstance(SERVICE *service)
createInstance(SERVICE *service, char **options)
{
return NULL;
}
@ -108,3 +109,14 @@ routeQuery(ROUTER *instance, void *session, GWBUF *queue)
{
return 0;
}
/**
* Diagnostics routine
*
* @param instance The router instance
* @param dcb The DCB for diagnostic output
*/
static void
diagnostic(ROUTER *instance, DCB *dcb)
{
}