This commit is contained in:
vraatikka 2013-08-21 23:34:56 +03:00
commit 76f31b6b08
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)
return NULL;
if ((rval = users_alloc()) == NULL)
{
fclose(fp);
return NULL;
}
while (fscanf(fp, "%[^:]:%s\n", uname, passwd) == 2)
{
users_add(rval, uname, passwd);
@ -274,13 +277,15 @@ char* admin_remove_user(
* Scan passwd and copy all but matching lines to temp file.
*/
if (fgetpos(fp, &rpos) != 0) {
int err = errno;
skygw_log_write( LOGFILE_ERROR,
int err = errno;
skygw_log_write( LOGFILE_ERROR,
"Unable to process passwd file %s : errno %d.\n"
"Removing user from file failed, and must be done manually.",
fname,
err);
return ADMIN_ERR_PWDFILEACCESS;
fclose(fp_tmp);
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS;
}
while (fscanf(fp, "%[^:]:%s\n", fusr, fpwd) == 2)
@ -303,6 +308,8 @@ char* admin_remove_user(
"done manually.",
fname,
err);
fclose(fp_tmp);
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS;
}
}
@ -311,14 +318,15 @@ char* admin_remove_user(
* Replace original passwd file with new.
*/
if (rename(fname_tmp, fname)) {
int err = errno;
skygw_log_write( LOGFILE_ERROR,
int err = errno;
skygw_log_write( LOGFILE_ERROR,
"Unable to rename new passwd file %s : errno %d.\n"
"Rename it to %s manually.",
fname_tmp,
err,
fname);
return ADMIN_ERR_PWDFILEACCESS;
unlink(fname_tmp);
return ADMIN_ERR_PWDFILEACCESS;
}
fclose(fp_tmp);

View File

@ -95,6 +95,7 @@ DCB *rval;
rval->data = NULL;
rval->protocol = NULL;
rval->session = NULL;
simple_mutex_init(&rval->mutex, "dcb mutex");
memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics
bitmask_init(&rval->memdata.bitmask);
rval->memdata.next = NULL;
@ -342,6 +343,7 @@ GWPROTOCOL *funcs;
int
dcb_read(DCB *dcb, GWBUF **head)
{
<<<<<<< TREE
GWBUF *buffer = NULL;
int b, n = 0;
int rc = 0;
@ -364,6 +366,10 @@ int eno = 0;
return -1;
}
=======
GWBUF *buffer = NULL;
int b, n = 0;
>>>>>>> MERGE-SOURCE
while (b > 0)
{
int bufsize = b < MAX_BUFFER_SIZE ? b : MAX_BUFFER_SIZE;
@ -376,6 +382,7 @@ int eno = 0;
if (n < 0)
{
gwbuf_free(buffer);
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
{
return n;
@ -387,6 +394,7 @@ int eno = 0;
}
else if (n == 0)
{
gwbuf_free(buffer);
return n;
}
@ -470,12 +478,28 @@ int w, saved_errno = 0;
saved_errno = errno;
if (w < 0)
{
<<<<<<< TREE
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_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;
}
@ -545,6 +569,7 @@ int saved_errno = 0;
saved_errno = errno;
if (w < 0)
{
<<<<<<< TREE
skygw_log_write(
LOGFILE_ERROR,
"%lu [dcb_drain_writeq] Write to fd %d failed, "
@ -553,6 +578,24 @@ int saved_errno = 0;
dcb->fd,
saved_errno);
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 ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
fprintf(stderr, "Client connection %i: continue for %i, %s\n", dcb->fd, errno, strerror(errno));
gwbuf_free(buffer);
return 1;
} else {
fprintf(stderr, "Client connection %i error: %i, %s\n", dcb->fd, errno, strerror(errno));;
gwbuf_free(buffer);
(dcb->func).close(dcb);
return 1;
}
@ -117,6 +119,7 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (n == 0) {
// socket closed
fprintf(stderr, "Client connection %i closed: %i, %s\n", dcb->fd, errno, strerror(errno));
gwbuf_free(buffer);
(dcb->func).close(dcb);
return 1;
}

View File

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

View File

@ -106,12 +106,14 @@ int fd;
/* read all data from file */
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));
return NULL;
}
/* Close the file */
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));
return NULL;
}
@ -188,14 +190,22 @@ int enlen;
return strdup(crypt);
/* If the input is not a HEX string return the input - it probably was not encrypted */
for (ptr = crypt; *ptr; ptr++)
{
if (!isxdigit(*ptr))
{
free(keys);
return strdup(crypt);
}
}
enlen = strlen(crypt) / 2;
gw_hex2bin(encrypted, crypt, strlen(crypt));
if ((plain = (unsigned char *)malloc(80)) == NULL)
{
free(keys);
return NULL;
}
AES_set_decrypt_key(keys->enckey, 8 * MAXSCALE_KEYLEN, &aeskey);

