Merge pull request #464 from jordansissel/fix-windows-file-problems

This PR should address: - https://logstash.jira.com/browse/LOGSTASH-430 It probably addresses other windows problems, but I couldn't find anything obvious in Jira.
This commit is contained in:
Jordan Sissel 2013-04-30 22:39:31 -07:00
commit 17d828a8ea
4 changed files with 28 additions and 21 deletions

View file

@ -31,6 +31,7 @@ class File
alias_method :expand_path_JRUBY_6970, :expand_path
def expand_path(path, dir=nil)
#p :expand_path => [path, dir]
if path =~ /(jar:)?file:\/.*\.jar!/
#p :expand_path_path => [path, dir]
jar, resource = path.split("!", 2)
@ -39,7 +40,17 @@ class File
# Nothing after the "!", nothing special to handle.
return expand_path_JRUBY_6970(path, dir)
else
return "#{jar}!#{expand_path_JRUBY_6970(resource, dir)}"
resource = expand_path_JRUBY_6970(resource, dir)
# TODO(sissel): use LogStash::Util::UNAME
if RbConfig::CONFIG["host_os"] == "mswin32"
# 'expand_path' on "/" will return "C:/" on windows.
# So like.. we don't want that because technically this
# is the root of the jar, not of a disk.
puts :expand_path => [path, "#{jar}!#{resource.gsub(/^[A-Z]:/, "")}"]
return "#{jar}!#{resource.gsub(/^[A-Z]:/, "")}"
else
return "#{jar}!#{resource}"
end
end
elsif dir =~ /(jar:)?file:\/.*\.jar!/
jar, dir = dir.split("!", 2)

View file

@ -125,8 +125,9 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
hostname = Socket.gethostname
@tail.subscribe do |path, line|
source = Addressable::URI.new(:scheme => "file", :host => hostname, :path => path).to_s
@logger.debug("Received line", :path => path, :line => line)
#source = Addressable::URI.new(:scheme => "file", :host => hostname, :path => path).to_s
source = "file://#{hostname}/#{path.gsub("\\","/")}"
@logger.debug? && @logger.debug("Received line", :path => path, :line => line)
e = to_event(line, source)
if e
queue << e

View file

@ -1,26 +1,22 @@
require "logstash/namespace"
require "ffi" # gem ffi
module LogStash::Util
PR_SET_NAME = 15
# This can throw an exception, if it does, we're probably not on linux.
# It certainly throws an exception on Windows; I don't know how
# to work around it other than this hack.
begin
require "sys/uname" # gem sys-uname
UNAME = Sys::Uname.uname.sysname
rescue LoadError, FFI::NotFoundError
UNAME = "unknown"
UNAME = case RbConfig::CONFIG["host_os"]
when /^linux/; "linux"
else; RbConfig::CONFIG["host_os"]
end
module LibC
extend FFI::Library
if UNAME == "Linux"
ffi_lib 'c'
if UNAME == "linux"
module LibC
extend FFI::Library
if UNAME == "linux"
ffi_lib 'c'
# Ok so the 2nd arg isn't really a string... but whaatever
attach_function :prctl, [:int, :string, :long, :long, :long], :int
# Ok so the 2nd arg isn't really a string... but whaatever
attach_function :prctl, [:int, :string, :long, :long, :long], :int
end
end
end
@ -31,9 +27,9 @@ module LogStash::Util
end
Thread.current[:name] = name
if UNAME == "Linux"
if UNAME == "linux"
# prctl PR_SET_NAME allows up to 16 bytes for a process name
# since MRI 1.9 and JRuby use system threads for this.
# since MRI 1.9, JRuby, and Rubinius use system threads for this.
LibC.prctl(PR_SET_NAME, name[0..16], 0, 0, 0)
end
end # def set_thread_name

View file

@ -22,7 +22,6 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "minitest" # for running the tests from the jar, (MIT license)
gem.add_runtime_dependency "pry" #(ruby license)
gem.add_runtime_dependency "stud" #(Apache 2.0 license)
gem.add_runtime_dependency "sys-uname" # for platform detection (Artistic 2.0 license)
gem.add_runtime_dependency "clamp" # for command line args/flags (MIT license)
gem.add_runtime_dependency "i18n" #(MIT license)