|
@@ -60,8 +60,12 @@ File sorting not implemented yet\n");
|
60
|
60
|
}
|
61
|
61
|
/* TODO begining binary search of date_min */
|
62
|
62
|
ret = _ttail_search_files_binary_search(t, tm, (const struct tm**)ftm);
|
63
|
|
-
|
64
|
|
- return 0;
|
|
63
|
+ for(i=0; i<t->logfile_sz; i++)
|
|
64
|
+ {
|
|
65
|
+ if(ftm) { free(ftm[i]); }
|
|
66
|
+ }
|
|
67
|
+ free(ftm);
|
|
68
|
+ return ret;
|
65
|
69
|
goto _ttail_search_closest_files_err;
|
66
|
70
|
|
67
|
71
|
_ttail_search_closest_files_err:
|
|
@@ -111,7 +115,7 @@ int _ttail_search_files_binary_search(ttail_t* t, const struct tm* in,
|
111
|
115
|
/* found at the begining of the file */
|
112
|
116
|
return 0;
|
113
|
117
|
}
|
114
|
|
- else if (!cmax)
|
|
118
|
+ else if (cmax <= 0)
|
115
|
119
|
{
|
116
|
120
|
/* found at EOF */
|
117
|
121
|
*off = _ttail_from_search_from_end(t, *id, in);
|
|
@@ -490,8 +494,10 @@ inline off_t _ttail_from_search_from_end(ttail_t* t , size_t id ,
|
490
|
494
|
FILE *f;
|
491
|
495
|
struct tm curtm;
|
492
|
496
|
off_t last;
|
493
|
|
- int ret;
|
|
497
|
+ int ret, cmpret;
|
|
498
|
+ off_t result;
|
494
|
499
|
|
|
500
|
+ result = -1;
|
495
|
501
|
f = t->logfile[id];
|
496
|
502
|
if(fseek(f, -1, SEEK_END) < 0)
|
497
|
503
|
{
|
|
@@ -502,36 +508,41 @@ inline off_t _ttail_from_search_from_end(ttail_t* t , size_t id ,
|
502
|
508
|
last = _ttail_file_start_line(f);
|
503
|
509
|
if(last < 0)
|
504
|
510
|
{
|
505
|
|
- goto _ttail_from_search_from_end_err;
|
|
511
|
+ break;
|
506
|
512
|
}
|
507
|
513
|
if(ttail_getline(t, id) < 0)
|
508
|
514
|
{
|
509
|
|
- goto _ttail_from_search_from_end_err;
|
|
515
|
+ break;
|
510
|
516
|
}
|
511
|
517
|
ret = ttail_logline2date(t, ttail_getline_buf(t), &curtm);
|
512
|
518
|
if(ret < 0)
|
513
|
519
|
{
|
514
|
|
- goto _ttail_from_search_from_end_err;
|
|
520
|
+ break;
|
515
|
521
|
}
|
516
|
|
- if(!ret && !ttail_tm_cmp(&curtm, tm))
|
|
522
|
+ cmpret = ttail_tm_cmp(&curtm, tm);
|
|
523
|
+ if(!ret)
|
517
|
524
|
{
|
518
|
|
- /* found */
|
519
|
|
- break;
|
|
525
|
+ if(cmpret >= 0)
|
|
526
|
+ {
|
|
527
|
+ /* found but continue to search the first one*/
|
|
528
|
+ result = last;
|
|
529
|
+ }
|
|
530
|
+ else
|
|
531
|
+ {
|
|
532
|
+ break;
|
|
533
|
+ }
|
520
|
534
|
}
|
521
|
535
|
if(last == 0)
|
522
|
536
|
{
|
523
|
537
|
/* considere the begining of the file as the answer */
|
524
|
538
|
return 0;
|
525
|
539
|
}
|
526
|
|
- if(fseek(f, last-1, SEEK_CUR))
|
|
540
|
+ if(fseek(f, last-1, SEEK_SET))
|
527
|
541
|
{
|
528
|
|
- goto _ttail_from_search_from_end_err;
|
|
542
|
+ return -1;
|
529
|
543
|
}
|
530
|
544
|
}
|
531
|
|
- return last;
|
532
|
|
-
|
533
|
|
- _ttail_from_search_from_end_err:
|
534
|
|
- return -1;
|
|
545
|
+ return result;
|
535
|
546
|
}
|
536
|
547
|
|
537
|
548
|
inline int _ttail_file_off_cmp(ttail_t* t, size_t id, off_t off,
|