Branch update
Branch update
This commit is contained in:
@ -116,10 +116,12 @@ char fname[1024], *home;
|
||||
char uname[80], passwd[80];
|
||||
|
||||
initialise();
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL)
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){
|
||||
sprintf(fname, "%s/etc/passwd", home);
|
||||
else
|
||||
}
|
||||
else{
|
||||
sprintf(fname, "/usr/local/skysql/MaxScale/etc/passwd");
|
||||
}
|
||||
if ((fp = fopen(fname, "r")) == NULL)
|
||||
return NULL;
|
||||
if ((rval = users_alloc()) == NULL)
|
||||
@ -150,10 +152,12 @@ FILE *fp;
|
||||
char fname[1024], *home, *cpasswd;
|
||||
|
||||
initialise();
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL)
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){
|
||||
sprintf(fname, "%s/etc/passwd", home);
|
||||
else
|
||||
}
|
||||
else{
|
||||
sprintf(fname, "/usr/local/skysql/MaxScale/etc/passwd");
|
||||
}
|
||||
|
||||
if (users == NULL)
|
||||
{
|
||||
@ -246,7 +250,7 @@ char* admin_remove_user(
|
||||
/**
|
||||
* Open passwd file and remove user from the file.
|
||||
*/
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL) {
|
||||
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024) {
|
||||
sprintf(fname, "%s/etc/passwd", home);
|
||||
sprintf(fname_tmp, "%s/etc/passwd_tmp", home);
|
||||
} else {
|
||||
@ -310,7 +314,12 @@ char* admin_remove_user(
|
||||
* Unmatching lines are copied to tmp file.
|
||||
*/
|
||||
if (strncmp(uname, fusr, strlen(uname)+1) != 0) {
|
||||
fsetpos(fp, &rpos); /** one step back */
|
||||
if(fsetpos(fp, &rpos) != 0){ /** one step back */
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Unable to set stream position. ")));
|
||||
|
||||
}
|
||||
fgets(line, LINELEN, fp);
|
||||
fputs(line, fp_tmp);
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ SHARED_BUF *sbuf;
|
||||
if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL)
|
||||
{
|
||||
free(rval);
|
||||
rval = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
@ -90,6 +91,7 @@ SHARED_BUF *sbuf;
|
||||
ss_dassert(sbuf->data != NULL);
|
||||
free(rval);
|
||||
free(sbuf);
|
||||
rval = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
spinlock_init(&rval->gwbuf_lock);
|
||||
@ -106,9 +108,8 @@ SHARED_BUF *sbuf;
|
||||
rval->gwbuf_bufobj = NULL;
|
||||
CHK_GWBUF(rval);
|
||||
retblock:
|
||||
if (rval == NULL || sbuf == NULL || sbuf->data == NULL)
|
||||
if (rval == NULL)
|
||||
{
|
||||
ss_dassert(rval != NULL && sbuf != NULL && sbuf->data != NULL);
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Memory allocation failed due to %s.",
|
||||
@ -516,8 +517,10 @@ void* gwbuf_get_buffer_object_data(
|
||||
}
|
||||
/** Unlock */
|
||||
spinlock_release(&buf->gwbuf_lock);
|
||||
|
||||
return bo->bo_data;
|
||||
if(bo){
|
||||
return bo->bo_data;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,7 @@
|
||||
* 12/09/14 Mark Riddoch Addition of checks on servers list and
|
||||
* internal router suppression of messages
|
||||
* 30/10/14 Massimiliano Pinto Added disable_master_failback parameter
|
||||
* 07/11/14 Massimiliano Pinto Addition of monitor timeouts for connect/read/write
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -59,6 +60,7 @@
|
||||
|
||||
extern int lm_enabled_logfiles_bitmask;
|
||||
|
||||
extern int setipaddress(struct in_addr *, char *);
|
||||
static int process_config_context(CONFIG_CONTEXT *);
|
||||
static int process_config_update(CONFIG_CONTEXT *);
|
||||
static void free_config_context(CONFIG_CONTEXT *);
|
||||
@ -462,6 +464,7 @@ int error_count = 0;
|
||||
|
||||
if (!succp)
|
||||
{
|
||||
if(param){
|
||||
LOGIF(LM, (skygw_log_write(
|
||||
LOGFILE_MESSAGE,
|
||||
"* Warning : invalid value type "
|
||||
@ -471,6 +474,12 @@ int error_count = 0;
|
||||
((SERVICE*)obj->element)->name,
|
||||
param->name,
|
||||
param->value)));
|
||||
}else{
|
||||
LOGIF(LE, (skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"Error : parameter was NULL")));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} /*< if (rw_split) */
|
||||
@ -767,6 +776,9 @@ int error_count = 0;
|
||||
int replication_heartbeat = 0;
|
||||
int detect_stale_master = 0;
|
||||
int disable_master_failback = 0;
|
||||
int connect_timeout = 0;
|
||||
int read_timeout = 0;
|
||||
int write_timeout = 0;
|
||||
|
||||
module = config_get_value(obj->parameters, "module");
|
||||
servers = config_get_value(obj->parameters, "servers");
|
||||
@ -788,6 +800,16 @@ int error_count = 0;
|
||||
disable_master_failback = atoi(config_get_value(obj->parameters, "disable_master_failback"));
|
||||
}
|
||||
|
||||
if (config_get_value(obj->parameters, "backend_connect_timeout")) {
|
||||
connect_timeout = atoi(config_get_value(obj->parameters, "backend_connect_timeout"));
|
||||
}
|
||||
if (config_get_value(obj->parameters, "backend_read_timeout")) {
|
||||
read_timeout = atoi(config_get_value(obj->parameters, "backend_read_timeout"));
|
||||
}
|
||||
if (config_get_value(obj->parameters, "backend_write_timeout")) {
|
||||
write_timeout = atoi(config_get_value(obj->parameters, "backend_write_timeout"));
|
||||
}
|
||||
|
||||
if (module)
|
||||
{
|
||||
obj->element = monitor_alloc(obj->object, module);
|
||||
@ -819,6 +841,14 @@ int error_count = 0;
|
||||
if(disable_master_failback == 1)
|
||||
monitorDisableMasterFailback(obj->element, disable_master_failback);
|
||||
|
||||
/* set timeouts */
|
||||
if (connect_timeout > 0)
|
||||
monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, connect_timeout);
|
||||
if (read_timeout > 0)
|
||||
monitorSetNetworkTimeout(obj->element, MONITOR_READ_TIMEOUT, read_timeout);
|
||||
if (write_timeout > 0)
|
||||
monitorSetNetworkTimeout(obj->element, MONITOR_WRITE_TIMEOUT, write_timeout);
|
||||
|
||||
/* get the servers to monitor */
|
||||
s = strtok(servers, ",");
|
||||
while (s)
|
||||
@ -1271,7 +1301,7 @@ SERVER *server;
|
||||
(PERCENT_TYPE|COUNT_TYPE));
|
||||
}
|
||||
|
||||
if (!succp)
|
||||
if (!succp && param != NULL)
|
||||
{
|
||||
LOGIF(LM, (skygw_log_write(
|
||||
LOGFILE_MESSAGE,
|
||||
@ -1316,6 +1346,7 @@ SERVER *server;
|
||||
|
||||
if (!succp)
|
||||
{
|
||||
if(param){
|
||||
LOGIF(LM, (skygw_log_write(
|
||||
LOGFILE_MESSAGE,
|
||||
"* Warning : invalid value type "
|
||||
@ -1325,6 +1356,11 @@ SERVER *server;
|
||||
((SERVICE*)obj->element)->name,
|
||||
param->name,
|
||||
param->value)));
|
||||
}else{
|
||||
LOGIF(LE, (skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"Error : parameter was NULL")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1359,7 +1395,7 @@ SERVER *server;
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(service, atoi(enable_root_user));
|
||||
|
||||
if (allow_localhost_match_wildcard_host)
|
||||
if (allow_localhost_match_wildcard_host && service)
|
||||
serviceEnableLocalhostMatchWildcardHost(
|
||||
service,
|
||||
atoi(allow_localhost_match_wildcard_host));
|
||||
@ -1623,6 +1659,9 @@ static char *monitor_params[] =
|
||||
"detect_replication_lag",
|
||||
"detect_stale_master",
|
||||
"disable_master_failback",
|
||||
"backend_connect_timeout",
|
||||
"backend_read_timeout",
|
||||
"backend_write_timeout",
|
||||
NULL
|
||||
};
|
||||
/**
|
||||
|
@ -646,7 +646,13 @@ getUsers(SERVICE *service, USERS *users)
|
||||
|
||||
users_data = (char *)calloc(nusers, (users_data_row_len * sizeof(char)) + 1);
|
||||
|
||||
if(users_data == NULL) {
|
||||
if (users_data == NULL) {
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Memory allocation for user data failed due to "
|
||||
"%d, %s.",
|
||||
errno,
|
||||
strerror(errno))));
|
||||
mysql_free_result(result);
|
||||
mysql_close(con);
|
||||
|
||||
@ -855,9 +861,6 @@ static int uh_cmpfun( void* v1, void* v2) {
|
||||
if (v1 == NULL || v2 == NULL)
|
||||
return 0;
|
||||
|
||||
if (hu1 == NULL || hu2 == NULL)
|
||||
return 0;
|
||||
|
||||
if (hu1->user == NULL || hu2->user == NULL)
|
||||
return 0;
|
||||
|
||||
@ -961,9 +964,6 @@ char *mysql_format_user_entry(void *data)
|
||||
|
||||
entry = (MYSQL_USER_HOST *) data;
|
||||
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
|
||||
mysql_user = (char *) calloc(mysql_user_len, sizeof(char));
|
||||
|
||||
if (mysql_user == NULL)
|
||||
|
@ -1140,41 +1140,48 @@ dcb_close(DCB *dcb)
|
||||
/*<
|
||||
* Stop dcb's listening and modify state accordingly.
|
||||
*/
|
||||
rc = poll_remove_dcb(dcb);
|
||||
|
||||
ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
|
||||
dcb->state == DCB_STATE_ZOMBIE);
|
||||
/**
|
||||
* close protocol and router session
|
||||
*/
|
||||
if (dcb->func.close != NULL)
|
||||
{
|
||||
dcb->func.close(dcb);
|
||||
}
|
||||
dcb_call_callback(dcb, DCB_REASON_CLOSE);
|
||||
if (dcb->state == DCB_STATE_POLLING)
|
||||
{
|
||||
rc = poll_remove_dcb(dcb);
|
||||
|
||||
if (rc == 0) {
|
||||
LOGIF(LD, (skygw_log_write(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [dcb_close] Removed dcb %p in state %s from "
|
||||
"poll set.",
|
||||
pthread_self(),
|
||||
dcb,
|
||||
STRDCBSTATE(dcb->state))));
|
||||
} else {
|
||||
LOGIF(LE, (skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"%lu [dcb_close] Error : Removing dcb %p in state %s from "
|
||||
"poll set failed.",
|
||||
pthread_self(),
|
||||
dcb,
|
||||
STRDCBSTATE(dcb->state))));
|
||||
}
|
||||
|
||||
if (dcb->state == DCB_STATE_NOPOLLING)
|
||||
{
|
||||
dcb_add_to_zombieslist(dcb);
|
||||
}
|
||||
if (rc == 0) {
|
||||
LOGIF(LD, (skygw_log_write(
|
||||
LOGFILE_DEBUG,
|
||||
"%lu [dcb_close] Removed dcb %p in state %s from "
|
||||
"poll set.",
|
||||
pthread_self(),
|
||||
dcb,
|
||||
STRDCBSTATE(dcb->state))));
|
||||
} else {
|
||||
LOGIF(LE, (skygw_log_write(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Removing DCB fd == %d in state %s from "
|
||||
"poll set failed.",
|
||||
dcb->fd,
|
||||
STRDCBSTATE(dcb->state))));
|
||||
}
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
/**
|
||||
* close protocol and router session
|
||||
*/
|
||||
if (dcb->func.close != NULL)
|
||||
{
|
||||
dcb->func.close(dcb);
|
||||
}
|
||||
dcb_call_callback(dcb, DCB_REASON_CLOSE);
|
||||
|
||||
|
||||
if (dcb->state == DCB_STATE_NOPOLLING)
|
||||
{
|
||||
dcb_add_to_zombieslist(dcb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
|
||||
dcb->state == DCB_STATE_ZOMBIE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1662,7 +1669,7 @@ static bool dcb_set_state_nomutex(
|
||||
"Old state %s > new state %s.",
|
||||
pthread_self(),
|
||||
dcb,
|
||||
STRDCBSTATE(*old_state),
|
||||
(old_state == NULL ? "NULL" : STRDCBSTATE(*old_state)),
|
||||
STRDCBSTATE(new_state))));
|
||||
}
|
||||
return succp;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <filter.h>
|
||||
#include <session.h>
|
||||
#include <modules.h>
|
||||
@ -328,27 +329,43 @@ DOWNSTREAM *me;
|
||||
if ((filter->obj = load_module(filter->module,
|
||||
MODULE_FILTER)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
me = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
}
|
||||
|
||||
if (filter->filter == NULL)
|
||||
{
|
||||
if ((filter->filter = (filter->obj->createInstance)(filter->options,
|
||||
filter->parameters)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
me = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
}
|
||||
if ((me = (DOWNSTREAM *)calloc(1, sizeof(DOWNSTREAM))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Memory allocation for filter session failed "
|
||||
"due to %d,%s.",
|
||||
errno,
|
||||
strerror(errno))));
|
||||
|
||||
goto retblock;
|
||||
}
|
||||
me->instance = filter->filter;
|
||||
me->routeQuery = (void *)(filter->obj->routeQuery);
|
||||
me->session = filter->obj->newSession(me->instance, session);
|
||||
|
||||
|
||||
if ((me->session=filter->obj->newSession(me->instance, session)) == NULL)
|
||||
{
|
||||
free(me);
|
||||
me = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
filter->obj->setDownstream(me->instance, me->session, downstream);
|
||||
|
||||
|
||||
retblock:
|
||||
return me;
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ const char *progname = NULL;
|
||||
static struct option long_options[] = {
|
||||
{"homedir", required_argument, 0, 'c'},
|
||||
{"config", required_argument, 0, 'f'},
|
||||
{"nodeamon", required_argument, 0, 'd'},
|
||||
{"nodaemon", no_argument, 0, 'd'},
|
||||
{"log", required_argument, 0, 'l'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, '?'},
|
||||
@ -479,6 +479,11 @@ static bool resolve_maxscale_conf_fname(
|
||||
goto return_succp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Allocate memory for use of realpath */
|
||||
*cnf_full_path = (char *)malloc(PATH_MAX+1);
|
||||
}
|
||||
/*<
|
||||
* 3. argument is valid relative pathname
|
||||
* '-f ../myconf.cnf'
|
||||
@ -549,6 +554,7 @@ static bool resolve_maxscale_homedir(
|
||||
if (*p_home_dir != NULL)
|
||||
{
|
||||
log_context = strdup("Command-line argument");
|
||||
tmp = NULL;
|
||||
goto check_home_dir;
|
||||
}
|
||||
/*<
|
||||
@ -640,7 +646,7 @@ check_home_dir:
|
||||
fprintf(stderr,
|
||||
"Using %s as MAXSCALE_HOME = %s\n",
|
||||
log_context,
|
||||
tmp);
|
||||
(tmp == NULL ? *p_home_dir : tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -648,8 +654,11 @@ check_home_dir:
|
||||
{
|
||||
succp = false;
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
if (tmp != NULL)
|
||||
{
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
if (log_context != NULL)
|
||||
{
|
||||
free(log_context);
|
||||
@ -993,7 +1002,7 @@ int main(int argc, char **argv)
|
||||
int n_services;
|
||||
int eno = 0; /*< local variable for errno */
|
||||
int opt;
|
||||
void** threads; /*< thread list */
|
||||
void** threads = NULL; /*< thread list */
|
||||
char mysql_home[PATH_MAX+1];
|
||||
char datadir_arg[10+PATH_MAX+1]; /*< '--datadir=' + PATH_MAX */
|
||||
char language_arg[11+PATH_MAX+1]; /*< '--language=' + PATH_MAX */
|
||||
@ -1470,7 +1479,14 @@ int main(int argc, char **argv)
|
||||
bool succp;
|
||||
|
||||
sprintf(buf, "%s/log", home_dir);
|
||||
mkdir(buf, 0777);
|
||||
if(mkdir(buf, 0777) != 0){
|
||||
|
||||
if(errno != EEXIST){
|
||||
fprintf(stderr,
|
||||
"Error: Cannot create log directory: %s\n",buf);
|
||||
goto return_main;
|
||||
}
|
||||
}
|
||||
argv[0] = "MaxScale";
|
||||
argv[1] = "-j";
|
||||
argv[2] = buf;
|
||||
@ -1517,7 +1533,12 @@ int main(int argc, char **argv)
|
||||
* machine.
|
||||
*/
|
||||
sprintf(datadir, "%s/data%d", home_dir, getpid());
|
||||
mkdir(datadir, 0777);
|
||||
if(mkdir(datadir, 0777) != 0){
|
||||
LOGIF(LE,(skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Directory creation failed due to %s.",
|
||||
strerror(errno))));
|
||||
}
|
||||
|
||||
if (!daemon_mode)
|
||||
{
|
||||
@ -1695,11 +1716,7 @@ int main(int argc, char **argv)
|
||||
for (n = 0; n < n_threads - 1; n++)
|
||||
{
|
||||
thread_wait(threads[n]);
|
||||
}
|
||||
free(threads);
|
||||
free(home_dir);
|
||||
free(cnf_file_path);
|
||||
|
||||
}
|
||||
/*<
|
||||
* Wait the flush thread.
|
||||
*/
|
||||
@ -1723,6 +1740,13 @@ int main(int argc, char **argv)
|
||||
unlink_pidfile();
|
||||
|
||||
return_main:
|
||||
if (threads)
|
||||
free(threads);
|
||||
if (home_dir)
|
||||
free(home_dir);
|
||||
if (cnf_file_path)
|
||||
free(cnf_file_path);
|
||||
|
||||
return rc;
|
||||
} /*< End of main */
|
||||
|
||||
|
@ -93,7 +93,7 @@ unsigned char mask;
|
||||
{
|
||||
bitmask->bits = realloc(bitmask->bits,
|
||||
(bitmask->length + BIT_LENGTH_INC) / 8);
|
||||
memset(bitmask + (bitmask->length / 8), 0,
|
||||
memset(bitmask->bits + (bitmask->length / 8), 0,
|
||||
BIT_LENGTH_INC / 8);
|
||||
bitmask->length += (BIT_LENGTH_INC / 8);
|
||||
}
|
||||
@ -121,7 +121,7 @@ unsigned char mask;
|
||||
{
|
||||
bitmask->bits = realloc(bitmask->bits,
|
||||
(bitmask->length + BIT_LENGTH_INC) / 8);
|
||||
memset(bitmask + (bitmask->length / 8), 0,
|
||||
memset(bitmask->bits + (bitmask->length / 8), 0,
|
||||
BIT_LENGTH_INC / 8);
|
||||
bitmask->length += (BIT_LENGTH_INC / 8);
|
||||
}
|
||||
@ -150,7 +150,7 @@ unsigned char mask;
|
||||
{
|
||||
bitmask->bits = realloc(bitmask->bits,
|
||||
(bitmask->length + BIT_LENGTH_INC) / 8);
|
||||
memset(bitmask + (bitmask->length / 8), 0,
|
||||
memset(bitmask->bits + (bitmask->length / 8), 0,
|
||||
BIT_LENGTH_INC / 8);
|
||||
bitmask->length += (BIT_LENGTH_INC / 8);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ void *
|
||||
load_module(const char *module, const char *type)
|
||||
{
|
||||
char *home, *version;
|
||||
char fname[MAXPATHLEN];
|
||||
char fname[MAXPATHLEN+1];
|
||||
void *dlhandle, *sym;
|
||||
char *(*ver)();
|
||||
void *(*ep)(), *modobj;
|
||||
@ -94,11 +94,12 @@ MODULE_INFO *mod_info = NULL;
|
||||
*
|
||||
* Search of the shared object.
|
||||
*/
|
||||
sprintf(fname, "./lib%s.so", module);
|
||||
snprintf(fname,MAXPATHLEN+1, "./lib%s.so", module);
|
||||
|
||||
if (access(fname, F_OK) == -1)
|
||||
{
|
||||
home = get_maxscale_home ();
|
||||
sprintf(fname, "%s/modules/lib%s.so", home, module);
|
||||
snprintf(fname, MAXPATHLEN+1,"%s/modules/lib%s.so", home, module);
|
||||
|
||||
if (access(fname, F_OK) == -1)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *enc;
|
||||
char *enc, *pw;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
@ -47,9 +47,21 @@ char *enc;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((enc = encryptPassword(argv[1])) != NULL)
|
||||
pw = calloc(81,sizeof(char));
|
||||
|
||||
if(pw == NULL){
|
||||
fprintf(stderr, "Error: cannot allocate enough memory.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
strncpy(pw,argv[1],80);
|
||||
|
||||
if ((enc = encryptPassword(pw)) != NULL){
|
||||
printf("%s\n", enc);
|
||||
else
|
||||
}else{
|
||||
fprintf(stderr, "Failed to encode the password\n");
|
||||
}
|
||||
|
||||
free(pw);
|
||||
return 0;
|
||||
}
|
||||
|
@ -175,6 +175,51 @@ GWBUF *addition;
|
||||
return orig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the SQL from a COM_QUERY packet and return in a NULL terminated buffer.
|
||||
* The buffer shoudl be freed by the caller when it is no longer required.
|
||||
*
|
||||
* If the packet is not a COM_QUERY packet then the function will return NULL
|
||||
*
|
||||
* @param buf The buffer chain
|
||||
* @return Null terminated string containing query text or NULL on error
|
||||
*/
|
||||
char *
|
||||
modutil_get_SQL(GWBUF *buf)
|
||||
{
|
||||
unsigned int len, length;
|
||||
unsigned char *ptr, *dptr, *rval = NULL;
|
||||
|
||||
if (!modutil_is_SQL(buf))
|
||||
return rval;
|
||||
ptr = GWBUF_DATA(buf);
|
||||
length = *ptr++;
|
||||
length += (*ptr++ << 8);
|
||||
length += (*ptr++ << 16);
|
||||
|
||||
if ((rval = (char *)malloc(length + 1)) == NULL)
|
||||
return NULL;
|
||||
dptr = rval;
|
||||
ptr += 2; // Skip sequence id and COM_QUERY byte
|
||||
len = GWBUF_LENGTH(buf) - 5;
|
||||
while (buf && length > 0)
|
||||
{
|
||||
int clen = length > len ? len : length;
|
||||
memcpy(dptr, ptr, clen);
|
||||
dptr += clen;
|
||||
length -= clen;
|
||||
buf = buf->next;
|
||||
if (buf)
|
||||
{
|
||||
ptr = GWBUF_DATA(buf);
|
||||
len = GWBUF_LENGTH(buf);
|
||||
}
|
||||
}
|
||||
*dptr = 0;
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy query string from GWBUF buffer to separate memory area.
|
||||
*
|
||||
|
@ -27,6 +27,7 @@
|
||||
* 23/05/14 Massimiliano Pinto Addition of monitor_interval parameter
|
||||
* and monitor id
|
||||
* 30/10/14 Massimiliano Pinto Addition of disable_master_failback parameter
|
||||
* 07/11/14 Massimiliano Pinto Addition of monitor network timeouts
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -342,5 +343,18 @@ monitorDisableMasterFailback(MONITOR *mon, int disable)
|
||||
{
|
||||
if (mon->module->disableMasterFailback != NULL) {
|
||||
mon->module->disableMasterFailback(mon->handle, disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Monitor timeouts for connect/read/write
|
||||
*
|
||||
* @param mon The monitor instance
|
||||
* @param type The timeout handling type
|
||||
* @param value The timeout to set
|
||||
*/
|
||||
void
|
||||
monitorSetNetworkTimeout(MONITOR *mon, int type, int value) {
|
||||
if (mon->module->setNetworkTimeout != NULL) {
|
||||
mon->module->setNetworkTimeout(mon->handle, type, value);
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +292,8 @@ poll_remove_dcb(DCB *dcb)
|
||||
CHK_DCB(dcb);
|
||||
|
||||
/*< It is possible that dcb has already been removed from the set */
|
||||
if (dcb->state != DCB_STATE_POLLING) {
|
||||
if (dcb->state != DCB_STATE_POLLING)
|
||||
{
|
||||
if (dcb->state == DCB_STATE_NOPOLLING ||
|
||||
dcb->state == DCB_STATE_ZOMBIE)
|
||||
{
|
||||
@ -300,7 +301,6 @@ poll_remove_dcb(DCB *dcb)
|
||||
}
|
||||
goto return_rc;
|
||||
}
|
||||
|
||||
/*<
|
||||
* Set state to NOPOLLING and remove dcb from poll set.
|
||||
*/
|
||||
|
@ -254,6 +254,7 @@ MAXKEYS key;
|
||||
secret_file,
|
||||
errno,
|
||||
strerror(errno))));
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,13 @@ SERVICE *service;
|
||||
}
|
||||
service->name = strdup(servname);
|
||||
service->routerModule = strdup(router);
|
||||
if (service->name == NULL || service->routerModule == NULL)
|
||||
{
|
||||
if (service->name)
|
||||
free(service->name);
|
||||
free(service);
|
||||
return NULL;
|
||||
}
|
||||
service->version_string = NULL;
|
||||
memset(&service->stats, 0, sizeof(SERVICE_STATS));
|
||||
service->ports = NULL;
|
||||
@ -196,8 +203,13 @@ GWPROTOCOL *funcs;
|
||||
|
||||
if (port->listener == NULL)
|
||||
{
|
||||
return 0;
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Failed to create listener for service %s.",
|
||||
service->name)));
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
if (strcmp(port->protocol, "MySQLClient") == 0) {
|
||||
int loaded;
|
||||
|
||||
@ -206,12 +218,25 @@ GWPROTOCOL *funcs;
|
||||
* including hosts and db names
|
||||
*/
|
||||
service->users = mysql_users_alloc();
|
||||
loaded = load_mysql_users(service);
|
||||
|
||||
|
||||
if ((loaded = load_mysql_users(service)) < 0)
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Unable to load users from %s:%d for "
|
||||
"service %s.",
|
||||
port->address,
|
||||
port->port,
|
||||
service->name)));
|
||||
hashtable_free(service->users->data);
|
||||
free(service->users);
|
||||
dcb_free(port->listener);
|
||||
port->listener = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
/* At service start last update is set to USERS_REFRESH_TIME seconds earlier.
|
||||
* This way MaxScale could try reloading users' just after startup
|
||||
*/
|
||||
|
||||
service->rate_limit.last=time(NULL) - USERS_REFRESH_TIME;
|
||||
service->rate_limit.nloads=1;
|
||||
|
||||
@ -219,14 +244,21 @@ GWPROTOCOL *funcs;
|
||||
LOGFILE_MESSAGE,
|
||||
"Loaded %d MySQL Users for service [%s].",
|
||||
loaded, service->name)));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Generic users table */
|
||||
service->users = users_alloc();
|
||||
}
|
||||
|
||||
if ((funcs =
|
||||
(GWPROTOCOL *)load_module(port->protocol, MODULE_PROTOCOL)) == NULL)
|
||||
if ((funcs=(GWPROTOCOL *)load_module(port->protocol, MODULE_PROTOCOL))
|
||||
== NULL)
|
||||
{
|
||||
if (service->users->data)
|
||||
{
|
||||
hashtable_free(service->users->data);
|
||||
}
|
||||
free(service->users);
|
||||
dcb_free(port->listener);
|
||||
port->listener = NULL;
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
@ -235,34 +267,60 @@ GWPROTOCOL *funcs;
|
||||
"for service %s not started.",
|
||||
port->protocol,
|
||||
service->name)));
|
||||
return 0;
|
||||
goto retblock;
|
||||
}
|
||||
memcpy(&(port->listener->func), funcs, sizeof(GWPROTOCOL));
|
||||
port->listener->session = NULL;
|
||||
|
||||
if (port->address)
|
||||
sprintf(config_bind, "%s:%d", port->address, port->port);
|
||||
else
|
||||
sprintf(config_bind, "0.0.0.0:%d", port->port);
|
||||
|
||||
if (port->listener->func.listen(port->listener, config_bind)) {
|
||||
if (port->listener->func.listen(port->listener, config_bind))
|
||||
{
|
||||
port->listener->session = session_alloc(service, port->listener);
|
||||
|
||||
if (port->listener->session != NULL) {
|
||||
if (port->listener->session != NULL)
|
||||
{
|
||||
port->listener->session->state = SESSION_STATE_LISTENER;
|
||||
listeners += 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Failed to create session to service %s.",
|
||||
service->name)));
|
||||
|
||||
if (service->users->data)
|
||||
{
|
||||
hashtable_free(service->users->data);
|
||||
}
|
||||
free(service->users);
|
||||
dcb_close(port->listener);
|
||||
port->listener = NULL;
|
||||
goto retblock;
|
||||
}
|
||||
} else {
|
||||
dcb_close(port->listener);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Error : Unable to start to listen port %d for %s %s.",
|
||||
port->port,
|
||||
port->protocol,
|
||||
service->name)));
|
||||
if (service->users->data)
|
||||
{
|
||||
hashtable_free(service->users->data);
|
||||
}
|
||||
free(service->users);
|
||||
dcb_close(port->listener);
|
||||
port->listener = NULL;
|
||||
}
|
||||
|
||||
retblock:
|
||||
return listeners;
|
||||
}
|
||||
|
||||
@ -1003,8 +1061,8 @@ int service_refresh_users(SERVICE *service) {
|
||||
if ( (time(NULL) < (service->rate_limit.last + USERS_REFRESH_TIME)) || (service->rate_limit.nloads > USERS_REFRESH_MAX_PER_TIME)) {
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"%lu [service_refresh_users] refresh rate limit exceeded loading new users' table",
|
||||
pthread_self())));
|
||||
"Refresh rate limit exceeded for load of users' table for service '%s'.",
|
||||
service->name)));
|
||||
|
||||
spinlock_release(&service->users_table_spin);
|
||||
return 1;
|
||||
|
@ -668,9 +668,10 @@ int i;
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"Failed to create filter '%s' for service '%s'.\n",
|
||||
service->filters[i]->name,
|
||||
service->name)));
|
||||
"Error : Failed to create filter '%s' for "
|
||||
"service '%s'.\n",
|
||||
service->filters[i]->name,
|
||||
service->name)));
|
||||
return 0;
|
||||
}
|
||||
session->filters[i].filter = service->filters[i];
|
||||
|
@ -269,7 +269,7 @@ int result = 0;
|
||||
char *home, buf[1024];
|
||||
|
||||
/* Unlink any existing password file before running this test */
|
||||
if ((home = getenv("MAXSCALE_HOME")) == NULL)
|
||||
if ((home = getenv("MAXSCALE_HOME")) == NULL || strlen(home) >= 1024)
|
||||
home = "/usr/local/skysql";
|
||||
sprintf(buf, "%s/etc/passwd", home);
|
||||
if (strcmp(buf, "/etc/passwd") != 0)
|
||||
|
@ -61,7 +61,9 @@ int buflen;
|
||||
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
|
||||
ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
|
||||
ss_dfprintf(stderr, "\t..done\nSet a hint for the buffer");
|
||||
hint = hint_create_parameter(NULL, strdup("name"), "value");
|
||||
char* name = strdup("name");
|
||||
hint = hint_create_parameter(NULL, name, "value");
|
||||
free(name);
|
||||
gwbuf_add_hint(buffer, hint);
|
||||
ss_info_dassert(hint == buffer->hint, "Buffer should point to first and only hint");
|
||||
ss_dfprintf(stderr, "\t..done\nSet a property for the buffer");
|
||||
|
@ -158,6 +158,7 @@ static bool do_hashtest(
|
||||
hashtable_free(h);
|
||||
|
||||
return_succp:
|
||||
free(val_arr);
|
||||
return succp;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,9 @@ HINT *hint;
|
||||
/* Hint tests */
|
||||
ss_dfprintf(stderr,
|
||||
"testhint : Add a parameter hint to a null list");
|
||||
hint = hint_create_parameter(NULL, strdup("name"), "value");
|
||||
char* name = strdup("name");
|
||||
hint = hint_create_parameter(NULL, name, "value");
|
||||
free(name);
|
||||
ss_info_dassert(NULL != hint, "New hint list should not be null");
|
||||
ss_info_dassert(0 == strcmp("value", hint->value), "Hint value should be correct");
|
||||
ss_info_dassert(0 != hint_exists(&hint, HINT_PARAMETER), "Hint of parameter type should exist");
|
||||
|
@ -68,7 +68,8 @@ char *status;
|
||||
server_set_status(server, SERVER_MASTER);
|
||||
status = server_status(server);
|
||||
ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status.");
|
||||
server_clear_status(server, SERVER_MASTER);
|
||||
server_clear_status(server, SERVER_MASTER);
|
||||
free(status);
|
||||
status = server_status(server);
|
||||
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared.");
|
||||
if (NULL != status) free(status);
|
||||
@ -78,7 +79,6 @@ char *status;
|
||||
ss_dfprintf(stderr, "\t..done\nFreeing Server.");
|
||||
ss_info_dassert(0 != server_free(server), "Free should succeed");
|
||||
ss_dfprintf(stderr, "\t..done\n");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user