From 903a8aabc149b740f6f95cf38c39425d169062b3 Mon Sep 17 00:00:00 2001 From: Peter Haag Date: Fri, 29 Mar 2024 18:00:20 +0100 Subject: [PATCH] Handle potential file rotate error --- src/collector/collector.c | 6 ++++-- src/collector/collector.h | 2 +- src/nfcapd/nfcapd.c | 4 +++- src/sflow/sfcapd.c | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/collector/collector.c b/src/collector/collector.c index 10f496d8..19bd69d4 100755 --- a/src/collector/collector.c +++ b/src/collector/collector.c @@ -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]; @@ -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); @@ -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) { diff --git a/src/collector/collector.h b/src/collector/collector.h index 279d5dde..e613880a 100755 --- a/src/collector/collector.h +++ b/src/collector/collector.h @@ -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); diff --git a/src/nfcapd/nfcapd.c b/src/nfcapd/nfcapd.c index 2a2ea42e..a117062b 100644 --- a/src/nfcapd/nfcapd.c +++ b/src/nfcapd/nfcapd.c @@ -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); diff --git a/src/sflow/sfcapd.c b/src/sflow/sfcapd.c index 9c4c1132..34530933 100644 --- a/src/sflow/sfcapd.c +++ b/src/sflow/sfcapd.c @@ -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);