Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins: in_exec: don't eat last character of plugin output #4655

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

leonardo-albertovich
Copy link
Collaborator

Notes : This is a backport of @rschwebel's PR #4496 so I'm reproducing his
PR comment. I don't know if there's a way to tag and credit him so if anyone
knows how to feel free to do so.

The plugin works if the execed command outputs a trailing newline,
because in that case that newline is replaced by the clamping \0.
However, when the command does not print a trailing newline, the last
character is overwritten.

This can be tested with:

[INPUT]
Name exec
Tag exec_adc
Command echo -n '{"foo": "bar"}'
Parser json
Interval_Sec 5
Interval_NSec 0
Buf_Size 8mb

With "-n" in the Command line, we end up with

[2021/12/01 03:11:44] [error] [input:exec:exec.0] parser returned an error

without this patch.

Fixes: #4493

Note : This is a backport of @rschwebel's PR 4496, credit should
be attributed to him

The plugin works if the execed command outputs a trailing newline,
because in that case that newline is replaced by the clamping \0.
However, when the command does not print a trailing newline, the last
character is overwritten.

This can be tested with:

[INPUT]
     Name          exec
     Tag           exec_adc
     Command       echo -n '{"foo": "bar"}'
     Parser        json
     Interval_Sec  5
     Interval_NSec 0
     Buf_Size      8mb

With "-n" in the Command line, we end up with

[2021/12/01 03:11:44] [error] [input:exec:exec.0] parser returned an error

without this patch. If the trailing \n is replaced with \0, reduce the
str_len accordingly.

Signed-off-by: Leonardo Alminana <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants