Skip to content

Commit

Permalink
Handle potential file rotate error
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Mar 29, 2024
1 parent 39a6946 commit 903a8aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/collector/collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ FlowSource_t *AddDynamicSource(FlowSource_t **FlowSource, struct sockaddr_storag

} // End of AddDynamicSource

void RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int done) {
int RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int done) {
// periodic file rotation
struct tm *now = localtime(&t_start);
char fmt[32];
Expand Down Expand Up @@ -439,7 +439,7 @@ void RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int
fs->nffile = OpenNewFile(fs->current, fs->nffile, CREATOR_NFCAPD, INHERIT, INHERIT);
if (!fs->nffile) {
LogError("killed due to fatal error: ident: %s", fs->Ident);
break;
return 0;
}
SetIdent(fs->nffile, fs->Ident);

Expand All @@ -452,6 +452,8 @@ void RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int

} // end of while (fs)

return 1;

} // End of RotateFlowFiles

void TriggerLauncher(time_t t_start, char *time_extension, int pfd, FlowSource_t *fs) {
Expand Down
2 changes: 1 addition & 1 deletion src/collector/collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int SetDynamicSourcesDir(FlowSource_t **FlowSource, char *dir);

FlowSource_t *AddDynamicSource(FlowSource_t **FlowSource, struct sockaddr_storage *ss);

void RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int done);
int RotateFlowFiles(time_t t_start, char *time_extension, FlowSource_t *fs, int done);

void TriggerLauncher(time_t t_start, char *time_extension, int pfd, FlowSource_t *fs);

Expand Down
4 changes: 3 additions & 1 deletion src/nfcapd/nfcapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ static void run(packet_function_t receive_packet, int socket, int pfd, int rfd,
// rotate cycle
alarm(0);

RotateFlowFiles(t_start, time_extension, FlowSource, done);
if (RotateFlowFiles(t_start, time_extension, FlowSource, done) == 0) {
return;
}

if (pfd) {
TriggerLauncher(t_start, time_extension, pfd, FlowSource);
Expand Down
4 changes: 3 additions & 1 deletion src/sflow/sfcapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ static void run(packet_function_t receive_packet, int socket, int pfd, int rfd,
// rotate cycle
alarm(0);

RotateFlowFiles(t_start, time_extension, FlowSource, done);
if (RotateFlowFiles(t_start, time_extension, FlowSource, done) == 0) {
return;
}

if (pfd) {
TriggerLauncher(t_start, time_extension, pfd, FlowSource);
Expand Down

0 comments on commit 903a8aa

Please sign in to comment.