This commit is contained in:
VilhoRaatikka 2014-11-13 18:00:43 +02:00
commit 9edee192a8
13 changed files with 131 additions and 57 deletions

View File

@ -66,6 +66,11 @@ if(GCOV)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
endif()
if(FAKE_CODE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFAKE_CODE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFAKE_CODE")
endif()
subdirs(MYSQL_DIR_ALL ${MYSQL_DIR})
foreach(DIR ${MYSQL_DIR_ALL})
include_directories(${DIR})

View File

@ -57,21 +57,19 @@ int main(int argc, char** argv)
{
fgets(readbuff,4092,infile);
psize = strlen(readbuff);
if(psize > 4092){
continue;
}
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1);
parse_query(qbuff);
tok = skygw_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
if(psize < 4092){
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1);
parse_query(qbuff);
tok = skygw_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
}
}
fclose(infile);
fclose(outfile);

View File

@ -269,7 +269,17 @@ MAXKEYS key;
errno,
strerror(errno))));
}
chmod(secret_file, S_IRUSR);
if( chmod(secret_file, S_IRUSR) < 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : failed to change the permissions of the"
"secret file [%s]. Error %d, %s.",
secret_file,
errno,
strerror(errno))));
}
return 0;
}

View File

@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <poll.h>
#include <dcb.h>
@ -44,6 +44,7 @@ test1()
{
DCB *dcb;
int result;
int eno = 0;
/* Poll tests */
ss_dfprintf(stderr,
@ -51,10 +52,35 @@ int result;
poll_init();
ss_dfprintf(stderr, "\t..done\nAdd a DCB");
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER);
if(dcb == NULL){
ss_dfprintf(stderr, "\nError on function call: dcb_alloc() returned NULL.\n");
return 1;
}
dcb->fd = socket(AF_UNIX, SOCK_STREAM, 0);
poll_add_dcb(dcb);
poll_remove_dcb(dcb);
poll_add_dcb(dcb);
if(dcb->fd < 0){
ss_dfprintf(stderr, "\nError on function call: socket() returned %d: %s\n",errno,strerror(errno));
return 1;
}
if((eno = poll_add_dcb(dcb)) != 0){
ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno);
return 1;
}
if((eno = poll_remove_dcb(dcb)) != 0){
ss_dfprintf(stderr, "\nError on function call: poll_remove_dcb() returned %d.\n",eno);
return 1;
}
if((eno = poll_add_dcb(dcb)) != 0){
ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno);
return 1;
}
ss_dfprintf(stderr, "\t..done\nStart wait for events.");
sleep(10);
poll_shutdown();

View File

@ -225,7 +225,9 @@ int gw_getsockerrno(
goto return_eno;
}
getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&eno, &elen);
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&eno, &elen) != 0){
eno = 0;
}
return_eno:
return eno;

View File

@ -435,7 +435,7 @@ HINT_MODE mode = HM_EXECUTE;
token_free(tok);
} /*< while */
if (tok->token == TOK_EOL)
if ( tok && tok->token == TOK_EOL)
{
token_free(tok);
}

View File

@ -398,7 +398,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
QLA_SESSION *my_session = (QLA_SESSION *)session;
char *ptr;
int length;
int length = 0;
struct tm t;
struct timeval tv;

View File

@ -415,8 +415,9 @@ GWBUF *clone = NULL;
modutil_MySQL_Query(queue, &dummy, &length, &residual);
clone = gwbuf_clone(queue);
my_session->residual = residual;
free(ptr);
}
free(ptr);
}
/* Pass the query downstream */

View File

