Skip to content

Commit

Permalink
logreader: add exit-on-eof flag()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bazsi committed Nov 5, 2024
1 parent a967442 commit fb3e52a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/logreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 },
};

Expand Down
1 change: 1 addition & 0 deletions lib/logreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 0 additions & 2 deletions modules/affile/file-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion modules/affile/file-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/affile/stdin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit fb3e52a

Please sign in to comment.