View File

@ -182,6 +182,7 @@ void
dprintAllServers(DCB *dcb)
{
SERVER *ptr;
char *stat;
spinlock_acquire(&server_spin);
ptr = allServers;
@ -189,7 +190,9 @@ SERVER *ptr;
{
dcb_printf(dcb, "Server %p\n", ptr);
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, "\tPort: %d\n", ptr->port);
dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections);
@ -208,9 +211,13 @@ SERVER *ptr;
void
dprintServer(DCB *dcb, SERVER *server)
{
char *stat;
dcb_printf(dcb, "Server %p\n", server);
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, "\tPort: %d\n", server->port);
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.
*/
typedef struct dcb {
simple_mutex_t mutex; /**< Protects dcb processing. Coarse and temporary? */
int fd; /**< The descriptor */
int state; /**< Current descriptor state */
char *remote; /**< Address of remote end */

View File

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

View File

@ -50,9 +50,9 @@ static void stopMonitor(void *);
static void registerServer(void *, SERVER *);
static void unregisterServer(void *, SERVER *);
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
@ -114,7 +114,7 @@ MYSQL_MONITOR *handle;
handle->databases = NULL;
handle->shutdown = 0;
handle->defaultUser = NULL;
handle->deaultPasswd = NULL;
handle->defaultPasswd = NULL;
spinlock_init(&handle->lock);
}
handle->tid = thread_start(monitorMain, handle);
@ -212,7 +212,7 @@ MONITOR_SERVERS *ptr, *lptr;
* @param arg The monitor handle
*/
static void
diagnostics(DCB *dcbm void *handle)
diagnostics(DCB *dcb, void *arg)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
MONITOR_SERVERS *db;
@ -251,7 +251,7 @@ char *sep;
* @param passwd The default password
*/
static void
defaultUser(void *arg, char *uname, char *passwd)
defaultUsers(void *arg, char *uname, char *passwd)
{
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;

View File

@ -488,6 +488,7 @@ int gw_read_client_event(DCB* dcb) {
ROUTER_OBJECT *router = NULL;
ROUTER *router_instance = NULL;
void *rsession = NULL;
<<<<<<< TREE
MySQLProtocol *protocol = NULL;
int b = -1;
@ -500,12 +501,17 @@ int gw_read_client_event(DCB* dcb) {
spinlock_release(&dcb->writeqlock);
return 1;
}
=======
MySQLProtocol *protocol = NULL;
int b = -1;
>>>>>>> MERGE-SOURCE
if (dcb) {
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
}
if (ioctl(dcb->fd, FIONREAD, &b)) {
<<<<<<< TREE
int eno = errno;
errno = 0;
skygw_log_write(
@ -520,6 +526,27 @@ int gw_read_client_event(DCB* dcb) {
spinlock_release(&dcb->writeqlock);
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 {
//fprintf(stderr, "Client IOCTL FIONREAD bytes to read = %i\n", b);
}

View File

@ -34,6 +34,8 @@
#include <gw.h>
#include <telnetd.h>
#include <adminusers.h>
#include <skygw_utils.h>
#include <log_manager.h>
/**
* @file telnetd.c - telnet daemon protocol module
@ -105,7 +107,7 @@ version()
void
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);
ptr = GWBUF_DATA(head);
while (*ptr == TELNET_IAC)
while (GWBUF_LENGTH(head) && *ptr == TELNET_IAC)
{
telnetd_command(dcb, ptr + 1);
GWBUF_CONSUME(head, 3);
@ -289,6 +291,7 @@ int n_connect = 0;
n_connect++;
((TELNETD *)(client->protocol))->state = TELNETD_STATE_LOGIN;
((TELNETD *)(client->protocol))->username = NULL;
dcb_printf(client, "MaxScale login: ");
client->state = DCB_STATE_POLLING;
}
@ -306,6 +309,11 @@ int n_connect = 0;
static int
telnetd_close(DCB *dcb)
{
TELNETD *telnetd = dcb->protocol;
if (telnetd && telnetd->username)
free(telnetd->username);
dcb_close(dcb);
return 0;
}

View File

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