Skip to content

Commit a57c285

Browse files
authored
Merge pull request #77 from sy-c/master
v2.4.1
2 parents fd0c035 + 0092c7c commit a57c285

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

doc/releaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ This file describes the main feature changes for each InfoLogger released versio
111111

112112
## v2.4.0 - 19/10/2021
113113
- Added getMessageCount() / resetMessageCount() to keep track of count of messages, by severity.
114+
115+
## v2.4.1 - 26/10/2021
116+
- Added a cleanup/retry in case of corrupted cache of infoLoggerD, to allow immediate restart. The corrupted files are saved and available for later debugging.

src/permanentFIFO.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,9 @@ int ct_load(int fd, struct circular_table* t, unsigned long id)
415415
- keep only non-ack data
416416
- reassign id numbers starting from zero
417417
It is required that the fifo is not in use at the time this function is called.
418+
When doBackup set, existing fifo files removed (saved to timestamped name) and fresh ones created.
418419
*/
419-
int permFIFO_file_clean(char* path)
420+
int permFIFO_file_clean(char* path, int doBackup)
420421
{
421422
char *f1, *f2, *f3;
422423
int fd1, fd3;
@@ -431,8 +432,20 @@ int permFIFO_file_clean(char* path)
431432

432433
/* retrieve filenames associated to FIFO */
433434
permFIFO_getFileName(path, &f1, &f2, &f3);
435+
436+
if (doBackup) {
437+
char backupName[256];
438+
unsigned int bTime = (unsigned int)time(NULL);
439+
slog(SLOG_INFO, "Backup suffix = %d", bTime);
440+
snprintf(backupName,sizeof(backupName), "%s.%u", f1, bTime);
441+
rename(f1, backupName);
442+
snprintf(backupName,sizeof(backupName), "%s.%u", f2, bTime);
443+
rename(f2, backupName);
444+
snprintf(backupName,sizeof(backupName), "%s.%u", f3, bTime);
445+
rename(f3, backupName);
446+
}
434447

435-
for (;;) {
448+
for (int retry = 0; retry < 3; retry++) {
436449
if (stat(f1, &statbuf)) {
437450
/* file does not exists */
438451
if (stat(f2, &statbuf)) {
@@ -461,7 +474,14 @@ int permFIFO_file_clean(char* path)
461474
unlink(f3);
462475

463476
/* read file header */
464-
if (read(fd1, &hm, sizeof(hm)) != sizeof(hm))
477+
bytes = read(fd1, &hm, sizeof(hm));
478+
if (bytes == 0) {
479+
/* file empty, remove and create new one */
480+
close(fd1);
481+
unlink(f1);
482+
continue;
483+
}
484+
if ( bytes != sizeof(hm))
465485
return 5;
466486
if (hm.tag != FIFO_FILE_TAG)
467487
return 6;
@@ -629,7 +649,12 @@ struct permFIFO* permFIFO_new(int size, char* path)
629649

630650
if (path != NULL) {
631651
/* first clean FIFO file */
632-
err = permFIFO_file_clean(path);
652+
err = permFIFO_file_clean(path, 0);
653+
if (err) {
654+
slog(SLOG_ERROR, "FIFO file cleaning failed : error %d", err);
655+
slog(SLOG_ERROR, "FIFO file backup and create fresh");
656+
err = permFIFO_file_clean(path, 1);
657+
}
633658
if (err) {
634659
slog(SLOG_ERROR, "FIFO file cleaning failed : error %d", err);
635660
return NULL;
@@ -1074,7 +1099,7 @@ int test1()
10741099

10751100
printf("Path=%s\n", path);
10761101
printf("FIFO file dump : %d\n", permFIFO_file_dump(path));
1077-
printf("FIFO file clean : %d\n", permFIFO_file_clean(path));
1102+
printf("FIFO file clean : %d\n", permFIFO_file_clean(path, 0));
10781103
printf("FIFO file dump : %d\n", permFIFO_file_dump(path));
10791104

10801105
fifo = ct_new(10);
@@ -1375,7 +1400,7 @@ int test6()
13751400
}
13761401
permFIFO_destroy(f);
13771402

1378-
permFIFO_file_clean(path);
1403+
permFIFO_file_clean(path, 0);
13791404
printf("FIFO file dump : %d\n", permFIFO_file_dump(path));
13801405
return 0;
13811406
}

0 commit comments

Comments
 (0)