From fb3e52a4126fe50bb2b2617456837e7478be0afa Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Mon, 14 Oct 2024 19:02:09 +0200 Subject: [PATCH] logreader: add exit-on-eof flag() With the exit-on-eof flag, you can request syslog-ng to exit whenever the first EOF is hit on the specific source, similarly to how the stdin() source behaves. Signed-off-by: Balazs Scheidler --- lib/logreader.c | 6 ++++++ lib/logreader.h | 1 + modules/affile/file-reader.c | 2 -- modules/affile/file-reader.h | 1 - modules/affile/stdin.c | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/logreader.c b/lib/logreader.c index c8747e4635..35fd7de285 100644 --- a/lib/logreader.c +++ b/lib/logreader.c @@ -389,6 +389,11 @@ log_reader_work_finished(void *s, gpointer arg) self->notify_code = 0; log_pipe_notify(self->control, notify_code, self); + + if (notify_code == NC_CLOSE && (self->options->flags & LR_EXIT_ON_EOF)) + { + cfg_shutdown(log_pipe_get_config(s)); + } } if ((self->super.super.flags & PIF_INITIALIZED) && self->proto) { @@ -868,6 +873,7 @@ CfgFlagHandler log_reader_flag_handlers[] = { "empty-lines", CFH_SET, offsetof(LogReaderOptions, flags), LR_EMPTY_LINES }, { "threaded", CFH_SET, offsetof(LogReaderOptions, flags), LR_THREADED }, { "ignore-aux-data", CFH_SET, offsetof(LogReaderOptions, flags), LR_IGNORE_AUX_DATA }, + { "exit-on-eof", CFH_SET, offsetof(LogReaderOptions, flags), LR_EXIT_ON_EOF }, { NULL }, }; diff --git a/lib/logreader.h b/lib/logreader.h index 6c633314c8..2d3b51f75e 100644 --- a/lib/logreader.h +++ b/lib/logreader.h @@ -39,6 +39,7 @@ #define LR_EMPTY_LINES 0x0004 #define LR_IGNORE_AUX_DATA 0x0008 #define LR_THREADED 0x0040 +#define LR_EXIT_ON_EOF 0x0080 /* options */ diff --git a/modules/affile/file-reader.c b/modules/affile/file-reader.c index 4c6af0ae29..7439d6dd53 100644 --- a/modules/affile/file-reader.c +++ b/modules/affile/file-reader.c @@ -267,8 +267,6 @@ file_reader_notify_method(LogPipe *s, gint notify_code, gpointer user_data) switch (notify_code) { case NC_CLOSE: - if (self->options->exit_on_eof) - cfg_shutdown(log_pipe_get_config(s)); break; case NC_FILE_MOVED: diff --git a/modules/affile/file-reader.h b/modules/affile/file-reader.h index 0091908242..05a8795c05 100644 --- a/modules/affile/file-reader.h +++ b/modules/affile/file-reader.h @@ -32,7 +32,6 @@ typedef struct _FileReaderOptions gint multi_line_timeout; gboolean restore_state; LogReaderOptions reader_options; - gboolean exit_on_eof; } FileReaderOptions; typedef struct _FileReader diff --git a/modules/affile/stdin.c b/modules/affile/stdin.c index 9dcc07d24b..b2be7e1be9 100644 --- a/modules/affile/stdin.c +++ b/modules/affile/stdin.c @@ -60,7 +60,7 @@ stdin_sd_new(GlobalConfig *cfg) { AFFileSourceDriver *self = affile_sd_new_instance("-", cfg); - self->file_reader_options.exit_on_eof = TRUE; + self->file_reader_options.reader_options.flags |= LR_EXIT_ON_EOF; self->file_reader_options.reader_options.super.stats_source = stats_register_type("stdin"); self->file_opener = file_opener_for_stdin_new(); affile_sd_set_transport_name(self, "local+stdin");