Bladeren bron

Enhancement in ttail init checking function

To handle case where none of the file given as argument is readable
Yann Weber 7 jaren geleden
bovenliggende
commit
93415c6adb
2 gewijzigde bestanden met toevoegingen van 21 en 1 verwijderingen
  1. 20
    0
      src/ttail_init.c
  2. 1
    1
      tests/ttail_search_check.c

+ 20
- 0
src/ttail_init.c Bestand weergeven

@@ -144,6 +144,25 @@ given\n");
144 144
 
145 145
 int ttail_init_check(ttail_t* t)
146 146
 {
147
+	size_t i, ret;
148
+	if(t->logfile_sz)
149
+	{
150
+		ret = 0;
151
+		for(i=0; i<t->logfile_sz; i++)
152
+		{
153
+			if(t->logfile[i])
154
+			{
155
+				ret = 1;
156
+				break;
157
+			}
158
+		}
159
+		if(!ret)
160
+		{
161
+			fprintf(stderr, "Unable to read from any of the files \
162
+given as argument\n");
163
+			return -1;
164
+		}
165
+	}
147 166
 	if(t->flag & TTAIL_FLAG_DATE_MAX)
148 167
 	{
149 168
 		fprintf(stderr, "Warning : date-max not yet implemented\n");
@@ -198,6 +217,7 @@ int ttail_add_logfile(ttail_t* res, const char* filename)
198 217
 	if(!fp)
199 218
 	{
200 219
 		fprintf(stderr, "Unable to open file : %s\n", filename);
220
+		res->logfile[res->logfile_sz-1] = NULL;
201 221
 		ret = 1;
202 222
 	}
203 223
 	res->logfile[res->logfile_sz-1] = fp;

+ 1
- 1
tests/ttail_search_check.c Bestand weergeven

@@ -321,7 +321,7 @@ START_TEST (test_search_files1)
321 321
 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
322 322
 
323 323
 	ret = _ttail_search_closest_files(ttail, &tm);
324
-	ck_assert_int_eq(ret, 1);
324
+	ck_assert_int_eq(ret, 0);
325 325
 	ck_assert(ttail->session->file.id == 0);
326 326
 	ck_assert(ttail->session->file.off == 0);
327 327
 }

Loading…
Annuleren
Opslaan