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

Loading…
Cancel
Save