Added licences and changed the use of zero-length arrays due to compiler problems.
This commit is contained in:
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -16,7 +35,7 @@
|
|||||||
typedef struct logfile_writebuf_st {
|
typedef struct logfile_writebuf_st {
|
||||||
skygw_chk_t wb_chk_top;
|
skygw_chk_t wb_chk_top;
|
||||||
size_t wb_bufsize;
|
size_t wb_bufsize;
|
||||||
char wb_buf[1];
|
char wb_buf[1]; /** no zero length arrays in C++ */
|
||||||
} logfile_writebuf_t;
|
} logfile_writebuf_t;
|
||||||
|
|
||||||
/** Writer thread structure */
|
/** Writer thread structure */
|
||||||
@ -403,7 +422,7 @@ static int logmanager_write(
|
|||||||
}
|
}
|
||||||
/** Split loginfo to buffers, if necessary, and add buffers
|
/** Split loginfo to buffers, if necessary, and add buffers
|
||||||
* to logfile.
|
* to logfile.
|
||||||
* Free write buffer pointer array, and original string. */
|
* Free write buffer pointer array. */
|
||||||
logfile_write_buffers(lf, wb_arr, str);
|
logfile_write_buffers(lf, wb_arr, str);
|
||||||
} else {
|
} else {
|
||||||
ss_dassert(flush);
|
ss_dassert(flush);
|
||||||
@ -459,36 +478,35 @@ static logfile_writebuf_t** get_or_create_writebuffers(
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Allocating memory for write buffer "
|
"Allocating memory for write buffer "
|
||||||
"pointer array failed.\n");
|
"pointer array failed.\n");
|
||||||
goto return_p_str;
|
goto return_p_wb;
|
||||||
}
|
}
|
||||||
/** Allocate memory for all write buffers.
|
/** Allocate memory for all write buffers.
|
||||||
* Real allocation size includes logfile_writebuf_t and bufsize.
|
* Real allocation size includes logfile_writebuf_t and bufsize.
|
||||||
* -1 is the one byte defined in logfile_writebuf_st.
|
* -1 is the one byte defined in logfile_writebuf_st.
|
||||||
*/
|
*/
|
||||||
allocsize = sizeof(logfile_writebuf_t)+bufsize-1;
|
allocsize = sizeof(logfile_writebuf_t)+bufsize-1;
|
||||||
*p_wb = (logfile_writebuf_t *)calloc(nbufs, allocsize);
|
|
||||||
|
|
||||||
if (*p_wb == NULL) {
|
/** Allocate each buffer with separate call because memory checkers
|
||||||
fprintf(stderr,
|
* don't like array of structs which have flexible arrays. */
|
||||||
"Allocating memory for write buffer "
|
|
||||||
"pointer array failed.\n");
|
|
||||||
free(*p_wb);
|
|
||||||
free(p_wb);
|
|
||||||
*p_wb = NULL;
|
|
||||||
goto return_p_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store pointers of each buffer from continuous memory chunk
|
|
||||||
* to p_str. Initialize each write buffer.
|
|
||||||
*/
|
|
||||||
for (i=0; i<nbufs; i++) {
|
for (i=0; i<nbufs; i++) {
|
||||||
p_wb[i] = (logfile_writebuf_t *)((char*)*p_wb)+i*allocsize;
|
p_wb[i] = (logfile_writebuf_t *)calloc(1, allocsize);
|
||||||
|
|
||||||
|
if (p_wb[i] == NULL) {
|
||||||
|
i -= 1;
|
||||||
|
while(i>=0) {
|
||||||
|
free(p_wb[i]);
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
free(p_wb);
|
||||||
|
p_wb = NULL;
|
||||||
|
fprintf(stderr, "Allocating memory for write buffer failed.\n");
|
||||||
|
goto return_p_wb;
|
||||||
|
}
|
||||||
p_wb[i]->wb_chk_top = CHK_NUM_WRITEBUF;
|
p_wb[i]->wb_chk_top = CHK_NUM_WRITEBUF;
|
||||||
p_wb[i]->wb_bufsize = bufsize;
|
p_wb[i]->wb_bufsize = bufsize;
|
||||||
}
|
}
|
||||||
ss_dassert(p_wb[i] == NULL);
|
|
||||||
|
|
||||||
return_p_str:
|
return_p_wb:
|
||||||
return p_wb;
|
return p_wb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,8 +543,6 @@ static void logfile_write_buffers(
|
|||||||
p += copylen;
|
p += copylen;
|
||||||
slen -= copylen;
|
slen -= copylen;
|
||||||
}
|
}
|
||||||
/** Release log string */
|
|
||||||
free(str);
|
|
||||||
ss_dassert(slen == 0);
|
ss_dassert(slen == 0);
|
||||||
ss_dassert(*p_wb == NULL);
|
ss_dassert(*p_wb == NULL);
|
||||||
p_wb = p_data;
|
p_wb = p_data;
|
||||||
@ -583,6 +599,8 @@ int skygw_log_write_flush(
|
|||||||
return_unregister:
|
return_unregister:
|
||||||
logmanager_unregister(lmgr);
|
logmanager_unregister(lmgr);
|
||||||
return_err:
|
return_err:
|
||||||
|
/** Free log string */
|
||||||
|
free(str);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,7 +611,7 @@ int skygw_log_write(
|
|||||||
char* str)
|
char* str)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (lmgr == NULL) {
|
if (lmgr == NULL) {
|
||||||
fprintf(stderr, "Error. Logmanager is not initialized.\n");
|
fprintf(stderr, "Error. Logmanager is not initialized.\n");
|
||||||
err = -1;
|
err = -1;
|
||||||
@ -622,6 +640,8 @@ int skygw_log_write(
|
|||||||
return_unregister:
|
return_unregister:
|
||||||
logmanager_unregister(lmgr);
|
logmanager_unregister(lmgr);
|
||||||
return_err:
|
return_err:
|
||||||
|
/** Free log string */
|
||||||
|
free(str);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,6 +951,7 @@ static bool logfile_init(
|
|||||||
{
|
{
|
||||||
bool succp = FALSE;
|
bool succp = FALSE;
|
||||||
size_t namelen;
|
size_t namelen;
|
||||||
|
size_t s;
|
||||||
fnames_conf_t* fn = &logmanager->lm_fnames_conf;
|
fnames_conf_t* fn = &logmanager->lm_fnames_conf;
|
||||||
|
|
||||||
logfile->lf_chk_top = CHK_NUM_LOGFILE;
|
logfile->lf_chk_top = CHK_NUM_LOGFILE;
|
||||||
@ -947,10 +968,11 @@ static bool logfile_init(
|
|||||||
/** Read existing files to logfile->lf_files_list and create
|
/** Read existing files to logfile->lf_files_list and create
|
||||||
* new file for log named after <directory>/<prefix><counter><suffix>
|
* new file for log named after <directory>/<prefix><counter><suffix>
|
||||||
*/
|
*/
|
||||||
|
s = UINTLEN(logfile->lf_name_sequence);
|
||||||
namelen = strlen(logfile->lf_logpath) +
|
namelen = strlen(logfile->lf_logpath) +
|
||||||
sizeof('/') +
|
sizeof('/') +
|
||||||
strlen(logfile->lf_name_prefix) +
|
strlen(logfile->lf_name_prefix) +
|
||||||
printf("%d",logfile->lf_name_sequence) +
|
s +
|
||||||
strlen(logfile->lf_name_suffix) +
|
strlen(logfile->lf_name_suffix) +
|
||||||
sizeof('\0');
|
sizeof('\0');
|
||||||
|
|
||||||
|
@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
typedef struct filewriter_st filewriter_t;
|
typedef struct filewriter_st filewriter_t;
|
||||||
|
@ -1,3 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
@brief (brief description)
|
||||||
|
|
||||||
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <skygw_utils.h>
|
#include <skygw_utils.h>
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -18,15 +37,6 @@
|
|||||||
|
|
||||||
#if defined(SS_DEBUG)
|
#if defined(SS_DEBUG)
|
||||||
|
|
||||||
# define STRBOOL(b) ((b) ? "TRUE" : "FALSE")
|
|
||||||
# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \
|
|
||||||
((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \
|
|
||||||
((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \
|
|
||||||
"QUERY_TYPE_UNKNOWN")))
|
|
||||||
#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \
|
|
||||||
((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \
|
|
||||||
((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \
|
|
||||||
"Unknown logfile type")))
|
|
||||||
# define ss_dfprintf fprintf
|
# define ss_dfprintf fprintf
|
||||||
# define ss_dfflush fflush
|
# define ss_dfflush fflush
|
||||||
# define ss_dfwrite fwrite
|
# define ss_dfwrite fwrite
|
||||||
@ -63,7 +73,6 @@
|
|||||||
|
|
||||||
#else /* SS_DEBUG */
|
#else /* SS_DEBUG */
|
||||||
|
|
||||||
# define STRBOOL(b)
|
|
||||||
# define ss_dfprintf(a, b, ...)
|
# define ss_dfprintf(a, b, ...)
|
||||||
# define ss_dfflush
|
# define ss_dfflush
|
||||||
# define ss_dfwrite
|
# define ss_dfwrite
|
||||||
@ -94,6 +103,15 @@ typedef enum skygw_chk_t {
|
|||||||
CHK_NUM_WRITEBUF
|
CHK_NUM_WRITEBUF
|
||||||
} skygw_chk_t;
|
} skygw_chk_t;
|
||||||
|
|
||||||
|
# define STRBOOL(b) ((b) ? "TRUE" : "FALSE")
|
||||||
|
# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \
|
||||||
|
((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \
|
||||||
|
((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \
|
||||||
|
"QUERY_TYPE_UNKNOWN")))
|
||||||
|
#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \
|
||||||
|
((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \
|
||||||
|
((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \
|
||||||
|
"Unknown logfile type")))
|
||||||
|
|
||||||
#define CHK_MLIST(l) { \
|
#define CHK_MLIST(l) { \
|
||||||
ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \
|
ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \
|
||||||
|
@ -1,28 +1,23 @@
|
|||||||
/**
|
/*
|
||||||
* @section LICENCE
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
*
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
* This file is distributed as part of the SkySQL Gateway. It is
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
* free software: you can redistribute it and/or modify it under
|
* version 2.
|
||||||
* the terms of the GNU General Public License as published by the
|
*
|
||||||
* Free Software Foundation, version 2.
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
*
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* This program is distributed in the hope that it will be useful,
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* details.
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
* GNU General Public License for more details.
|
* You should have received a copy of the GNU General Public License along with
|
||||||
*
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
* You should have received a copy of the GNU General Public License
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
* along with this program; if not, write to the Free Software
|
*
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
* Copyright SkySQL Ab 2013
|
||||||
* 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Copyright SkySQL Ab
|
|
||||||
*
|
|
||||||
* @file
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#if !defined(SKYGW_TYPES_H)
|
#if !defined(SKYGW_TYPES_H)
|
||||||
#define SKYGW_TYPES_H
|
#define SKYGW_TYPES_H
|
||||||
|
|
||||||
@ -37,7 +32,9 @@
|
|||||||
#define MB MEGABYTE_BYTE
|
#define MB MEGABYTE_BYTE
|
||||||
#define GB GIGABYTE_BYTE
|
#define GB GIGABYTE_BYTE
|
||||||
|
|
||||||
|
#define CALCLEN(i) (floor(log10(abs(i))) + 1)
|
||||||
|
|
||||||
|
#define UINTLEN(i) (i<10 ? 1 : (i<100 ? 2 : (i<1000 ? 3 : CALCLEN(i))))
|
||||||
|
|
||||||
#if defined(__cplusplus) && !defined(TRUE) && !defined(FALSE)
|
#if defined(__cplusplus) && !defined(TRUE) && !defined(FALSE)
|
||||||
# define TRUE true
|
# define TRUE true
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
Reference in New Issue
Block a user