tlog: bump tlog to v1.6
This commit is contained in:
52
src/tlog.c
52
src/tlog.c
@@ -306,7 +306,7 @@ void tlog_set_maxline_size(struct tlog_log *log, int size)
|
|||||||
log->max_line_size = size;
|
log->max_line_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tlog_set_permission(struct tlog_log *log, mode_t file, mode_t archive)
|
void tlog_set_permission(struct tlog_log *log, unsigned int file, unsigned int archive)
|
||||||
{
|
{
|
||||||
log->file_perm = file;
|
log->file_perm = file;
|
||||||
log->archive_perm = archive;
|
log->archive_perm = archive;
|
||||||
@@ -317,7 +317,7 @@ int tlog_localtime(struct tlog_time *tm)
|
|||||||
return _tlog_gettime(tm);
|
return _tlog_gettime(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog_log *tlog_get_root()
|
tlog_log *tlog_get_root(void)
|
||||||
{
|
{
|
||||||
return tlog.root;
|
return tlog.root;
|
||||||
}
|
}
|
||||||
@@ -1395,6 +1395,35 @@ static int _tlog_root_write_log(struct tlog_log *log, const char *buff, int buff
|
|||||||
return tlog.output_func(&empty_info.info, buff, bufflen, tlog_get_private(log));
|
return tlog.output_func(&empty_info.info, buff, bufflen, tlog_get_private(log));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tlog_wait_zip_fini(void)
|
||||||
|
{
|
||||||
|
tlog_log *next;
|
||||||
|
if (tlog.root == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wait_zip = 1;
|
||||||
|
int time_out = 0;
|
||||||
|
while (wait_zip) {
|
||||||
|
wait_zip = 0;
|
||||||
|
time_out++;
|
||||||
|
next = tlog.log;
|
||||||
|
while (next) {
|
||||||
|
if (next->zip_pid > 0 && wait_zip == 0) {
|
||||||
|
wait_zip = 1;
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kill(next->zip_pid, 0) != 0 || time_out >= 5000) {
|
||||||
|
next->zip_pid = -1;
|
||||||
|
}
|
||||||
|
next = next->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static void *_tlog_work(void *arg)
|
static void *_tlog_work(void *arg)
|
||||||
{
|
{
|
||||||
int log_len = 0;
|
int log_len = 0;
|
||||||
@@ -1408,6 +1437,9 @@ static void *_tlog_work(void *arg)
|
|||||||
|
|
||||||
unused = arg;
|
unused = arg;
|
||||||
|
|
||||||
|
// for child process
|
||||||
|
tlog_wait_zip_fini();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
log_len = 0;
|
log_len = 0;
|
||||||
log_extlen = 0;
|
log_extlen = 0;
|
||||||
@@ -1680,6 +1712,12 @@ static void tlog_fork_prepare(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&tlog.lock);
|
pthread_mutex_lock(&tlog.lock);
|
||||||
|
tlog_log *next;
|
||||||
|
next = tlog.log;
|
||||||
|
while (next) {
|
||||||
|
next->multi_log = 1;
|
||||||
|
next = next->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tlog_fork_parent(void)
|
static void tlog_fork_parent(void)
|
||||||
@@ -1699,6 +1737,16 @@ static void tlog_fork_child(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next = tlog.log;
|
||||||
|
while (next) {
|
||||||
|
next->start = 0;
|
||||||
|
next->end = 0;
|
||||||
|
next->ext_end = 0;
|
||||||
|
next->dropped = 0;
|
||||||
|
next->filesize = 0;
|
||||||
|
next = next->next;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
int ret = pthread_create(&tlog.tid, &attr, _tlog_work, NULL);
|
int ret = pthread_create(&tlog.tid, &attr, _tlog_work, NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ level: Current log Levels
|
|||||||
format: Log formats
|
format: Log formats
|
||||||
*/
|
*/
|
||||||
#ifndef BASE_FILE_NAME
|
#ifndef BASE_FILE_NAME
|
||||||
#define BASE_FILE_NAME __FILE__
|
#define BASE_FILE_NAME \
|
||||||
|
(__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \
|
||||||
|
: __FILE__)
|
||||||
#endif
|
#endif
|
||||||
#define tlog(level, format, ...) tlog_ext(level, BASE_FILE_NAME, __LINE__, __func__, NULL, format, ##__VA_ARGS__)
|
#define tlog(level, format, ...) tlog_ext(level, BASE_FILE_NAME, __LINE__, __func__, NULL, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user