This commit is contained in:
vraatikka
2013-08-21 23:34:56 +03:00
12 changed files with 173 additions and 16 deletions

View File

@ -122,7 +122,10 @@ char uname[80], passwd[80];
if ((fp = fopen(fname, "r")) == NULL) if ((fp = fopen(fname, "r")) == NULL)
return NULL; return NULL;
if ((rval = users_alloc()) == NULL) if ((rval = users_alloc()) == NULL)
{
fclose(fp);
return NULL; return NULL;
}
while (fscanf(fp, "%[^:]:%s\n", uname, passwd) == 2) while (fscanf(fp, "%[^:]:%s\n", uname, passwd) == 2)
{ {
users_add(rval, uname, passwd); users_add(rval, uname, passwd);
@ -280,6 +283,8 @@ char* admin_remove_user(
"Removing user from file failed, and must be done manually.", "Removing user from file failed, and must be done manually.",
fname, fname,
err); err);
fclose(fp_tmp);
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;
} }
@ -303,6 +308,8 @@ char* admin_remove_user(
"done manually.", "done manually.",
fname, fname,
err); err);
fclose(fp_tmp);
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;
} }
} }
@ -318,6 +325,7 @@ char* admin_remove_user(
fname_tmp, fname_tmp,
err, err,
fname); fname);
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS; return ADMIN_ERR_PWDFILEACCESS;
} }

View File

