From 8b24e2a0f1fd9aa9ff01edd6f6435029116fc758 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 6 Feb 2023 23:09:13 +0900 Subject: [PATCH] Replace $$ with Process.pid. Process.pid is easier to understand. Signed-off-by: abetomo --- lib/fluent/supervisor.rb | 16 ++++++++-------- test/command/test_ctl.rb | 2 +- test/test_supervisor.rb | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index b372f92249..55e95ae01c 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -91,12 +91,12 @@ def run_rpc_server # built-in RPC for signals @rpc_server.mount_proc('/api/processes.interruptWorkers') { |req, res| $log.debug "fluentd RPC got /api/processes.interruptWorkers request" - Process.kill :INT, $$ + Process.kill :INT, Process.pid nil } @rpc_server.mount_proc('/api/processes.killWorkers') { |req, res| $log.debug "fluentd RPC got /api/processes.killWorkers request" - Process.kill :TERM, $$ + Process.kill :TERM, Process.pid nil } @rpc_server.mount_proc('/api/processes.flushBuffersAndKillWorkers') { |req, res| @@ -105,8 +105,8 @@ def run_rpc_server supervisor_sigusr1_handler stop(true) else - Process.kill :USR1, $$ - Process.kill :TERM, $$ + Process.kill :USR1, Process.pid + Process.kill :TERM, Process.pid end nil } @@ -115,7 +115,7 @@ def run_rpc_server if Fluent.windows? supervisor_sigusr1_handler else - Process.kill :USR1, $$ + Process.kill :USR1, Process.pid end nil } @@ -125,7 +125,7 @@ def run_rpc_server # restart worker with auto restarting by killing kill_worker else - Process.kill :HUP, $$ + Process.kill :HUP, Process.pid end nil } @@ -141,7 +141,7 @@ def run_rpc_server if Fluent.windows? supervisor_sigusr2_handler else - Process.kill :USR2, $$ + Process.kill :USR2, Process.pid end nil @@ -213,7 +213,7 @@ def reload def install_windows_event_handler return unless Fluent.windows? - @pid_signame = "fluentd_#{$$}" + @pid_signame = "fluentd_#{Process.pid}" @signame = config[:signame] Thread.new do diff --git a/test/command/test_ctl.rb b/test/command/test_ctl.rb index a29ff62308..f9adc19c8b 100644 --- a/test/command/test_ctl.rb +++ b/test/command/test_ctl.rb @@ -35,7 +35,7 @@ def test_commands(data) Signal.trap(signal) do got_signal = true end - Fluent::Ctl.new([command, "#{$$}"]).call + Fluent::Ctl.new([command, Process.pid.to_s]).call assert_true(got_signal) end end diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb index c8b3f5845b..bafb2b3a0e 100644 --- a/test/test_supervisor.rb +++ b/test/test_supervisor.rb @@ -201,7 +201,7 @@ def test_main_process_signal_handlers sv.send(:install_main_process_signal_handlers) begin - Process.kill :USR1, $$ + Process.kill :USR1, Process.pid rescue end @@ -247,7 +247,7 @@ def test_supervisor_signal_handler server = DummyServer.new server.install_supervisor_signal_handlers begin - Process.kill :USR1, $$ + Process.kill :USR1, Process.pid rescue end @@ -314,10 +314,10 @@ def server.config $log.out.reset if $log && $log.out && $log.out.respond_to?(:reset) end - data("Normal", {raw_path: "C:\\Windows\\Temp\\sigdump.log", expected: "C:\\Windows\\Temp\\sigdump-#{$$}.log"}) - data("UNIX style", {raw_path: "/Windows/Temp/sigdump.log", expected: "/Windows/Temp/sigdump-#{$$}.log"}) - data("No extension", {raw_path: "C:\\Windows\\Temp\\sigdump", expected: "C:\\Windows\\Temp\\sigdump-#{$$}"}) - data("Multi-extension", {raw_path: "C:\\Windows\\Temp\\sig.dump.bk", expected: "C:\\Windows\\Temp\\sig.dump-#{$$}.bk"}) + data("Normal", {raw_path: "C:\\Windows\\Temp\\sigdump.log", expected: "C:\\Windows\\Temp\\sigdump-#{Process.pid}.log"}) + data("UNIX style", {raw_path: "/Windows/Temp/sigdump.log", expected: "/Windows/Temp/sigdump-#{Process.pid}.log"}) + data("No extension", {raw_path: "C:\\Windows\\Temp\\sigdump", expected: "C:\\Windows\\Temp\\sigdump-#{Process.pid}"}) + data("Multi-extension", {raw_path: "C:\\Windows\\Temp\\sig.dump.bk", expected: "C:\\Windows\\Temp\\sig.dump-#{Process.pid}.bk"}) def test_fluentsigdump_get_path_with_pid(data) path = Fluent::FluentSigdump.get_path_with_pid(data[:raw_path]) assert_equal(data[:expected], path)