Skip to content

fluent-ctl: reject 0 and multi-line values as a PID - #5719

Merged
Watson1978 merged 2 commits into
fluent:masterfrom
og-orca:fluent-ctl-invalid-pid
Dec 3, 2026
Merged

Watson1978 merged 2 commits into
fluent:masterfrom
og-orca:fluent-ctl-invalid-pid

Conversation

@og-orca

@og-orca og-orca commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #5716

What this PR does / why we need it:
fluent-ctl shutdown 0 killed the shell that ran it, because Process.kill with PID 0 goes to the whole process group. $'abc\n123' did the same: ^ and $ match per line, so it passed the check and to_i made it 0.

L176 uses /\A[1-9][0-9]*\n?\z/ now. It is the regexp from the issue plus one optional trailing newline, so the content of the PID file that fluentd --daemon writes can still be passed as is. I ran the steps from the issue, each one in its own session:

fluent-ctl before and after

The issue also names L95, but I left that one alone. call_winsvc_control_code opens fluentdwinsvc whatever name it gets, so with the stricter regexp fluent-ctl shutdown 0 on Windows would go that way and ask the real service to stop. Today it only fails to find the event fluentd_0. That is from reading the code, I didn't run it on Windows.

test_invalid_pid got five more rows. All of them fail on master. A PID with leading zeros like 0123 is rejected now too. test_pid_with_trailing_newline checks that one trailing newline is still accepted.

Docs Changes:
None

Release Note:
fluent-ctl: reject 0 and multi-line values as a PID

PID 0 makes Process.kill signal the whole process group, so
fluent-ctl shutdown 0 killed the shell that ran it. A value like
"abc\n123" passed the check too and became 0 in to_i.

Signed-off-by: og-orca <301901286+og-orca@users.noreply.github.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I ran the steps from #5716 on this branch. 0 and $'abc\n123' are rejected now, and the process group keeps running.

I also agree with leaving L95 as it is. With a stricter check there, fluent-ctl shutdown 0 would go to call_winsvc_control_code. That method always opens fluentdwinsvc, whatever name it gets, and asks it to stop.

One regression is left. A PID that ends with a newline is rejected now. Please see the inline comment.

Comment thread lib/fluent/command/ctl.rb Resolved
@Watson1978 Watson1978 added bug Something isn't working backport to v1.19 We will backport this fix to the LTS branch labels Dec 3, 2026
Signed-off-by: og-orca <301901286+og-orca@users.noreply.github.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. A PID that ends with one newline works again. I checked it with the PID file of a running fluentd --daemon. The new row confirms that two newlines are rejected. LGTM.

@Watson1978
Watson1978 merged commit e859373 into fluent:master Dec 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fluent-ctl sends the signal to its own process group when the PID is 0 or has a newline

2 participants