@ -95,6 +95,7 @@ DCB *rval;
rval->data = NULL; rval->data = NULL;
rval->protocol = NULL; rval->protocol = NULL;
rval->session = NULL; rval->session = NULL;
simple_mutex_init(&rval->mutex, "dcb mutex");
memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics
bitmask_init(&rval->memdata.bitmask); bitmask_init(&rval->memdata.bitmask);
rval->memdata.next = NULL; rval->memdata.next = NULL;
@ -342,6 +343,7 @@ GWPROTOCOL *funcs;
int int
dcb_read(DCB *dcb, GWBUF **head) dcb_read(DCB *dcb, GWBUF **head)
{ {
<<<<<<< TREE
GWBUF *buffer = NULL; GWBUF *buffer = NULL;
int b, n = 0; int b, n = 0;
int rc = 0; int rc = 0;
@ -364,6 +366,10 @@ int eno = 0;
return -1; return -1;
} }
=======
GWBUF *buffer = NULL;
int b, n = 0;
>>>>>>> MERGE-SOURCE
while (b > 0) while (b > 0)
{ {
int bufsize = b < MAX_BUFFER_SIZE ? b : MAX_BUFFER_SIZE; int bufsize = b < MAX_BUFFER_SIZE ? b : MAX_BUFFER_SIZE;
@ -376,6 +382,7 @@ int eno = 0;
if (n < 0) if (n < 0)
{ {
gwbuf_free(buffer);
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
{ {
return n; return n;
@ -387,6 +394,7 @@ int eno = 0;
} }
else if (n == 0) else if (n == 0)
{ {
gwbuf_free(buffer);
return n; return n;
} }
@ -470,12 +478,28 @@ int w, saved_errno = 0;
saved_errno = errno; saved_errno = errno;
if (w < 0) if (w < 0)
{ {
<<<<<<< TREE
skygw_log_write( skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [dcb_write] Write to fd %d failed, errno %d", "%lu [dcb_write] Write to fd %d failed, errno %d",
pthread_self(), pthread_self(),
dcb->fd, dcb->fd,
saved_errno); saved_errno);
=======
skygw_log_write(
LOGFILE_ERROR,
"%lu [dcb_write] Write to fd %d failed, errno %d",
pthread_self(),
dcb->fd,
saved_errno);
skygw_log_write(
LOGFILE_TRACE,
"%lu [dcb_write] Write to fd %d failed, errno %d",
pthread_self(),
dcb->fd,
saved_errno);
>>>>>>> MERGE-SOURCE
break; break;
} }
@ -545,6 +569,7 @@ int saved_errno = 0;
saved_errno = errno; saved_errno = errno;
if (w < 0) if (w < 0)
{ {
<<<<<<< TREE
skygw_log_write( skygw_log_write(
LOGFILE_ERROR, LOGFILE_ERROR,
"%lu [dcb_drain_writeq] Write to fd %d failed, " "%lu [dcb_drain_writeq] Write to fd %d failed, "
@ -553,6 +578,24 @@ int saved_errno = 0;
dcb->fd, dcb->fd,
saved_errno); saved_errno);
break; break;
=======
skygw_log_write(
LOGFILE_ERROR,
"%lu [dcb_drain_writeq] Write to fd %d failed, "
"errno %d",
pthread_self(),
dcb->fd,
saved_errno);
skygw_log_write(
LOGFILE_TRACE,
"%lu [dcb_drain_writeq] Write to df %d failed, "
"errno %d",
pthread_self(),
dcb->fd,
saved_errno);
break;
>>>>>>> MERGE-SOURCE
} }
/* /*

View File

@ -106,9 +106,11 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (n < 0) { if (n < 0) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
fprintf(stderr, "Client connection %i: continue for %i, %s\n", dcb->fd, errno, strerror(errno)); fprintf(stderr, "Client connection %i: continue for %i, %s\n", dcb->fd, errno, strerror(errno));
gwbuf_free(buffer);
return 1; return 1;
} else { } else {
fprintf(stderr, "Client connection %i error: %i, %s\n", dcb->fd, errno, strerror(errno));; fprintf(stderr, "Client connection %i error: %i, %s\n", dcb->fd, errno, strerror(errno));;
gwbuf_free(buffer);
(dcb->func).close(dcb); (dcb->func).close(dcb);
return 1; return 1;
} }
@ -117,6 +119,7 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (n == 0) { if (n == 0) {
// socket closed // socket closed
fprintf(stderr, "Client connection %i closed: %i, %s\n", dcb->fd, errno, strerror(errno)); fprintf(stderr, "Client connection %i closed: %i, %s\n", dcb->fd, errno, strerror(errno));
gwbuf_free(buffer);
(dcb->func).close(dcb); (dcb->func).close(dcb);
return 1; return 1;
} }

View File

@ -195,13 +195,28 @@ bool no_op = FALSE;
{ {
DCB *dcb = (DCB *)events[i].data.ptr; DCB *dcb = (DCB *)events[i].data.ptr;
__uint32_t ev = events[i].events; __uint32_t ev = events[i].events;
<<<<<<< TREE
skygw_log_write( skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"%lu [poll_waitevents] event %d", "%lu [poll_waitevents] event %d",
pthread_self(), pthread_self(),
ev); ev);
=======
simple_mutex_t* mutex = &dcb->mutex;
>>>>>>> MERGE-SOURCE
<<<<<<< TREE
=======
simple_mutex_lock(mutex, TRUE);
skygw_log_write(
LOGFILE_TRACE,
"%lu [poll_waitevents] event %d",
pthread_self(),
ev);
>>>>>>> MERGE-SOURCE
if (DCB_ISZOMBIE(dcb)) if (DCB_ISZOMBIE(dcb))
<<<<<<< TREE
{ {
skygw_log_write( skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
@ -209,12 +224,27 @@ bool no_op = FALSE;
pthread_self()); pthread_self());
continue; continue;
} }
=======
{
skygw_log_write(
LOGFILE_TRACE,
"%lu [poll_waitevents] dcb is zombie",
pthread_self());
simple_mutex_unlock(mutex);
continue;
}
>>>>>>> MERGE-SOURCE
if (ev & EPOLLERR) if (ev & EPOLLERR)
{ {
atomic_add(&pollStats.n_error, 1); atomic_add(&pollStats.n_error, 1);
dcb->func.error(dcb); dcb->func.error(dcb);
<<<<<<< TREE
if (DCB_ISZOMBIE(dcb)) { if (DCB_ISZOMBIE(dcb)) {
=======
if (DCB_ISZOMBIE(dcb)) {
simple_mutex_unlock(mutex);
>>>>>>> MERGE-SOURCE
continue; continue;
} }
} }
@ -222,7 +252,12 @@ bool no_op = FALSE;
{ {
atomic_add(&pollStats.n_hup, 1); atomic_add(&pollStats.n_hup, 1);
dcb->func.hangup(dcb); dcb->func.hangup(dcb);
<<<<<<< TREE
if (DCB_ISZOMBIE(dcb)) { if (DCB_ISZOMBIE(dcb)) {
=======
if (DCB_ISZOMBIE(dcb)) {
simple_mutex_unlock(mutex);
>>>>>>> MERGE-SOURCE
continue; continue;
} }
} }
@ -261,8 +296,14 @@ bool no_op = FALSE;
dcb->func.read(dcb); dcb->func.read(dcb);
} }
} }
<<<<<<< TREE
} /**< for */ } /**< for */
no_op = FALSE; no_op = FALSE;
=======
simple_mutex_unlock(mutex);
} /**< for */
no_op = FALSE;
>>>>>>> MERGE-SOURCE
} }
dcb_process_zombies(thread_id); dcb_process_zombies(thread_id);
if (shutdown) if (shutdown)

