Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/command/ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def parse_options!
usage("PID or SVCNAME isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
else
usage("PID isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
usage("Invalid PID: #{@pid_or_svcname}") unless /^[0-9]+$/.match?(@pid_or_svcname)
usage("Invalid PID: #{@pid_or_svcname}") unless /\A[1-9][0-9]*\n?\z/.match?(@pid_or_svcname)
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions test/command/test_ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def test_commands_with_winsvcname(data)
end

data("not a number" => [["shutdown", "abc"], "Error: Invalid PID: abc"],
"zero" => [["shutdown", "0"], "Error: Invalid PID: 0"],
"leading zero" => [["shutdown", "0123"], "Error: Invalid PID: 0123"],
"digits on the first line" => [["shutdown", "123\nabc"], "Error: Invalid PID: 123\nabc"],
"digits on the second line" => [["shutdown", "abc\n123"], "Error: Invalid PID: abc\n123"],
"two trailing newlines" => [["shutdown", "123\n\n"], "Error: Invalid PID: 123\n\n"],
"no PID" => [["shutdown"], "Error: PID isn't specified!"])
def test_invalid_pid(data)
omit "Windows accepts a service name instead of a PID" if Fluent.windows?
Expand All @@ -70,6 +75,16 @@ def test_invalid_pid(data)
assert_include(out, message)
end

def test_pid_with_trailing_newline
omit "Windows accepts a service name instead of a PID" if Fluent.windows?

# The PID file that `fluentd --daemon` writes ends with a newline.
mock(Process).kill(:USR1, Process.pid) { 1 }
assert_nothing_raised do
Fluent::Ctl.new(["flush", "#{Process.pid}\n"]).call
end
end

def test_default_winsvc_name
omit "Only for Windows" unless Fluent.windows?

Expand Down
Loading