int logger_vprintf(LOGGER_HANDLE *log, const char* fmt, va_list ap) { int result; my_off_t filesize; char cvtbuf[1024]; size_t n_bytes; mysql_mutex_lock(&log->lock); if (log->rotations > 0) if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || ((unsigned long long)filesize >= log->size_limit && do_rotate(log))) { result= -1; errno= my_errno; goto exit; /* Log rotation needed but failed */ } n_bytes= my_vsnprintf(cvtbuf, sizeof(cvtbuf), fmt, ap); if (n_bytes >= sizeof(cvtbuf)) n_bytes= sizeof(cvtbuf) - 1; result= my_write(log->file, (uchar *) cvtbuf, n_bytes, MYF(0)); exit: mysql_mutex_unlock(&log->lock); return result; }
my_off_t my_b_append_tell(IO_CACHE* info) { /* Sometimes we want to make sure that the variable is not put into a register in debugging mode so we can see its value in the core */ #ifndef DBUG_OFF # define dbug_volatile volatile #else # define dbug_volatile #endif /* Prevent optimizer from putting res in a register when debugging we need this to be able to see the value of res when the assert fails */ dbug_volatile my_off_t res; /* We need to lock the append buffer mutex to keep flush_io_cache() from messing with the variables that we need in order to provide the answer to the question. */ mysql_mutex_lock(&info->append_buffer_lock); #ifndef DBUG_OFF /* Make sure EOF is where we think it is. Note that we cannot just use my_tell() because we have a reader thread that could have left the file offset in a non-EOF location */ { volatile my_off_t save_pos; save_pos = my_tell(info->file,MYF(0)); my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0)); /* Save the value of my_tell in res so we can see it when studying coredump */ DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer) == (res=my_tell(info->file,MYF(0)))); my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0)); } #endif res = info->end_of_file + (info->write_pos-info->append_read_pos); mysql_mutex_unlock(&info->append_buffer_lock); return res; }
int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size) { int result; my_off_t filesize; mysql_mutex_lock(&log->lock); if (log->rotations > 0) if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || ((unsigned long long)filesize >= log->size_limit && do_rotate(log))) { result= -1; errno= my_errno; goto exit; /* Log rotation needed but failed */ } result= my_write(log->file, (uchar *) buffer, size, MYF(0)); exit: mysql_mutex_unlock(&log->lock); return result; }