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

Abierto Apto para principiantes
#5,716 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ruby
Área
backend, cli

Línea de trabajo

Empieza por la validación de PID en lib/fluent/command/ctl.rb, alrededor de las líneas 95 y 176, y luego lee test_invalid_pid en test/command/test_ctl.rb. Comprueba que se rechacen PID 0 y un argumento multilínea como "abc\n123" sin enviar una señal, mientras que los PID positivos válidos sigan funcionando. El issue indica que la prueba existente puede cubrir ambos casos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Ruby
Estrellas
13.6k
Forks
1.4k
Merge medio
1 d 10 h
PR fusionados (30 d)
79

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de fluent/fluentd

Todos los issues de fluent/fluentd

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.