This commit is contained in:
VilhoRaatikka
2014-11-13 18:00:43 +02:00
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") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
endif() 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}) subdirs(MYSQL_DIR_ALL ${MYSQL_DIR})
foreach(DIR ${MYSQL_DIR_ALL}) foreach(DIR ${MYSQL_DIR_ALL})
include_directories(${DIR}) include_directories(${DIR})

View File

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

View File

@ -269,7 +269,17 @@ MAXKEYS key;
errno, errno,
strerror(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; return 0;
} }

View File

@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <poll.h> #include <poll.h>
#include <dcb.h> #include <dcb.h>
@ -44,6 +44,7 @@ test1()
{ {
DCB *dcb; DCB *dcb;
int result; int result;
int eno = 0;
/* Poll tests */ /* Poll tests */
ss_dfprintf(stderr, ss_dfprintf(stderr,
@ -51,10 +52,35 @@ int result;
poll_init(); poll_init();
ss_dfprintf(stderr, "\t..done\nAdd a DCB"); ss_dfprintf(stderr, "\t..done\nAdd a DCB");
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER); 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); dcb->fd = socket(AF_UNIX, SOCK_STREAM, 0);
poll_add_dcb(dcb);
poll_remove_dcb(dcb); if(dcb->fd < 0){
poll_add_dcb(dcb); 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."); ss_dfprintf(stderr, "\t..done\nStart wait for events.");
sleep(10); sleep(10);
poll_shutdown(); poll_shutdown();

View File

@ -225,7 +225,9 @@ int gw_getsockerrno(
goto return_eno; 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:
return eno; return eno;

View File

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

View File

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

View File

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

View File

@ -314,10 +314,10 @@ char *remote, *user;
else else
my_session->userName = NULL; my_session->userName = NULL;
my_session->active = 1; 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_instance->source))
my_session->active = 0; 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_instance->user))
my_session->active = 0; my_session->active = 0;

View File

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

View File

@ -948,6 +948,7 @@ int gw_MySQLListener(
char *config_bind) char *config_bind)
{ {
int l_so; int l_so;
int syseno = 0;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
struct sockaddr_un local_addr; struct sockaddr_un local_addr;
struct sockaddr *current_addr; struct sockaddr *current_addr;
@ -996,7 +997,10 @@ int gw_MySQLListener(
listen_dcb->fd = -1; listen_dcb->fd = -1;
// socket options // 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 // set NONBLOCKING mode
setnonblocking(l_so); setnonblocking(l_so);
@ -1109,6 +1113,7 @@ int gw_MySQLAccept(DCB *listener)
int sendbuf = GW_BACKEND_SO_SNDBUF; int sendbuf = GW_BACKEND_SO_SNDBUF;
socklen_t optlen = sizeof(sendbuf); socklen_t optlen = sizeof(sendbuf);
int eno = 0; int eno = 0;
int syseno = 0;
int i = 0; int i = 0;
CHK_DCB(listener); CHK_DCB(listener);
@ -1215,9 +1220,16 @@ int gw_MySQLAccept(DCB *listener)
#endif /* FAKE_CODE */ #endif /* FAKE_CODE */
/* set nonblocking */ /* set nonblocking */
sendbuf = GW_CLIENT_SO_SNDBUF; 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; 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); setnonblocking(c_sock);
client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);

View File

@ -358,7 +358,8 @@ telnetd_listen(DCB *listener, char *config)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
int one = 1; int one = 1;
int rc; int rc;
int syseno = 0;
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL)); memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
@ -372,7 +373,12 @@ int rc;
} }
// socket options // 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 // set NONBLOCKING mode
setnonblocking(listener->fd); setnonblocking(listener->fd);
// bind address and port // 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){ if(tbl != NULL){
for(i = 0; i<tsize;i++)
{
free(tbl[i]);
}
free(tbl); free(tbl);
} }