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

未关闭 适合新手
#5,716 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ruby
领域
backend, cli

调研方向

先查看 lib/fluent/command/ctl.rb 第 95 行和第 176 行附近的 PID 验证,然后阅读 test/command/test_ctl.rb 中的 test_invalid_pid。检查 PID 0 和类似 "abc\n123" 的多行参数是否会在不发送信号的情况下被拒绝,同时有效的正 PID 仍能正常工作。Issue 指出,现有测试可以覆盖这两种情况。

由索引模型根据 Issue 内容生成。

描述

bug
Describe the bug

fluent-ctl accepts 0 as a PID. It also accepts an argument that has a line with only digits, such as "abc\n123". Both become PID 0, and Process.kill(:TERM, 0) sends the signal to every process in the caller's process group. So fluent-ctl shutdown 0 stops the shell script that runs it, and the other processes in the same group, instead of reporting an invalid PID.

The PID check uses ^ and $, which match at line boundaries, and allows 0 (ctl.rb L176):

usage("Invalid PID: #{@pid_or_svcname}") unless /^[0-9]+$/.match?(@pid_or_svcname)

call_signal then converts the argument with to_i (ctl.rb L113), which gives 0 for both "0" and "abc\n123". restart, flush, reload and dump work the same way with other signals. On Windows, the same regular expression decides whether the argument is a PID or a service name (ctl.rb L95).

To Reproduce

Run each command in its own session, so that only a throwaway process group gets the signal:

setsid bash -c 'sleep 5 & fluent-ctl shutdown 0; echo "fluent-ctl rc=$?"; wait'; echo "group rc=$?"
setsid bash -c 'sleep 5 & fluent-ctl shutdown "$1"; echo "fluent-ctl rc=$?"; wait' _ $'abc\n123'; echo "group rc=$?"
# For comparison, a PID that does not exist
setsid bash -c 'sleep 5 & fluent-ctl shutdown 999999; echo "fluent-ctl rc=$?"; wait'; echo "group rc=$?"

Results on master (31157cba) and v1.20.1:

Argument Result
0 The whole group gets SIGTERM (exit status 143). Nothing after fluent-ctl runs.
$'abc\n123' Same as 0.
999999 (for comparison) fluent-ctl fails with Errno::ESRCH. The rest of the group keeps running.
Expected behavior

fluent-ctl rejects these arguments with Error: Invalid PID, as it does for abc, and sends no signal.

Your Environment
- Fluentd version: master (31157cba) and v1.20.1
- Package version: -
- Operating system: Ubuntu 24.04.5 LTS
- Kernel version: 6.8.0-151-generic
- Ruby: 4.0.10
Your Configuration
No configuration is needed. Only fluent-ctl is used.
Your Error Log
No error is logged. The calling shell is terminated:
Terminated
group rc=143
Additional context

A possible fix is to use /\A[1-9][0-9]*\z/ at L176 and L95. With this change, both arguments fail with Error: Invalid PID, the process group keeps running, and test/command/test_ctl.rb passes. test_invalid_pid, added in #5661, can take "0" and "abc\n123" as more data.

主要语言
Ruby
星标
13.6k
派生
1.4k
平均合并
1 天 10 小时
30 天内合并 PR
79

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fluent/fluentd 的其他 Issue

查看 fluent/fluentd 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。