This commit is contained in:
Mark Riddoch
2015-02-16 09:21:38 +00:00
16 changed files with 160 additions and 168 deletions

View File

@ -40,8 +40,8 @@ configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY
configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst) configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst)
configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm) configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm)
set(CMAKE_C_FLAGS "-Wall -fPIC") set(CMAKE_C_FLAGS "-Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -fPIC")
set(CMAKE_CXX_FLAGS "-Wall -fPIC") set(CMAKE_CXX_FLAGS "-Wall -Wno-unused-variable -Wno-unused-but-set-variable -fPIC")
set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4") set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4")
if(CMAKE_VERSION VERSION_GREATER 2.6) if(CMAKE_VERSION VERSION_GREATER 2.6)

View File

@ -167,7 +167,7 @@ struct logfile_st {
size_t lf_file_size; size_t lf_file_size;
/** list of block-sized log buffers */ /** list of block-sized log buffers */
mlist_t lf_blockbuf_list; mlist_t lf_blockbuf_list;
int lf_buf_size; size_t lf_buf_size;
bool lf_flushflag; bool lf_flushflag;
bool lf_rotateflag; bool lf_rotateflag;
int lf_spinlock; /**< lf_flushflag & lf_rotateflag */ int lf_spinlock; /**< lf_flushflag & lf_rotateflag */
@ -633,7 +633,7 @@ static int logmanager_write_log(
int err = 0; int err = 0;
blockbuf_t* bb; blockbuf_t* bb;
blockbuf_t* bb_c; blockbuf_t* bb_c;
int timestamp_len; size_t timestamp_len;
int i; int i;
CHK_LOGMANAGER(lm); CHK_LOGMANAGER(lm);
@ -680,9 +680,9 @@ static int logmanager_write_log(
else else
{ {
/** Length of string that will be written, limited by bufsize */ /** Length of string that will be written, limited by bufsize */
int safe_str_len; size_t safe_str_len;
/** Length of session id */ /** Length of session id */
int sesid_str_len; size_t sesid_str_len;
/** /**
* 2 braces, 2 spaces and terminating char * 2 braces, 2 spaces and terminating char
@ -2335,7 +2335,6 @@ static bool check_file_and_path(
bool* writable, bool* writable,
bool do_log) bool do_log)
{ {
int fd;
bool exists; bool exists;
if (filename == NULL) if (filename == NULL)
@ -2349,112 +2348,54 @@ static bool check_file_and_path(
} }
else else
{ {
fd = open(filename, O_CREAT|O_EXCL, S_IRWXU); if(access(filename,F_OK) == 0)
{
if (fd == -1) exists = true;
{
/** File exists, check permission to read/write */
if (errno == EEXIST)
{
/** Open file and write a byte for test */
fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG);
if (fd == -1) if(access(filename,W_OK) == 0)
{ {
if (do_log && file_is_symlink(filename)) if(writable)
{ {
fprintf(stderr, *writable = true;
"*\n* Error : Can't access " }
"file pointed to by %s due " }
"to %s.\n", else
filename, {
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't access %s due "
"to %s.\n",
filename,
strerror(errno));
}
if (writable)
{
*writable = false;
}
}
else
{
if (writable)
{
char c = ' ';
if (write(fd, &c, 1) == 1)
{
*writable = true;
}
else
{
if (do_log &&
file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't write to "
"file pointed to by %s due to "
"%s.\n",
filename,
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't write to "
"%s due to %s.\n",
filename,
strerror(errno));
}
*writable = false;
}
}
close(fd);
}
exists = true;
}
else
{
if (do_log && file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't access the file "
"pointed to by %s due to %s.\n",
filename,
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't access %s due to %s.\n",
filename,
strerror(errno));
}
exists = false;
if (writable) if (do_log && file_is_symlink(filename))
{ {
*writable = false; fprintf(stderr,
} "*\n* Error : Can't access "
} "file pointed to by %s due "
} "to %s.\n",
else filename,
{ strerror(errno));
close(fd); }
unlink(filename); else if (do_log)
exists = false; {
fprintf(stderr,
"*\n* Error : Can't access %s due "
"to %s.\n",
filename,
strerror(errno));
}
if (writable) if(writable)
{ {
*writable = true; *writable = false;
} }
} }
}
else
{
exists = false;
if(writable)
{
*writable = true;
}
}
} }
return exists; return exists;
} }

View File

