Simple fix: disable logging to files where logging fails.
This commit is contained in:
VilhoRaatikka
2014-11-10 13:50:24 +02:00
parent 37fa9668a9
commit 20ddcfb8c4

View File

@ -276,6 +276,8 @@ static bool check_file_and_path(
bool* writable); bool* writable);
static bool file_is_symlink(char* filename); static bool file_is_symlink(char* filename);
static int skygw_log_disable_raw(logfile_id_t id, bool emergency); /*< no locking */
const char* get_suffix_default(void) const char* get_suffix_default(void)
{ {
@ -1185,25 +1187,36 @@ return_err:
return err; return err;
} }
int skygw_log_disable( int skygw_log_disable(
logfile_id_t id) logfile_id_t id) /*< no locking */
{
int rc;
rc = skygw_log_disable_raw(id, false);
return rc;
}
static int skygw_log_disable_raw(
logfile_id_t id,
bool emergency) /*< no locking */
{ {
bool err = 0; bool err = 0;
if (!logmanager_register(true)) { if (!logmanager_register(true))
//fprintf(stderr, "ERROR: Can't register to logmanager\n"); {
err = -1; err = -1;
goto return_err; goto return_err;
} }
CHK_LOGMANAGER(lm); CHK_LOGMANAGER(lm);
if (logfile_set_enabled(id, false)) { if (emergency || logfile_set_enabled(id, false))
lm->lm_enabled_logfiles &= ~id; {
/** lm->lm_enabled_logfiles &= ~id;
* Set global variable /**
*/ * Set global variable
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles; */
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
} }
logmanager_unregister(); logmanager_unregister();
@ -2403,6 +2416,7 @@ static bool filewriter_init(
skygw_message_t* logmes) skygw_message_t* logmes)
{ {
bool succp = false; bool succp = false;
int err;
logfile_t* lf; logfile_t* lf;
logfile_id_t id; logfile_id_t id;
int i; int i;
@ -2456,10 +2470,22 @@ static bool filewriter_init(
} else { } else {
start_msg_str = strdup("---\tLogging is disabled.\n"); start_msg_str = strdup("---\tLogging is disabled.\n");
} }
skygw_file_write(fw->fwr_file[id], err = skygw_file_write(fw->fwr_file[id],
(void *)start_msg_str, (void *)start_msg_str,
strlen(start_msg_str), strlen(start_msg_str),
true); true);
if (err != 0)
{
fprintf(stderr,
"Error : writing to file %s failed due to %d, %s. "
"Exiting MaxScale.\n",
lf->lf_full_file_name,
err,
strerror(err));
succp = false;
goto return_succp;
}
free(start_msg_str); free(start_msg_str);
} }
fw->fwr_state = RUN; fw->fwr_state = RUN;
@ -2603,7 +2629,10 @@ static void* thr_filewriter_fun(
#endif #endif
node = bb_list->mlist_first; node = bb_list->mlist_first;
while (node != NULL) { while (node != NULL)
{
int err = 0;
CHK_MLIST_NODE(node); CHK_MLIST_NODE(node);
bb = (blockbuf_t *)node->mlnode_data; bb = (blockbuf_t *)node->mlnode_data;
CHK_BLOCKBUF(bb); CHK_BLOCKBUF(bb);
@ -2630,11 +2659,25 @@ static void* thr_filewriter_fun(
true); true);
} }
skygw_file_write(file, err = skygw_file_write(
(void *)bb->bb_buf, file,
bb->bb_buf_used, (void *)bb->bb_buf,
(flush_logfile || bb->bb_buf_used,
flushall_logfiles)); (flush_logfile ||
flushall_logfiles));
if (err)
{
fprintf(stderr,
"Error : Write to %s log "
": %s failed due to %d, "
"%s. Disabling the log.",
STRLOGNAME((logfile_id_t)i),
lf->lf_full_file_name,
err,
strerror(err));
/** Force log off */
skygw_log_disable_raw((logfile_id_t)i, true);
}
/** /**
* Reset buffer's counters and mark * Reset buffer's counters and mark
* not full. * not full.