Skip to content

Commit

Permalink
Use Fluent.windows? instead of $platformwin
Browse files Browse the repository at this point in the history
  • Loading branch information
nurse committed Oct 1, 2015
1 parent e9d5dab commit 3996d5d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
6 changes: 6 additions & 0 deletions lib/fluent/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/fluent/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
end
require 'cool.io'

$platformwin = /mswin|mingw/ === RUBY_PLATFORM
require 'fluent/env'
require 'fluent/version'
require 'fluent/log'
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/file_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ def s.ino; @ino; end
s
end
end
end if $platformwin
end if Fluent.windows?
2 changes: 1 addition & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

if $platformwin
if Fluent.windows?
require_relative 'file_wrapper'
else
Fluent::FileWrapper = File
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/out_exec_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

require 'fluent/load'
require 'etc'
if $platformwin
if Fluent.windows?
require 'windows/library'
require 'windows/system_info'
include Windows::Library
Expand Down Expand Up @@ -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(/\\/, '/')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -356,7 +356,7 @@ def supervise(&block)
def main_process(&block)
begin
block.call
if $platformwin
if Fluent.windows?
@th_ma.join
end

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_in_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def test_configure
def connect
UNIXSocket.new("#{TMP_DIR}/unix")
end
end unless $platformwin
end unless Fluent.windows?
4 changes: 2 additions & 2 deletions test/plugin/test_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
]
Expand Down

0 comments on commit 3996d5d

Please sign in to comment.