Browse Source

Better error handling

Add some perror calls
Yann Weber 7 years ago
parent
commit
1207a9f742
1 changed files with 29 additions and 5 deletions
  1. 29
    5
      src/ttail_search_files.c

+ 29
- 5
src/ttail_search_files.c View File

@@ -96,6 +96,11 @@ date-max\n");
96 96
 			(const struct tm**)ftm, 0);
97 97
 		if(ret)
98 98
 		{
99
+			if(t->verbose > 2)
100
+			{
101
+				fprintf(stderr, "Error while looking for \
102
+date-max\n");
103
+			}
99 104
 			goto _ttail_search_closest_files_err;
100 105
 		}
101 106
 		t->session->file.off_max.off++;
@@ -270,6 +275,11 @@ int _ttail_search_files_binary_search(ttail_t* t, const struct tm* in,
270 275
 			ret = _ttail_search_file_binary_search(t, in, ftm, min);
271 276
 			if(ret)
272 277
 			{
278
+				if(t->verbose > 2)
279
+				{
280
+					fprintf(stderr, "Error while \
281
+running binary search algorithm in '%s'\n", t->logfile_name[*id]);
282
+				}
273 283
 				*id = 0;
274 284
 				return ret;
275 285
 			}
@@ -340,16 +350,20 @@ inline int _ttail_search_file_binary_search(ttail_t* t, const struct tm* in,
340 350
 		if(cur > prev)
341 351
 		{
342 352
 			cur = _ttail_file_next_line(t->logfile[id]);
353
+			if(cur < 0)
354
+			{
355
+				/* not sure errno is really set */
356
+				perror("Error searching previous line");
357
+				return -1;
358
+			}
343 359
 		}
344 360
 		else
345
-		{
346
-			cur = _ttail_file_start_line(t->logfile[id]);
347
-		}
348
-		if(cur < -1)
349 361
 		{
350 362
 			cur = _ttail_file_start_line(t->logfile[id]);
351 363
 			if(cur < 0)
352 364
 			{
365
+				/* not sure errno is really set */
366
+				perror("Error searching previous line");
353 367
 				return -1;
354 368
 			}
355 369
 		}
@@ -362,6 +376,11 @@ inline int _ttail_search_file_binary_search(ttail_t* t, const struct tm* in,
362 376
 		ret = _ttail_file_cur_cmp(t, id, in, &cmpres);
363 377
 		if(ret < 0)
364 378
 		{
379
+			if(t->verbose > 2)
380
+			{
381
+				fprintf(stderr, "Error comparing a logline \
382
+to a date directly from a file\n");
383
+			}
365 384
 			return -1;
366 385
 		}
367 386
 		else if(cmpres == 0)
@@ -579,7 +598,7 @@ inline long _ttail_file_next_line(FILE* f)
579 598
 	r=0;
580 599
 	buff = NULL;
581 600
 	s = getline(&buff, &r, f);
582
-	if(s == -1)
601
+	if(s < 0)
583 602
 	{
584 603
 		goto _ttail_file_next_line_err;
585 604
 	}
@@ -594,6 +613,7 @@ inline long _ttail_file_next_line(FILE* f)
594 613
 		{
595 614
 			if(fseek(f, -1, SEEK_CUR)<0)
596 615
 			{
616
+				perror("Unable to set position in file");
597 617
 				goto _ttail_file_next_line_err;
598 618
 			}
599 619
 			break;
@@ -619,6 +639,7 @@ inline long _ttail_file_start_line(FILE* f)
619 639
 
620 640
 	if((start = ftell(f)) < 0)
621 641
 	{
642
+		perror("Unable to get position in file");
622 643
 		return -1;
623 644
 	}
624 645
 	res = 0;
@@ -627,6 +648,7 @@ inline long _ttail_file_start_line(FILE* f)
627 648
 	{
628 649
 		if(fseek(f, read_beg, SEEK_SET) < 0)
629 650
 		{
651
+			perror("Unable to set position in file");
630 652
 			return -1;
631 653
 		}
632 654
 		start = read_beg;
@@ -634,6 +656,7 @@ inline long _ttail_file_start_line(FILE* f)
634 656
 		read_beg = start - read_sz;
635 657
 		if(fseek(f, read_beg, SEEK_SET) < 0)
636 658
 		{
659
+			perror("Unable to set position in file");
637 660
 			return -1;
638 661
 		}
639 662
 		last = -1; /* last pos we saw a '\n' */
@@ -667,6 +690,7 @@ inline long _ttail_file_start_line(FILE* f)
667 690
 	}
668 691
 	if(fseek(f, res, SEEK_SET) < 0)
669 692
 	{
693
+		perror("Unable to set position in file");
670 694
 		return -1;
671 695
 	}
672 696
 	return res;

Loading…
Cancel
Save