Fixed log manager sometimes not writing the last character in a log message.
This was caused by type conversions from int to size_t and the usage of the MAX macro.
This commit is contained in:
@ -683,7 +683,7 @@ static int logmanager_write_log(
|
|||||||
size_t safe_str_len;
|
size_t safe_str_len;
|
||||||
/** Length of session id */
|
/** Length of session id */
|
||||||
size_t sesid_str_len;
|
size_t sesid_str_len;
|
||||||
|
size_t cmplen = 0;
|
||||||
/**
|
/**
|
||||||
* 2 braces, 2 spaces and terminating char
|
* 2 braces, 2 spaces and terminating char
|
||||||
* If session id is stored to tls_log_info structure, allocate
|
* If session id is stored to tls_log_info structure, allocate
|
||||||
@ -691,7 +691,7 @@ static int logmanager_write_log(
|
|||||||
*/
|
*/
|
||||||
if (id == LOGFILE_TRACE && tls_log_info.li_sesid != 0)
|
if (id == LOGFILE_TRACE && tls_log_info.li_sesid != 0)
|
||||||
{
|
{
|
||||||
sesid_str_len = 2+2+get_decimal_len(tls_log_info.li_sesid)+1;
|
sesid_str_len = 5*sizeof(char)+get_decimal_len(tls_log_info.li_sesid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -699,14 +699,16 @@ static int logmanager_write_log(
|
|||||||
}
|
}
|
||||||
timestamp_len = get_timestamp_len();
|
timestamp_len = get_timestamp_len();
|
||||||
|
|
||||||
|
cmplen = sesid_str_len > 0 ? sesid_str_len - sizeof(char) : 0;
|
||||||
|
|
||||||
/** Find out how much can be safely written with current block size */
|
/** Find out how much can be safely written with current block size */
|
||||||
if (timestamp_len-1+MAX(sesid_str_len-1,0)+str_len > lf->lf_buf_size)
|
if (timestamp_len-sizeof(char)+cmplen+str_len > lf->lf_buf_size)
|
||||||
{
|
{
|
||||||
safe_str_len = lf->lf_buf_size;
|
safe_str_len = lf->lf_buf_size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
safe_str_len = timestamp_len-1+MAX(sesid_str_len-1,0)+str_len;
|
safe_str_len = timestamp_len-sizeof(char)+cmplen+str_len;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Seek write position and register to block buffer.
|
* Seek write position and register to block buffer.
|
||||||
|
@ -157,7 +157,7 @@ static bool do_hashtest(
|
|||||||
CHK_HASHTABLE(h);
|
CHK_HASHTABLE(h);
|
||||||
hashtable_free(h);
|
hashtable_free(h);
|
||||||
|
|
||||||
return_succp:
|
|
||||||
free(val_arr);
|
free(val_arr);
|
||||||
return succp;
|
return succp;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <server.h>
|
#include <server.h>
|
||||||
|
#include <log_manager.h>
|
||||||
/**
|
/**
|
||||||
* test1 Allocate a server and do lots of other things
|
* test1 Allocate a server and do lots of other things
|
||||||
*
|
*
|
||||||
|
@ -187,7 +187,7 @@ int main(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance.thrpool = t_thr_pool;
|
instance.thrpool = t_thr_pool;
|
||||||
int thr_num = 1;
|
intptr_t thr_num = 1;
|
||||||
|
|
||||||
for(i = 0;i<instance.thrcount;i++){
|
for(i = 0;i<instance.thrcount;i++){
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
||||||
/** One for terminating '\0' */
|
/** One for terminating '\0' */
|
||||||
const int timestamp_len = 4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1;
|
const size_t timestamp_len = (4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1) * sizeof(char);
|
||||||
|
|
||||||
/** Single-linked list for storing test cases */
|
/** Single-linked list for storing test cases */
|
||||||
|
|
||||||
@ -662,7 +662,7 @@ bool mlist_cursor_move_to_first(
|
|||||||
/** End of mlist */
|
/** End of mlist */
|
||||||
|
|
||||||
|
|
||||||
int get_timestamp_len(void)
|
size_t get_timestamp_len(void)
|
||||||
{
|
{
|
||||||
return timestamp_len;
|
return timestamp_len;
|
||||||
}
|
}
|
||||||
@ -682,13 +682,13 @@ int get_timestamp_len(void)
|
|||||||
* @details (write detailed description here)
|
* @details (write detailed description here)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int snprint_timestamp(
|
size_t snprint_timestamp(
|
||||||
char* p_ts,
|
char* p_ts,
|
||||||
int tslen)
|
size_t tslen)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
int rval;
|
size_t rval;
|
||||||
|
|
||||||
if (p_ts == NULL) {
|
if (p_ts == NULL) {
|
||||||
rval = 0;
|
rval = 0;
|
||||||
@ -708,7 +708,7 @@ int snprint_timestamp(
|
|||||||
tm.tm_min,
|
tm.tm_min,
|
||||||
tm.tm_sec);
|
tm.tm_sec);
|
||||||
|
|
||||||
rval = strlen(p_ts);
|
rval = strlen(p_ts)*sizeof(char);
|
||||||
retblock:
|
retblock:
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,8 @@ int skygw_thread_start(skygw_thread_t* thr);
|
|||||||
skygw_thr_state_t skygw_thread_get_state(skygw_thread_t* thr);
|
skygw_thr_state_t skygw_thread_get_state(skygw_thread_t* thr);
|
||||||
pthread_t skygw_thread_gettid(skygw_thread_t* thr);
|
pthread_t skygw_thread_gettid(skygw_thread_t* thr);
|
||||||
|
|
||||||
int get_timestamp_len(void);
|
size_t get_timestamp_len(void);
|
||||||
int snprint_timestamp(char* p_ts, int tslen);
|
size_t snprint_timestamp(char* p_ts, size_t tslen);
|
||||||
|
|
||||||
EXTERN_C_BLOCK_BEGIN
|
EXTERN_C_BLOCK_BEGIN
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user