Browse Source

Bugfix & enhancement

Now an error is triggered if date-min > date-max
Bugfix on date-max searching (on multiple loglines with a date == date-max)
Yann Weber 7 years ago
parent
commit
833b2dae19
3 changed files with 24 additions and 6 deletions
  1. 2
    0
      src/include/ttail_search.h
  2. 11
    2
      src/ttail_init.c
  3. 11
    4
      src/ttail_search_files.c

+ 2
- 0
src/include/ttail_search.h View File

@@ -58,11 +58,13 @@ void ttail_search_print_res(ttail_t*);
58 58
  *@param ttail_t*
59 59
  *@param struct tm* tmin
60 60
  *@return 0 if ok -1 if fatal error 1 if not found
61
+ *@todo implement me
61 62
  */
62 63
 int _ttail_search_closest_stdin(ttail_t*);
63 64
 /**@brief Output result loglines to stdout
64 65
  *@param ttail_t*
65 66
  *@param int fd
67
+ *@todo implement me
66 68
  */
67 69
 void _ttail_search_print_stdin(ttail_t*, int);
68 70
 

+ 11
- 2
src/ttail_init.c View File

@@ -191,11 +191,20 @@ given as argument\n");
191 191
 			return -1;
192 192
 		}
193 193
 	}
194
-	if(!(t->flag & TTAIL_FLAG_DATE_MIN))
194
+	if(!(t->flag & TTAIL_FLAG_DATE_MIN) && !(t->flag & TTAIL_FLAG_DATE_MAX))
195 195
 	{
196
-		fprintf(stderr, "--date-min -d is mandatory\n");
196
+		fprintf(stderr, "one of --date-min -d --date-max -m is \
197
+mandatory\n");
197 198
 		return -1;
198 199
 	}
200
+	if((t->flag & TTAIL_FLAG_DATE_MIN) && (t->flag & TTAIL_FLAG_DATE_MAX))
201
+	{
202
+		if(ttail_tm_cmp(&(t->date_min), &(t->date_max)) > 0)
203
+		{
204
+			fprintf(stderr, "date-min > date-max.\n");
205
+			return -1;
206
+		}
207
+	}
199 208
 	if(!(t->flag & TTAIL_FLAG_FORMAT))
200 209
 	{
201 210
 		fprintf(stderr, "No date format set nor detected. Abording.\n");

+ 11
- 4
src/ttail_search_files.c View File

@@ -254,11 +254,18 @@ int _ttail_search_files_binary_search(ttail_t* t, const struct tm* in,
254 254
 		else if (cmax == 0)
255 255
 		{
256 256
 			/* found at EOF */
257
-			*off = _ttail_from_search_from_end(t, *id, in);
258
-			if(*off < 0)
257
+			if(min)
259 258
 			{
260
-				*off = 0;
261
-				return -1;
259
+				*off = _ttail_from_search_from_end(t, *id, in);
260
+				if(*off < 0)
261
+				{
262
+					*off = 0;
263
+					return -1;
264
+				}
265
+			}
266
+			else
267
+			{
268
+				*off = t->session->file.file_sz[*id];
262 269
 			}
263 270
 			return 0;
264 271
 		}

Loading…
Cancel
Save