From 3996d5d1981476854d78d13491e333a1dadd0889 Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Thu, 1 Oct 2015 10:53:56 +0900 Subject: [PATCH] Use Fluent.windows? instead of $platformwin --- lib/fluent/env.rb | 6 ++++++ lib/fluent/load.rb | 1 - lib/fluent/plugin/file_wrapper.rb | 2 +- lib/fluent/plugin/in_tail.rb | 2 +- lib/fluent/plugin/out_exec_filter.rb | 2 +- lib/fluent/supervisor.rb | 24 ++++++++++++------------ test/plugin/test_buf_file.rb | 2 +- test/plugin/test_in_stream.rb | 2 +- test/plugin/test_out_file.rb | 4 ++-- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/fluent/env.rb b/lib/fluent/env.rb index 2916ff669d..8f20db8906 100644 --- a/lib/fluent/env.rb +++ b/lib/fluent/env.rb @@ -21,4 +21,10 @@ module Fluent DEFAULT_LISTEN_PORT = 24224 DEFAULT_FILE_PERMISSION = 0644 DEFAULT_DIR_PERMISSION = 0755 + IS_WINDOWS = /mswin|mingw/ === RUBY_PLATFORM + private_constant :IS_WINDOWS + + def self.windows? + IS_WINDOWS + end end diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index a8a2f63c8f..1a0d064443 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -16,7 +16,6 @@ end require 'cool.io' -$platformwin = /mswin|mingw/ === RUBY_PLATFORM require 'fluent/env' require 'fluent/version' require 'fluent/log' diff --git a/lib/fluent/plugin/file_wrapper.rb b/lib/fluent/plugin/file_wrapper.rb index 925bf1e29a..a1272d2815 100644 --- a/lib/fluent/plugin/file_wrapper.rb +++ b/lib/fluent/plugin/file_wrapper.rb @@ -118,4 +118,4 @@ def s.ino; @ino; end s end end -end if $platformwin +end if Fluent.windows? diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 857fce075d..5c403660d4 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -14,7 +14,7 @@ # limitations under the License. # -if $platformwin +if Fluent.windows? require_relative 'file_wrapper' else Fluent::FileWrapper = File diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index 3a4d5929b3..4646e4a702 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -262,7 +262,7 @@ def start(command) def kill_child(join_wait) begin - signal = $platformwin ? :KILL : :TERM + signal = Fluent.windows? ? :KILL : :TERM Process.kill(signal, @pid) rescue #Errno::ECHILD, Errno::ESRCH, Errno::EPERM # Errno::ESRCH 'No such process', ignore diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 5f32c4e22f..e26cd91d7f 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -16,7 +16,7 @@ require 'fluent/load' require 'etc' -if $platformwin +if Fluent.windows? require 'windows/library' require 'windows/system_info' include Windows::Library @@ -128,7 +128,7 @@ def initialize(opt) @without_source = opt[:without_source] @signame = opt[:signame] - if $platformwin + if Fluent.windows? ruby_path = "\0" * 256 GetModuleFileName.call(0,ruby_path,256) ruby_path = ruby_path.rstrip.gsub(/\\/, '/') @@ -172,7 +172,7 @@ def start change_privilege init_engine install_main_process_signal_handlers - install_main_process_winsigint_handler if $platformwin + install_main_process_winsigint_handler if Fluent.windows? run_configure finish_daemonize if @daemonize run_engine @@ -310,7 +310,7 @@ def supervise(&block) $log.info "starting fluentd-#{Fluent::VERSION}" - if !$platformwin + if !Fluent.windows? @main_pid = fork do main_process(&block) end @@ -340,7 +340,7 @@ def supervise(&block) @main_pid = nil ecode = $?.to_i - if $platformwin + if Fluent.windows? @th_sv.kill if @th_sv.alive? @th_sv.join rescue nil end @@ -356,7 +356,7 @@ def supervise(&block) def main_process(&block) begin block.call - if $platformwin + if Fluent.windows? @th_ma.join end @@ -399,17 +399,17 @@ def install_supervisor_signal_handlers $log.debug "fluentd supervisor process get SIGHUP" $log.info "restarting" supervisor_sighup_handler - end unless $platformwin + end unless Fluent.windows? trap :USR1 do $log.debug "fluentd supervisor process get SIGUSR1" supervisor_sigusr1_handler - end unless $platformwin + end unless Fluent.windows? end def supervisor_sigint_handler @finished = true - unless $platformwin + unless Fluent.windows? if pid = @main_pid # kill processes only still exists unless Process.waitpid(pid, Process::WNOHANG) @@ -561,7 +561,7 @@ def install_main_process_signal_handlers trap :INT do $log.debug "fluentd main process get SIGINT" - unless $platformwin + unless Fluent.windows? unless @finished @finished = true $log.debug "getting start to shutdown main process" @@ -588,7 +588,7 @@ def install_main_process_signal_handlers trap :HUP do # TODO $log.debug "fluentd main process get SIGHUP" - end unless $platformwin + end unless Fluent.windows? trap :USR1 do $log.debug "fluentd main process get SIGUSR1" @@ -605,7 +605,7 @@ def install_main_process_signal_handlers $log.warn "flushing thread error: #{e}" end }.run - end unless $platformwin + end unless Fluent.windows? end def run_engine diff --git a/test/plugin/test_buf_file.rb b/test/plugin/test_buf_file.rb index 3a6ce23de5..2da05d16a8 100644 --- a/test/plugin/test_buf_file.rb +++ b/test/plugin/test_buf_file.rb @@ -26,7 +26,7 @@ def filebufferchunk(key, unique, opts={}) end def test_init - omit "Windows doesn't support symlink" if $platformwin + omit "Windows doesn't support symlink" if Fluent.windows? chunk = filebufferchunk('key', 'init1') assert_equal 'key', chunk.key assert_equal 'init1', chunk.unique_id diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 7d1f5a0d27..0ac5a4ae4c 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -122,4 +122,4 @@ def test_configure def connect UNIXSocket.new("#{TMP_DIR}/unix") end -end unless $platformwin +end unless Fluent.windows? diff --git a/test/plugin/test_out_file.rb b/test/plugin/test_out_file.rb index 206eb868b0..daa50fc5da 100644 --- a/test/plugin/test_out_file.rb +++ b/test/plugin/test_out_file.rb @@ -62,7 +62,7 @@ def test_default_localtime d = create_driver(%[path #{TMP_DIR}/out_file_test]) time = Time.parse("2011-01-02 13:14:15 UTC").to_i - with_timezone($platformwin ? 'NST-8' : 'Asia/Taipei') do + with_timezone(Fluent.windows? ? 'NST-8' : 'Asia/Taipei') do d.emit({"a"=>1}, time) d.expect_format %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n] d.run @@ -232,7 +232,7 @@ def test_write_with_append end def test_write_with_symlink - omit "Windows doesn't support symlink" if $platformwin + omit "Windows doesn't support symlink" if Fluent.windows? conf = CONFIG + %[ symlink_path #{SYMLINK_PATH} ]