View File

@ -106,12 +106,14 @@ int fd;
/* read all data from file */ /* read all data from file */
if (read(fd, keys, sizeof(MAXKEYS)) != sizeof(MAXKEYS)) if (read(fd, keys, sizeof(MAXKEYS)) != sizeof(MAXKEYS))
{ {
free(keys);
skygw_log_write( LOGFILE_ERROR, "secrets_readKeys, failed reading from secret file [%s]. Error %i, %s\n", secret_file, errno, strerror(errno)); skygw_log_write( LOGFILE_ERROR, "secrets_readKeys, failed reading from secret file [%s]. Error %i, %s\n", secret_file, errno, strerror(errno));
return NULL; return NULL;
} }
/* Close the file */ /* Close the file */
if (close(fd) < 0) { if (close(fd) < 0) {
free(keys);
skygw_log_write( LOGFILE_ERROR, "secrets_readKeys, failed closing the secret file [%s]. Error %i, %s\n", secret_file, errno, strerror(errno)); skygw_log_write( LOGFILE_ERROR, "secrets_readKeys, failed closing the secret file [%s]. Error %i, %s\n", secret_file, errno, strerror(errno));
return NULL; return NULL;
} }
@ -188,14 +190,22 @@ int enlen;
return strdup(crypt); return strdup(crypt);
/* If the input is not a HEX string return the input - it probably was not encrypted */ /* If the input is not a HEX string return the input - it probably was not encrypted */
for (ptr = crypt; *ptr; ptr++) for (ptr = crypt; *ptr; ptr++)
{
if (!isxdigit(*ptr)) if (!isxdigit(*ptr))
{
free(keys);
return strdup(crypt); return strdup(crypt);
}
}
enlen = strlen(crypt) / 2; enlen = strlen(crypt) / 2;
gw_hex2bin(encrypted, crypt, strlen(crypt)); gw_hex2bin(encrypted, crypt, strlen(crypt));
if ((plain = (unsigned char *)malloc(80)) == NULL) if ((plain = (unsigned char *)malloc(80)) == NULL)
{
free(keys);
return NULL; return NULL;
}
AES_set_decrypt_key(keys->enckey, 8 * MAXSCALE_KEYLEN, &aeskey); AES_set_decrypt_key(keys->enckey, 8 * MAXSCALE_KEYLEN, &aeskey);

View File

@ -182,6 +182,7 @@ void
dprintAllServers(DCB *dcb) dprintAllServers(DCB *dcb)
{ {
SERVER *ptr; SERVER *ptr;
char *stat;
spinlock_acquire(&server_spin); spinlock_acquire(&server_spin);
ptr = allServers; ptr = allServers;
@ -189,7 +190,9 @@ SERVER *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, "\tStatus: %s\n", server_status(ptr)); stat = server_status(ptr);
dcb_printf(dcb, "\tStatus: %s\n", stat);
free(stat);
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);
dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections); dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections);
@ -208,9 +211,13 @@ SERVER *ptr;
void void
dprintServer(DCB *dcb, SERVER *server) dprintServer(DCB *dcb, SERVER *server)
{ {
char *stat;
dcb_printf(dcb, "Server %p\n", server); dcb_printf(dcb, "Server %p\n", server);
dcb_printf(dcb, "\tServer: %s\n", server->name); dcb_printf(dcb, "\tServer: %s\n", server->name);
dcb_printf(dcb, "\tStatus: %s\n", server_status(server)); stat = server_status(server);
dcb_printf(dcb, "\tStatus: %s\n", stat);
free(stat);
dcb_printf(dcb, "\tProtocol: %s\n", server->protocol); dcb_printf(dcb, "\tProtocol: %s\n", server->protocol);
dcb_printf(dcb, "\tPort: %d\n", server->port); dcb_printf(dcb, "\tPort: %d\n", server->port);
dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections); dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections);

