|
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]; |