@ -1253,7 +1253,7 @@ char* skygw_get_affected_fields(GWBUF* buf)
List_iterator<Item> ilist(lex->current_select->item_list); List_iterator<Item> ilist(lex->current_select->item_list);
item = (Item*)ilist.next(); item = (Item*)ilist.next();
for (item; item != NULL; item=(Item*)ilist.next()) for (; item != NULL; item=(Item*)ilist.next())
{ {
itype = item->type(); itype = item->type();
@ -1572,7 +1572,7 @@ char* skygw_get_qtype_str(
skygw_query_op_t query_classifier_get_operation(GWBUF* querybuf) skygw_query_op_t query_classifier_get_operation(GWBUF* querybuf)
{ {
LEX* lex = get_lex(querybuf); LEX* lex = get_lex(querybuf);
skygw_query_op_t operation; skygw_query_op_t operation = QUERY_OP_UNDEFINED;
if(lex){ if(lex){
switch(lex->sql_command){ switch(lex->sql_command){
case SQLCOM_SELECT: case SQLCOM_SELECT:

View File

@ -158,6 +158,7 @@ int sendMessage(MYSQL* server, amqp_message_t* msg)
(int)((msg->properties.correlation_id.len + 1)*2+1) + (int)((msg->properties.correlation_id.len + 1)*2+1) +
strlen(DB_INSERT), strlen(DB_INSERT),
rval = 0; rval = 0;
char* saved;
char *qstr = calloc(buffsz,sizeof(char)), char *qstr = calloc(buffsz,sizeof(char)),
*rawmsg = calloc((msg->body.len + 1),sizeof(char)), *rawmsg = calloc((msg->body.len + 1),sizeof(char)),
*clnmsg = calloc(((msg->body.len + 1)*2+1),sizeof(char)), *clnmsg = calloc(((msg->body.len + 1)*2+1),sizeof(char)),
@ -170,9 +171,9 @@ int sendMessage(MYSQL* server, amqp_message_t* msg)
sprintf(qstr,"%.*s",(int)msg->body.len,(char *)msg->body.bytes); sprintf(qstr,"%.*s",(int)msg->body.len,(char *)msg->body.bytes);
fprintf(out_fd,"Received: %s\n",qstr); fprintf(out_fd,"Received: %s\n",qstr);
char *ptr = strtok(qstr,"|"); char *ptr = strtok_r(qstr,"|",&saved);
sprintf(rawdate,"%s",ptr); sprintf(rawdate,"%s",ptr);
ptr = strtok(NULL,"\n\0"); ptr = strtok_r(NULL,"\n\0",&saved);
if(ptr == NULL){ if(ptr == NULL){
fprintf(out_fd,"Message content not valid.\n"); fprintf(out_fd,"Message content not valid.\n");
rval = 1; rval = 1;

View File

@ -991,7 +991,7 @@ static void usage(void)
" -f|--config=... relative|absolute pathname of MaxScale configuration file\n" " -f|--config=... relative|absolute pathname of MaxScale configuration file\n"
" (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n" " (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n"
" -l|--log=... log to file or shared memory\n" " -l|--log=... log to file or shared memory\n"
" -lfile or -lshm - defaults to shared memory\n" " -lfile or -lshm - defaults to file\n"
" -v|--version print version info and exit\n" " -v|--version print version info and exit\n"
" -?|--help show this help\n" " -?|--help show this help\n"
, progname); , progname);
@ -1039,6 +1039,7 @@ int main(int argc, char **argv)
int l; int l;
int i; int i;
int n; int n;
intptr_t thread_id;
int n_threads; /*< number of epoll listener threads */ int n_threads; /*< number of epoll listener threads */
int n_services; int n_services;
int eno = 0; /*< local variable for errno */ int eno = 0; /*< local variable for errno */
@ -1052,7 +1053,7 @@ int main(int argc, char **argv)
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */ char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
void* log_flush_thr = NULL; void* log_flush_thr = NULL;
int option_index; int option_index;
int logtofile = 0; /* Use shared memory or file */ int logtofile = 1; /* Use shared memory or file */
ssize_t log_flush_timeout_ms = 0; ssize_t log_flush_timeout_ms = 0;
sigset_t sigset; sigset_t sigset;
sigset_t sigpipe_mask; sigset_t sigpipe_mask;
@ -1788,9 +1789,9 @@ int main(int argc, char **argv)
/*< /*<
* Start server threads. * Start server threads.
*/ */
for (n = 0; n < n_threads - 1; n++) for (thread_id = 0; thread_id < n_threads - 1; thread_id++)
{ {
threads[n] = thread_start(poll_waitevents, (void *)(n + 1)); threads[thread_id] = thread_start(poll_waitevents, (void *)(thread_id + 1));
} }
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE, LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"MaxScale started with %d server threads.", "MaxScale started with %d server threads.",
@ -1803,9 +1804,9 @@ int main(int argc, char **argv)
/*< /*<
* Wait server threads' completion. * Wait server threads' completion.
*/ */
for (n = 0; n < n_threads - 1; n++) for (thread_id = 0; thread_id < n_threads - 1; thread_id++)
{ {
thread_wait(threads[n]); thread_wait(threads[thread_id]);
} }
/*< /*<
* Wait the flush thread. * Wait the flush thread.

View File

@ -678,12 +678,14 @@ void *key, *value;
if (!(*keywrite)(fd, key)) if (!(*keywrite)(fd, key))
{ {
close(fd); close(fd);
hashtable_iterator_free(iter);
return -1; return -1;
} }
if ((value = hashtable_fetch(table, key)) == NULL || if ((value = hashtable_fetch(table, key)) == NULL ||
(*valuewrite)(fd, value) == 0) (*valuewrite)(fd, value) == 0)
{ {
close(fd); close(fd);
hashtable_iterator_free(iter);
return -1; return -1;
} }
rval++; rval++;
@ -691,10 +693,13 @@ void *key, *value;
} }
/* Now go back and write the count of entries */ /* Now go back and write the count of entries */
lseek(fd, 7L, SEEK_SET); if(lseek(fd, 7L, SEEK_SET) != -1)
write(fd, &rval, sizeof(rval)); {
write(fd, &rval, sizeof(rval));
}
close(fd); close(fd);
hashtable_iterator_free(iter);
return rval; return rval;
} }

View File

@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include <secrets.h> #include <secrets.h>
main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc != 2) if (argc != 2)
{ {

View File

@ -28,10 +28,12 @@
* @endverbatim * @endverbatim
*/ */
#include <memlog.h> #include <memlog.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
static MEMLOG *memlogs = NULL; static MEMLOG *memlogs = NULL;
static SPINLOCK *memlock = SPINLOCK_INIT; static SPINLOCK memlock = SPINLOCK_INIT;
/** /**
* Create a new instance of a memory logger. * Create a new instance of a memory logger.

View File

@ -237,7 +237,7 @@ char *
modutil_get_SQL(GWBUF *buf) modutil_get_SQL(GWBUF *buf)
{ {
unsigned int len, length; unsigned int len, length;
unsigned char *ptr, *dptr, *rval = NULL; char *ptr, *dptr, *rval = NULL;
if (!modutil_is_SQL(buf)) if (!modutil_is_SQL(buf))
return rval; return rval;

View File

@ -437,7 +437,7 @@ poll_waitevents(void *arg)
{ {
struct epoll_event events[MAX_EVENTS]; struct epoll_event events[MAX_EVENTS];
int i, nfds, timeout_bias = 1; int i, nfds, timeout_bias = 1;
int thread_id = (int)arg; intptr_t thread_id = (intptr_t)arg;
DCB *zombies = NULL; DCB *zombies = NULL;
int poll_spins = 0; int poll_spins = 0;

View File

@ -221,7 +221,7 @@ GWPROTOCOL *funcs;
{ {
/* Try loading authentication data from file cache */ /* Try loading authentication data from file cache */
char *ptr, path[4096]; char *ptr, path[4097];
strcpy(path, "/usr/local/skysql/MaxScale"); strcpy(path, "/usr/local/skysql/MaxScale");
if ((ptr = getenv("MAXSCALE_HOME")) != NULL) if ((ptr = getenv("MAXSCALE_HOME")) != NULL)
{ {
@ -251,6 +251,7 @@ GWPROTOCOL *funcs;
{ {
/* Save authentication data to file cache */ /* Save authentication data to file cache */
char *ptr, path[4096]; char *ptr, path[4096];
int mkdir_rval = 0;
strcpy(path, "/usr/local/skysql/MaxScale"); strcpy(path, "/usr/local/skysql/MaxScale");
if ((ptr = getenv("MAXSCALE_HOME")) != NULL) if ((ptr = getenv("MAXSCALE_HOME")) != NULL)
{ {
@ -259,10 +260,33 @@ GWPROTOCOL *funcs;
strncat(path, "/", 4096); strncat(path, "/", 4096);
strncat(path, service->name, 4096); strncat(path, service->name, 4096);
if (access(path, R_OK) == -1) if (access(path, R_OK) == -1)
mkdir(path, 0777); {
mkdir_rval = mkdir(path, 0777);
}
if(mkdir_rval)
{
skygw_log_write(LOGFILE_ERROR,"Error : Failed to create directory '%s': [%d] %s",
path,
errno,
strerror(errno));
mkdir_rval = 0;
}
strncat(path, "/.cache", 4096); strncat(path, "/.cache", 4096);
if (access(path, R_OK) == -1) if (access(path, R_OK) == -1)
mkdir(path, 0777); {
mkdir_rval = mkdir(path, 0777);
}
if(mkdir_rval)
{
skygw_log_write(LOGFILE_ERROR,"Error : Failed to create directory '%s': [%d] %s",
path,
errno,
strerror(errno));
mkdir_rval = 0;
}
strncat(path, "/dbusers", 4096); strncat(path, "/dbusers", 4096);
dbusers_save(service->users, path); dbusers_save(service->users, path);
} }

View File

@ -637,8 +637,9 @@ void link_rules(char* rule, FW_INSTANCE* instance)
/**Apply rules to users*/ /**Apply rules to users*/
bool match_any; bool match_any = true;
char *tok, *ruleptr, *userptr, *modeptr; char *tok, *ruleptr, *userptr, *modeptr;
char *saveptr = NULL;
RULELIST* rulelist = NULL; RULELIST* rulelist = NULL;
userptr = strstr(rule,"users "); userptr = strstr(rule,"users ");
@ -654,9 +655,9 @@ void link_rules(char* rule, FW_INSTANCE* instance)
*modeptr++ = '\0'; *modeptr++ = '\0';
*ruleptr++ = '\0'; *ruleptr++ = '\0';
tok = strtok(modeptr," "); tok = strtok_r(modeptr," ",&saveptr);
if(strcmp(tok,"match") == 0){ if(tok && strcmp(tok,"match") == 0){
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
if(strcmp(tok,"any") == 0){ if(strcmp(tok,"any") == 0){
match_any = true; match_any = true;
}else if(strcmp(tok,"all") == 0){ }else if(strcmp(tok,"all") == 0){
@ -667,8 +668,8 @@ void link_rules(char* rule, FW_INSTANCE* instance)
} }
} }
tok = strtok(ruleptr," "); tok = strtok_r(ruleptr," ",&saveptr);
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
while(tok) while(tok)
{ {
@ -682,7 +683,7 @@ void link_rules(char* rule, FW_INSTANCE* instance)
rulelist = tmp_rl; rulelist = tmp_rl;
} }
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
} }
/** /**
@ -690,8 +691,8 @@ void link_rules(char* rule, FW_INSTANCE* instance)
*/ */
*(ruleptr) = '\0'; *(ruleptr) = '\0';
userptr = strtok(rule," "); userptr = strtok_r(rule," ",&saveptr);
userptr = strtok(NULL," "); userptr = strtok_r(NULL," ",&saveptr);
while(userptr) while(userptr)
{ {
@ -738,10 +739,16 @@ void link_rules(char* rule, FW_INSTANCE* instance)
(void *)userptr, (void *)userptr,
(void *)user); (void *)user);
userptr = strtok(NULL," "); userptr = strtok_r(NULL," ",&saveptr);
} }
while(rulelist)
{
RULELIST *tmp = rulelist;
rulelist = rulelist->next;
free(tmp);
}
} }
@ -755,7 +762,8 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
ss_dassert(rule != NULL && instance != NULL); ss_dassert(rule != NULL && instance != NULL);
char *rulecpy = strdup(rule); char *rulecpy = strdup(rule);
char *tok = strtok(rulecpy," ,"); char *saveptr = NULL;
char *tok = strtok_r(rulecpy," ,",&saveptr);
bool allow,deny,mode; bool allow,deny,mode;
RULE* ruledef = NULL; RULE* ruledef = NULL;
@ -763,7 +771,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
if(strcmp("rule",tok) == 0){ /**Define a new rule*/ if(strcmp("rule",tok) == 0){ /**Define a new rule*/
tok = strtok(NULL," ,"); tok = strtok_r(NULL," ,",&saveptr);
if(tok == NULL) goto retblock; if(tok == NULL) goto retblock;
@ -798,8 +806,13 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
add_users(rule, instance); add_users(rule, instance);
goto retblock; goto retblock;
} }
else
{
skygw_log_write(LOGFILE_ERROR,"Error : Unknown token in rule file: %s",tok);
goto retblock;
}
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
if((allow = (strcmp(tok,"allow") == 0)) || if((allow = (strcmp(tok,"allow") == 0)) ||
@ -808,7 +821,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
mode = allow ? true:false; mode = allow ? true:false;
ruledef->allow = mode; ruledef->allow = mode;
ruledef->type = RT_PERMISSION; ruledef->type = RT_PERMISSION;
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
while(tok){ while(tok){
@ -820,13 +833,13 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
{ {
STRLINK *tail = NULL,*current; STRLINK *tail = NULL,*current;
ruledef->type = RT_COLUMN; ruledef->type = RT_COLUMN;
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
while(tok && strcmp(tok,"at_times") != 0){ while(tok && strcmp(tok,"at_times") != 0){
current = malloc(sizeof(STRLINK)); current = malloc(sizeof(STRLINK));
current->value = strdup(tok); current->value = strdup(tok);
current->next = tail; current->next = tail;
tail = current; tail = current;
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
} }
ruledef->data = (void*)tail; ruledef->data = (void*)tail;
@ -836,7 +849,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
else if(strcmp(tok,"at_times") == 0) else if(strcmp(tok,"at_times") == 0)
{ {
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
TIMERANGE *tr = NULL; TIMERANGE *tr = NULL;
while(tok){ while(tok){
TIMERANGE *tmp = parse_time(tok,instance); TIMERANGE *tmp = parse_time(tok,instance);
@ -846,7 +859,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
} }
tmp->next = tr; tmp->next = tr;
tr = tmp; tr = tmp;
tok = strtok(NULL, " ,"); tok = strtok_r(NULL, " ,",&saveptr);
} }
ruledef->active = tr; ruledef->active = tr;
} }
@ -855,7 +868,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
bool escaped = false; bool escaped = false;
regex_t *re; regex_t *re;
char* start, *str; char* start, *str;
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
char delim = '\''; char delim = '\'';
while(*tok == '\'' || *tok == '"'){ while(*tok == '\'' || *tok == '"'){
delim = *tok; delim = *tok;
@ -914,20 +927,20 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
qs->id = ++instance->idgen; qs->id = ++instance->idgen;
spinlock_release(instance->lock); spinlock_release(instance->lock);
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
if(tok == NULL){ if(tok == NULL){
free(qs); free(qs);
goto retblock; goto retblock;
} }
qs->limit = atoi(tok); qs->limit = atoi(tok);
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
if(tok == NULL){ if(tok == NULL){
free(qs); free(qs);
goto retblock; goto retblock;
} }
qs->period = atof(tok); qs->period = atof(tok);
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
if(tok == NULL){ if(tok == NULL){
free(qs); free(qs);
goto retblock; goto retblock;
@ -943,7 +956,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
} }
else if(strcmp(tok,"on_operations") == 0) else if(strcmp(tok,"on_operations") == 0)
{ {
tok = strtok(NULL," "); tok = strtok_r(NULL," ",&saveptr);
if(!parse_querytypes(tok,ruledef)){ if(!parse_querytypes(tok,ruledef)){
skygw_log_write(LOGFILE_ERROR, skygw_log_write(LOGFILE_ERROR,
"fwfilter: Invalid query type" "fwfilter: Invalid query type"
@ -951,7 +964,7 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
,tok); ,tok);
} }
} }
tok = strtok(NULL," ,"); tok = strtok_r(NULL," ,",&saveptr);
} }
goto retblock; goto retblock;

View File

@ -11,6 +11,7 @@ add_executable(harness harness_util.c harness_common.c ${CORE})
target_link_libraries(harness_ui fullcore log_manager utils) target_link_libraries(harness_ui fullcore log_manager utils)
target_link_libraries(harness fullcore) target_link_libraries(harness fullcore)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${ERRMSG} ${CMAKE_CURRENT_BINARY_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${ERRMSG} ${CMAKE_CURRENT_BINARY_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/harness.cnf ${CMAKE_CURRENT_BINARY_DIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testdriver.sh ${CMAKE_CURRENT_BINARY_DIR}/testdriver.sh @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testdriver.sh ${CMAKE_CURRENT_BINARY_DIR}/testdriver.sh @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hintfilter/hint_testing.cnf ${CMAKE_CURRENT_BINARY_DIR}/hintfilter/hint_testing.cnf) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hintfilter/hint_testing.cnf ${CMAKE_CURRENT_BINARY_DIR}/hintfilter/hint_testing.cnf)

View File

@ -141,6 +141,7 @@ FILTER_PARAMETER** read_params(int* paramc)
{ {
char buffer[256]; char buffer[256];
char* token; char* token;
char* saveptr;
char* names[64]; char* names[64];
char* values[64]; char* values[64];
int pc = 0, do_read = 1, val_len = 0; int pc = 0, do_read = 1, val_len = 0;
@ -157,14 +158,14 @@ FILTER_PARAMETER** read_params(int* paramc)
if(strcmp("done\n",buffer) == 0){ if(strcmp("done\n",buffer) == 0){
do_read = 0; do_read = 0;
}else{ }else{
token = strtok(buffer,"=\n"); token = strtok_r(buffer,"=\n",&saveptr);
if(token!=NULL){ if(token!=NULL){
val_len = strcspn(token," \n\0"); val_len = strcspn(token," \n\0");
if((names[pc] = calloc((val_len + 1),sizeof(char))) != NULL){ if((names[pc] = calloc((val_len + 1),sizeof(char))) != NULL){
memcpy(names[pc],token,val_len); memcpy(names[pc],token,val_len);
} }
} }
token = strtok(NULL,"=\n"); token = strtok_r(NULL,"=\n",&saveptr);
if(token!=NULL){ if(token!=NULL){
val_len = strcspn(token," \n\0"); val_len = strcspn(token," \n\0");
if((values[pc] = calloc((val_len + 1),sizeof(char))) != NULL){ if((values[pc] = calloc((val_len + 1),sizeof(char))) != NULL){
@ -997,6 +998,7 @@ int process_opts(int argc, char** argv)
int fd, buffsize = 1024; int fd, buffsize = 1024;
int rd,rdsz, rval = 0, error = 0; int rd,rdsz, rval = 0, error = 0;
size_t fsize; size_t fsize;
char* saveptr;
char *buff = calloc(buffsize,sizeof(char)), *tok = NULL; char *buff = calloc(buffsize,sizeof(char)), *tok = NULL;
/**Parse 'harness.cnf' file*/ /**Parse 'harness.cnf' file*/
@ -1027,16 +1029,16 @@ int process_opts(int argc, char** argv)
instance.session_count = 1; instance.session_count = 1;
rdsz = read(fd,buff,fsize); rdsz = read(fd,buff,fsize);
buff[rdsz] = '\0'; buff[rdsz] = '\0';
tok = strtok(buff,"="); tok = strtok_r(buff,"=",&saveptr);
while(tok){ while(tok){
if(!strcmp(tok,"threads")){ if(!strcmp(tok,"threads")){
tok = strtok(NULL,"\n\0"); tok = strtok_r(NULL,"\n\0",&saveptr);
instance.thrcount = strtol(tok,0,0); instance.thrcount = strtol(tok,0,0);
}else if(!strcmp(tok,"sessions")){ }else if(!strcmp(tok,"sessions")){
tok = strtok(NULL,"\n\0"); tok = strtok_r(NULL,"\n\0",&saveptr);
instance.session_count = strtol(tok,0,0); instance.session_count = strtol(tok,0,0);
} }
tok = strtok(NULL,"="); tok = strtok_r(NULL,"=",&saveptr);
} }

View File

@ -20,7 +20,6 @@ int main(int argc, char** argv){
printf("\n\n\tFilter Test Harness\n\n"); printf("\n\n\tFilter Test Harness\n\n");
} }
while(instance.running){ while(instance.running){
printf("Harness> "); printf("Harness> ");
memset(buffer,0,256); memset(buffer,0,256);

View File

@ -488,8 +488,11 @@ char *ptr;
} }
static int static int
cmp_topn(TOPNQ **a, TOPNQ **b) cmp_topn(const void *va, const void *vb)
{ {
TOPNQ **a = (TOPNQ **)va;
TOPNQ **b = (TOPNQ **)vb;
if ((*b)->duration.tv_sec == (*a)->duration.tv_sec) if ((*b)->duration.tv_sec == (*a)->duration.tv_sec)
return (*b)->duration.tv_usec - (*a)->duration.tv_usec; return (*b)->duration.tv_usec - (*a)->duration.tv_usec;
return (*b)->duration.tv_sec - (*a)->duration.tv_sec; return (*b)->duration.tv_sec - (*a)->duration.tv_sec;