Removed stdout specific functions in skygw_utils and moved the logic to log_manager instead.
This commit is contained in:
parent
47e5b12eb8
commit
7c988c4fd5
@ -2161,9 +2161,9 @@ static bool logfile_open_file(
|
||||
|
||||
if(use_stdout)
|
||||
{
|
||||
fw->fwr_file[lf->lf_id] = skygw_file_init_stdout (
|
||||
lf->lf_full_file_name,
|
||||
lf->lf_full_link_name);
|
||||
fw->fwr_file[lf->lf_id] = skygw_file_alloc (
|
||||
lf->lf_full_file_name);
|
||||
fw->fwr_file[lf->lf_id]->sf_file = stdout;
|
||||
}
|
||||
else if (lf->lf_store_shmem)
|
||||
{
|
||||
@ -2742,7 +2742,7 @@ static void filewriter_done(
|
||||
{
|
||||
id = (logfile_id_t)i;
|
||||
if(use_stdout)
|
||||
skygw_file_close_stdout(fw->fwr_file[id], true);
|
||||
skygw_file_free(fw->fwr_file[id]);
|
||||
else
|
||||
skygw_file_close(fw->fwr_file[id], true);
|
||||
}
|
||||
@ -2876,6 +2876,9 @@ static void* thr_filewriter_fun(
|
||||
}
|
||||
else if ((succp = logfile_open_file(fwr, lf)))
|
||||
{
|
||||
if(use_stdout)
|
||||
skygw_file_free (file);
|
||||
else
|
||||
skygw_file_close(file, false); /*< close old file */
|
||||
}
|
||||
|
||||
|
@ -1882,24 +1882,37 @@ return_rc:
|
||||
return rc;
|
||||
}
|
||||
|
||||
skygw_file_t* skygw_file_alloc(
|
||||
char* fname)
|
||||
{
|
||||
skygw_file_t* file;
|
||||
|
||||
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"* Error : Memory allocation for file %s failed.\n",
|
||||
fname);
|
||||
perror("SkyGW file allocation\n");
|
||||
return NULL;
|
||||
}
|
||||
ss_dassert(file != NULL);
|
||||
file->sf_chk_top = CHK_NUM_FILE;
|
||||
file->sf_chk_tail = CHK_NUM_FILE;
|
||||
file->sf_fname = strdup(fname);
|
||||
return file;
|
||||
}
|
||||
|
||||
skygw_file_t* skygw_file_init(
|
||||
char* fname,
|
||||
char* symlinkname)
|
||||
{
|
||||
skygw_file_t* file;
|
||||
|
||||
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
|
||||
if ((file = skygw_file_alloc (fname)) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"* Error : Memory allocation for file %s failed.\n",
|
||||
fname);
|
||||
perror("SkyGW file allocation\n");
|
||||
/** Error was reported in skygw_file_alloc */
|
||||
goto return_file;
|
||||
}
|
||||
ss_dassert(file != NULL);
|
||||
file->sf_chk_top = CHK_NUM_FILE;
|
||||
file->sf_chk_tail = CHK_NUM_FILE;
|
||||
file->sf_fname = strdup(fname);
|
||||
|
||||
if ((file->sf_file = fopen(file->sf_fname, "a")) == NULL)
|
||||
{
|
||||
@ -1963,58 +1976,10 @@ return_file:
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
skygw_file_t* skygw_file_init_stdout(
|
||||
char* fname,
|
||||
char* symlinkname)
|
||||
void skygw_file_free(skygw_file_t* file)
|
||||
{
|
||||
skygw_file_t* file;
|
||||
|
||||
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"* Error : Memory allocation for file %s failed.\n",
|
||||
fname);
|
||||
perror("SkyGW file allocation\n");
|
||||
goto return_file;
|
||||
}
|
||||
ss_dassert(file != NULL);
|
||||
file->sf_chk_top = CHK_NUM_FILE;
|
||||
file->sf_chk_tail = CHK_NUM_FILE;
|
||||
file->sf_fname = strdup(fname);
|
||||
file->sf_file = stdout;
|
||||
CHK_FILE(file);
|
||||
|
||||
return_file:
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
void skygw_file_close_stdout(
|
||||
skygw_file_t* file,
|
||||
bool shutdown)
|
||||
{
|
||||
int fd;
|
||||
int err;
|
||||
|
||||
if (file != NULL)
|
||||
{
|
||||
CHK_FILE(file);
|
||||
|
||||
if (!file_write_footer(file, shutdown))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"* Writing footer to log file %s failed.\n",
|
||||
file->sf_fname);
|
||||
perror("Write fike footer\n");
|
||||
}
|
||||
fd = fileno(file->sf_file);
|
||||
fsync(fd);
|
||||
|
||||
ss_dfprintf(stderr, "Closed %s\n", file->sf_fname);
|
||||
free(file->sf_fname);
|
||||
free(file);
|
||||
}
|
||||
free(file->sf_fname);
|
||||
free(file);
|
||||
}
|
||||
|
||||
void skygw_file_close(
|
||||
@ -2037,7 +2002,7 @@ void skygw_file_close(
|
||||
}
|
||||
fd = fileno(file->sf_file);
|
||||
fsync(fd);
|
||||
|
||||
|
||||
if ((err = fclose(file->sf_file)) != 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
@ -2049,8 +2014,7 @@ void skygw_file_close(
|
||||
else
|
||||
{
|
||||
ss_dfprintf(stderr, "Closed %s\n", file->sf_fname);
|
||||
free(file->sf_fname);
|
||||
free(file);
|
||||
skygw_file_free (file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,10 +216,10 @@ EXTERN_C_BLOCK_END
|
||||
/** Skygw thread routines */
|
||||
|
||||
/** Skygw file routines */
|
||||
skygw_file_t* skygw_file_alloc(char* fname);
|
||||
void skygw_file_free(skygw_file_t* file);
|
||||
skygw_file_t* skygw_file_init(char* fname, char* symlinkname);
|
||||
skygw_file_t* skygw_file_init_stdout(char* fname, char* symlinkname);
|
||||
void skygw_file_close(skygw_file_t* file, bool shutdown);
|
||||
void skygw_file_close_stdout(skygw_file_t*, bool);
|
||||
int skygw_file_write(
|
||||
skygw_file_t* file,
|
||||
void* data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user