View File

@ -134,6 +134,7 @@ typedef struct {
* gateway may be selected to execute the required actions when a network event occurs. * gateway may be selected to execute the required actions when a network event occurs.
*/ */
typedef struct dcb { typedef struct dcb {
simple_mutex_t mutex; /**< Protects dcb processing. Coarse and temporary? */
int fd; /**< The descriptor */ int fd; /**< The descriptor */
int state; /**< Current descriptor state */ int state; /**< Current descriptor state */
char *remote; /**< Address of remote end */ char *remote; /**< Address of remote end */

View File

@ -34,7 +34,7 @@ LDFLAGS=-shared -L$(LOGPATH) -Wl,-rpath,$(DEST)/lib \
MYSQLSRCS=mysql_mon.c MYSQLSRCS=mysql_mon.c
MYSQLOBJ=$(MYSQLSRCS:.c=.o) MYSQLOBJ=$(MYSQLSRCS:.c=.o)
GALERASRCS=mysql_mon.c GALERASRCS=galera_mon.c
GALERAOBJ=$(GALERASRCS:.c=.o) GALERAOBJ=$(GALERASRCS:.c=.o)
SRCS=$(MYSQLSRCS) SRCS=$(MYSQLSRCS)
OBJ=$(SRCS:.c=.o) OBJ=$(SRCS:.c=.o)

View File

@ -50,9 +50,9 @@ static void stopMonitor(void *);
static void registerServer(void *, SERVER *); static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *); static void unregisterServer(void *, SERVER *);
static void defaultUsers(void *, char *, char *); static void defaultUsers(void *, char *, char *);
static void daignostics(DCB *, void *); static void diagnostics(DCB *, void *);
static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUser, daignostics }; static MONITOR_OBJECT MyObject = { startMonitor, stopMonitor, registerServer, unregisterServer, defaultUsers, diagnostics };
/** /**
* Implementation of the mandatory version entry point * Implementation of the mandatory version entry point
@ -114,7 +114,7 @@ MYSQL_MONITOR *handle;
handle->databases = NULL; handle->databases = NULL;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->deaultPasswd = NULL; handle->defaultPasswd = NULL;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
handle->tid = thread_start(monitorMain, handle); handle->tid = thread_start(monitorMain, handle);
@ -212,7 +212,7 @@ MONITOR_SERVERS *ptr, *lptr;
* @param arg The monitor handle * @param arg The monitor handle
*/ */
static void static void
diagnostics(DCB *dcbm void *handle) diagnostics(DCB *dcb, void *arg)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *db; MONITOR_SERVERS *db;
@ -251,7 +251,7 @@ char *sep;
* @param passwd The default password * @param passwd The default password
*/ */
static void static void
defaultUser(void *arg, char *uname, char *passwd) defaultUsers(void *arg, char *uname, char *passwd)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;

View File

@ -488,6 +488,7 @@ int gw_read_client_event(DCB* dcb) {
ROUTER_OBJECT *router = NULL; ROUTER_OBJECT *router = NULL;
ROUTER *router_instance = NULL; ROUTER *router_instance = NULL;
void *rsession = NULL; void *rsession = NULL;
<<<<<<< TREE
MySQLProtocol *protocol = NULL; MySQLProtocol *protocol = NULL;
int b = -1; int b = -1;
@ -500,12 +501,17 @@ int gw_read_client_event(DCB* dcb) {
spinlock_release(&dcb->writeqlock); spinlock_release(&dcb->writeqlock);
return 1; return 1;
} }
=======
MySQLProtocol *protocol = NULL;
int b = -1;
>>>>>>> MERGE-SOURCE
if (dcb) { if (dcb) {
protocol = DCB_PROTOCOL(dcb, MySQLProtocol); protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
} }
if (ioctl(dcb->fd, FIONREAD, &b)) { if (ioctl(dcb->fd, FIONREAD, &b)) {
<<<<<<< TREE
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write( skygw_log_write(
@ -520,6 +526,27 @@ int gw_read_client_event(DCB* dcb) {
spinlock_release(&dcb->writeqlock); spinlock_release(&dcb->writeqlock);
return 1; return 1;
=======
int eno = errno;
errno = 0;
skygw_log_write(
LOGFILE_ERROR,
"%lu [gw_read_client_event] Setting FIONREAD for %d failed. "
"errno %d, %s",
pthread_self(),
dcb->fd,
eno ,
strerror(eno));
skygw_log_write(
LOGFILE_TRACE,
"%lu [gw_read_client_event] Setting FIONREAD for %d failed. "
"errno %d, %s",
pthread_self(),
dcb->fd,
eno ,
strerror(eno));
return 1;
>>>>>>> MERGE-SOURCE
} else { } else {
//fprintf(stderr, "Client IOCTL FIONREAD bytes to read = %i\n", b); //fprintf(stderr, "Client IOCTL FIONREAD bytes to read = %i\n", b);
} }

View File

@ -34,6 +34,8 @@
#include <gw.h> #include <gw.h>
#include <telnetd.h> #include <telnetd.h>
#include <adminusers.h> #include <adminusers.h>
#include <skygw_utils.h>
#include <log_manager.h>
/** /**
* @file telnetd.c - telnet daemon protocol module * @file telnetd.c - telnet daemon protocol module
@ -105,7 +107,7 @@ version()
void void
ModuleInit() ModuleInit()
{ {
fprintf(stderr, "Initialise Telnetd Protocol module.\n"); skygw_log_write(LOGFILE_TRACE, "Initialise Telnetd Protocol module.\n");
} }
/** /**
@ -147,7 +149,7 @@ char *password, *t;
{ {
unsigned char *ptr = GWBUF_DATA(head); unsigned char *ptr = GWBUF_DATA(head);
ptr = GWBUF_DATA(head); ptr = GWBUF_DATA(head);
while (*ptr == TELNET_IAC) while (GWBUF_LENGTH(head) && *ptr == TELNET_IAC)
{ {
telnetd_command(dcb, ptr + 1); telnetd_command(dcb, ptr + 1);
GWBUF_CONSUME(head, 3); GWBUF_CONSUME(head, 3);
@ -289,6 +291,7 @@ int n_connect = 0;
n_connect++; n_connect++;
((TELNETD *)(client->protocol))->state = TELNETD_STATE_LOGIN; ((TELNETD *)(client->protocol))->state = TELNETD_STATE_LOGIN;
((TELNETD *)(client->protocol))->username = NULL;
dcb_printf(client, "MaxScale login: "); dcb_printf(client, "MaxScale login: ");
client->state = DCB_STATE_POLLING; client->state = DCB_STATE_POLLING;
} }
@ -306,6 +309,11 @@ int n_connect = 0;
static int static int
telnetd_close(DCB *dcb) telnetd_close(DCB *dcb)
{ {
TELNETD *telnetd = dcb->protocol;
if (telnetd && telnetd->username)
free(telnetd->username);
dcb_close(dcb); dcb_close(dcb);
return 0; return 0;
} }

View File

@ -264,6 +264,15 @@ static void* newSession(
} }
} /* for */ } /* for */
if (candidate == NULL)
{
skygw_log_write_flush(LOGFILE_MESSAGE,
"No suitable servers found for connection.");
free(client);
return NULL;
}
if (inst->master == NULL) { if (inst->master == NULL) {
inst->master = inst->servers[i-1]; inst->master = inst->servers[i-1];
} }