Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 411785 | Differences between
and this patch

Collapse All | Expand All

(-)uptimed-0.3.16.orig/libuptimed/urec.c (-6 / +32 lines)
Lines 215-234 Link Here
215
	time_t utime, btime;
215
	time_t utime, btime;
216
	long l_utime, l_btime;
216
	long l_utime, l_btime;
217
	char buf[256], sys[SYSMAX+1];
217
	char buf[256], sys[SYSMAX+1];
218
	struct stat filestat, filestatold;
219
	int useold = 0;
218
	
220
	
219
	f = fopen(FILE_RECORDS, "r");
221
	if (stat(FILE_RECORDS, &filestat))
220
	if (!f) {
222
		useold = 1;
221
		f = fopen(FILE_RECORDS".old", "r");
223
	if (stat(FILE_RECORDS".old", &filestatold))
222
		if (!f) return;
224
		useold = -1;
225
226
	/* assume that backupdb larger than normal db means normal is corrupted */
227
	if (!useold && (filestat.st_size < filestatold.st_size))
228
		useold = 1;
223
229
224
		printf("uptimed: reading from backup database %s.old\n", FILE_RECORDS);
230
dbtry:
231
	switch (useold) {
232
		case 0:
233
			f = fopen(FILE_RECORDS, "r");
234
			break;
235
		case 1:
236
			f = fopen(FILE_RECORDS".old", "r");
237
			printf("uptimed: reading from backup database %s.old\n", FILE_RECORDS);
238
			break;
239
		default:
240
			/* this should probably terminate uptimed somehow */
241
			printf("uptimed: no useable database found.\n");
242
			return;
243
	}
244
			
245
	if (!f) {
246
		printf("uptimed: error opening database for reading.\n");
247
		return;
225
	}
248
	}
226
	
249
	
227
	fgets(str, sizeof(str), f);
250
	fgets(str, sizeof(str), f);
228
	while (!feof(f)) {
251
	while (!feof(f)) {
229
		/* Check for validity of input string. */
252
		/* Check for validity of input string. */
230
		if (sscanf(str, "%ld:%ld:%[^]\n]", &l_utime, &l_btime, buf) != 3) {
253
		if (sscanf(str, "%ld:%ld:%[^]\n]", &l_utime, &l_btime, buf) != 3) {
231
			/* Skip this entry. Do we want feedback here? */
254
			/* database is corrupted */
255
			fclose(f);
256
			useold++;
257
			goto dbtry;
232
		} else {
258
		} else {
233
			utime = (time_t)l_utime;
259
			utime = (time_t)l_utime;
234
			btime = (time_t)l_btime;
260
			btime = (time_t)l_btime;
(-)uptimed-0.3.16.orig/libuptimed/urec.h (+1 lines)
Lines 21-26 Link Here
21
#include <string.h>
21
#include <string.h>
22
#include <stdlib.h>
22
#include <stdlib.h>
23
#include <sys/types.h>
23
#include <sys/types.h>
24
#include <sys/stat.h>
24
25
25
#ifdef PLATFORM_LINUX
26
#ifdef PLATFORM_LINUX
26
#include <sys/sysinfo.h>
27
#include <sys/sysinfo.h>

Return to bug 411785