@ -314,10 +314,10 @@ char *remote, *user;
else
my_session->userName = NULL;
my_session->active = 1;
if (my_instance->source && strcmp(my_session->clientHost,
if (my_instance->source && my_session->clientHost && strcmp(my_session->clientHost,
my_instance->source))
my_session->active = 0;
if (my_instance->user && strcmp(my_session->userName,
if (my_instance->user && my_session->userName && strcmp(my_session->userName,
my_instance->user))
my_session->active = 0;

View File

@ -40,6 +40,7 @@
#include <httpd.h>
#include <gw.h>
#include <modinfo.h>
#include <log_manager.h>
MODULE_INFO info = {
MODULE_API_PROTOCOL,
@ -171,7 +172,7 @@ HTTPD_session *client_data = NULL;
j++;
}
while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf))) {
while (!ISspace(buf[j]) && (i < sizeof(url) - 1) && (j < sizeof(buf) - 1)) {
url[i] = buf[j];
i++; j++;
}
@ -236,7 +237,7 @@ HTTPD_session *client_data = NULL;
dcb_printf(dcb, "Welcome to HTTPD MaxScale (c) %s\n\n", version_str);
if (strcmp(url, "/show") == 0) {
if (strlen(query_string)) {
if (query_string && strlen(query_string)) {
if (strcmp(query_string, "dcb") == 0)
dprintAllDCBs(dcb);
if (strcmp(query_string, "session") == 0)
@ -327,25 +328,29 @@ int n_connect = 0;
else
{
atomic_add(&dcb->stats.n_accepts, 1);
client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);
client->fd = so;
client->remote = strdup(inet_ntoa(addr.sin_addr));
memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL));
if((client = dcb_alloc(DCB_ROLE_REQUEST_HANDLER))){
client->fd = so;
client->remote = strdup(inet_ntoa(addr.sin_addr));
memcpy(&client->func, &MyObject, sizeof(GWPROTOCOL));
/* we don't need the session */
client->session = NULL;
/* we don't need the session */
client->session = NULL;
/* create the session data for HTTPD */
client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session));
client->data = client_data;
/* create the session data for HTTPD */
client_data = (HTTPD_session *)calloc(1, sizeof(HTTPD_session));
client->data = client_data;
if (poll_add_dcb(client) == -1)
{
return n_connect;
if (poll_add_dcb(client) == -1)
{
close(so);
return n_connect;
}
n_connect++;
}
n_connect++;
}
}
return n_connect;
}
@ -373,7 +378,8 @@ httpd_listen(DCB *listener, char *config)
{
struct sockaddr_in addr;
int one = 1;
int rc;
int rc;
int syseno = 0;
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
if (!parse_bindconfig(config, 6442, &addr))
@ -385,12 +391,16 @@ int rc;
}
/* socket options */
setsockopt(listener->fd,
syseno = setsockopt(listener->fd,
SOL_SOCKET,
SO_REUSEADDR,
(char *)&one,
sizeof(one));
if(syseno != 0){
skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno));
return 0;
}
/* set NONBLOCKING mode */
setnonblocking(listener->fd);
@ -439,15 +449,19 @@ static int httpd_get_line(int sock, char *buf, int size) {
if (c == '\r') {
n = recv(sock, &c, 1, MSG_PEEK);
/* DEBUG printf("%02X\n", c); */
if ((n > 0) && (c == '\n'))
recv(sock, &c, 1, 0);
else
if ((n > 0) && (c == '\n')) {
if(recv(sock, &c, 1, 0) < 0){
c = '\n';
}
} else {
c = '\n';
}
}
buf[i] = c;
i++;
} else
} else {
c = '\n';
}
}
buf[i] = '\0';

View File

@ -948,6 +948,7 @@ int gw_MySQLListener(
char *config_bind)
{
int l_so;
int syseno = 0;
struct sockaddr_in serv_addr;
struct sockaddr_un local_addr;
struct sockaddr *current_addr;
@ -996,7 +997,10 @@ int gw_MySQLListener(
listen_dcb->fd = -1;
// socket options
setsockopt(l_so, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
if((syseno = setsockopt(l_so, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one))) != 0){
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno))));
}
// set NONBLOCKING mode
setnonblocking(l_so);
@ -1109,6 +1113,7 @@ int gw_MySQLAccept(DCB *listener)
int sendbuf = GW_BACKEND_SO_SNDBUF;
socklen_t optlen = sizeof(sendbuf);
int eno = 0;
int syseno = 0;
int i = 0;
CHK_DCB(listener);
@ -1215,9 +1220,16 @@ int gw_MySQLAccept(DCB *listener)
#endif /* FAKE_CODE */
/* set nonblocking */
sendbuf = GW_CLIENT_SO_SNDBUF;
setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen);
if((syseno = setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen)) != 0){
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno))));
}
sendbuf = GW_CLIENT_SO_RCVBUF;
setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen);
if((syseno = setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen)) != 0){
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno))));
}
setnonblocking(c_sock);
client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);

View File

@ -358,7 +358,8 @@ telnetd_listen(DCB *listener, char *config)
{
struct sockaddr_in addr;
int one = 1;
int rc;
int rc;
int syseno = 0;
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
@ -372,7 +373,12 @@ int rc;
}
// socket options
setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
syseno = setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
if(syseno != 0){
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno))));
return 0;
}
// set NONBLOCKING mode
setnonblocking(listener->fd);
// bind address and port

View File

@ -1540,12 +1540,12 @@ skygw_query_type_t is_read_tmp_table(
}
}
for(i = 0; i<tsize;i++)
{
free(tbl[i]);
}
if(tbl != NULL){
for(i = 0; i<tsize;i++)
{
free(tbl[i]);
}
free(tbl);
}