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/libuptimed/urec.c (-27 / +29 lines)
Lines 268-301 void save_records(int max, time_t log_th Link Here
268
	rename(FILE_RECORDS".tmp", FILE_RECORDS);
268
	rename(FILE_RECORDS".tmp", FILE_RECORDS);
269
}
269
}
270
270
271
#ifdef PLATFORM_LINUX
271
#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
272
int createbootid(void) {
272
int createbootid(void) {
273
	FILE *f;
273
	/* these platforms doesn't need to create a bootid file.
274
	char str[256];
274
	 * readbootid() fetches it directly from the system every time.
275
	time_t bootid = 0;
275
	 */
276
	
277
	f=fopen("/proc/stat", "r");
278
	if (!f) {
279
		printf ("Error opening /proc file. Can not determine bootid, exiting!\n"); exit(-1);
280
	} else {
281
		fgets(str, sizeof(str), f);
282
		while (!feof(f)) {
283
			if (strstr(str, "btime")) {
284
				bootid=atoi(str+6);
285
				break;
286
			}
287
			fgets(str, sizeof(str), f);
288
		}
289
		fclose(f);
290
	}
291
	
292
	f = fopen(FILE_BOOTID, "w");
293
	if (!f) {
294
		printf("Error writing bootid file, exiting!\n");  exit(-1);
295
	} else {
296
		fprintf(f, "%ld\n", bootid);
297
		fclose(f);
298
	}
299
	return 0;
276
	return 0;
300
}
277
}
301
#endif
278
#endif
Lines 384-389 time_t readbootid(void) { Link Here
384
	}
361
	}
385
362
386
	return bootid;
363
	return bootid;
364
#elif PLATFORM_LINUX
365
	FILE *f;
366
	char str[256];
367
	time_t bootid = 0;
368
369
	f=fopen("/proc/stat", "r");
370
	if (!f) {
371
		printf ("Error opening /proc/stat file. Can not determine bootid, exiting!\n");
372
		exit(-1);
373
	} else {
374
		fgets(str, sizeof(str), f);
375
		while (!feof(f)) {
376
			if (strstr(str, "btime")) {
377
				bootid=atoi(str+6);
378
				break;
379
			}
380
			fgets(str, sizeof(str), f);
381
		}
382
		fclose(f);
383
	}
384
	if (bootid == 0) {
385
		printf ("Parsing btime from /proc/stat failed. Can not determine bootid, exiting!\n");
386
		exit(-1);
387
	}
388
	return bootid;
387
#else
389
#else
388
	FILE *f;
390
	FILE *f;
389
	char str[256];
391
	char str[256];
(-)uptimed-0.3.16/src/uptimed.c (-2 lines)
Lines 75-81 int main(int argc, char *argv[]) Link Here
75
 		}
75
 		}
76
 	}		
76
 	}		
77
77
78
#ifndef PLATFORM_BSD
79
	/* Create bootid and exit. Should be done once on startup. */
78
	/* Create bootid and exit. Should be done once on startup. */
80
	if (create_bootid)
79
	if (create_bootid)
81
	{
80
	{
Lines 83-89 int main(int argc, char *argv[]) Link Here
83
		syslog(LOG_INFO, SYSLOG_PREFIX "created bootid: %d", readbootid());
82
		syslog(LOG_INFO, SYSLOG_PREFIX "created bootid: %d", readbootid());
84
		exit(0);
83
		exit(0);
85
	}
84
	}
86
#endif
87
85
88
	if (update_interval<1)
86
	if (update_interval<1)
89
		update_interval=1;
87
		update_interval=1;

Return to bug 411785